main.py 1.9 KB

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