main.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #! venv/bin/python
  2. import json
  3. import sys
  4. import view as view
  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. if old_status != status[1]:
  30. write_file_next = True
  31. send_message = True
  32. if write_file_next:
  33. summary = {'text': status[2], 'roman': status[0], 'integer': status[1]}
  34. summary_json = json.dumps(summary, indent=2)
  35. write_file = open('status.json', 'w')
  36. write_file.write(summary_json)
  37. write_file.close()
  38. if send_message:
  39. view.send_message(status['integer'])