main.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 player_id in [4, 15]:
  9. status = model.get_loot_level(player_id)
  10. # print(status)
  11. old_status = 0
  12. write_file_next = False
  13. try:
  14. old_status_file = open(f'status-{player_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-{player_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, \
  33. f"status['integer'] {status['integer']} is not an integer: {type(status['integer'])}"
  34. if old_status != status['integer']:
  35. write_file_next = True
  36. send_message = True
  37. # print('write_file_next: {}'.format(write_file_next))
  38. if write_file_next:
  39. # summary = {'text': status["status"], 'roman': status["roman"], 'integer': status["integer"]}
  40. pprint(status)
  41. summary_json = json.dumps(status, indent=2)
  42. print(summary_json)
  43. write_file = open(f'status-{player_id}.json', 'w')
  44. write_file.write(summary_json)
  45. write_file.close()
  46. write_file.close()
  47. if send_message:
  48. view.send_message(status)