main.py 1.7 KB

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