main.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #! venv/bin/python
  2. import json
  3. import sys
  4. import model
  5. import view
  6. import types
  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 types.IntType, f"old_status {old_status} is not an integer: {type(old_status)}"
  31. assert type(status[1]) is types.IntType, f"status[1] {status[1]} is not an integer: {type(status[1])}"
  32. if old_status != status[1]:
  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[2], 'roman': status[0], 'integer': status[1]}
  38. summary_json = json.dumps(summary, indent=2)
  39. write_file = open('status.json', 'w')
  40. write_file.write(summary_json)
  41. write_file.close()
  42. if send_message:
  43. view.send_message(status['integer'])