main.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. print('if old_status {} != status[1] {}'.format(old_status, status[1]))
  29. if old_status != status[1]:
  30. write_file_next = True
  31. send_message = True
  32. print('write_file_next: {}'.format(write_file_next))
  33. if write_file_next:
  34. summary = {'text': status[2], 'roman': status[0], 'integer': status[1]}
  35. summary_json = json.dumps(summary, indent=2)
  36. write_file = open('status.json', 'w')
  37. write_file.write(summary_json)
  38. write_file.close()
  39. if send_message:
  40. view.send_message(status['integer'])