main.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #! venv/bin/python
  2. import json
  3. import sys
  4. import model
  5. import view
  6. if __name__ == '__main__':
  7. status = model.get_loot_level()
  8. print(status)
  9. old_status = 0
  10. write_file_next = False
  11. try:
  12. old_status_file = open('status.json', 'r')
  13. if old_status_file.mode == 'r':
  14. old_status_raw = old_status_file.read()
  15. if old_status_raw:
  16. old_status_json = json.loads(old_status_raw)
  17. old_status = int(old_status_json['integer'])
  18. else:
  19. write_file_next = True
  20. old_status_file.close()
  21. except FileNotFoundError:
  22. empty_status_file = open('status.json', 'w+')
  23. print('Created new file ... Exiting')
  24. empty_status_file.close()
  25. sys.exit(1)
  26. print(old_status)
  27. send_message = False
  28. if old_status != status[1]:
  29. write_file_next = True
  30. send_message = True
  31. if write_file_next:
  32. summary = {'text': status[2], 'roman': status[0], 'integer': status[1]}
  33. summary_json = json.dumps(summary, indent=2)
  34. write_file = open('status.json', 'w')
  35. write_file.write(summary_json)
  36. write_file.close()
  37. if send_message:
  38. view.send_message(status['integer'])