main.py 2.0 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. # seconds = extract_hospital_time(status['text'], status['integer'])
  12. write_file_next = False
  13. # Get data from stored json file
  14. old_status_json, old_status = model.get_json_file(player_id)
  15. if old_status_json == -1 or old_status == -1:
  16. write_file_next = True
  17. calculate_next_opportunity = False
  18. send_message = False
  19. # print('if old_status {} != status[\'integer\'] {}'.format(old_status, status['integer']))
  20. assert type(old_status) is int, f"old_status {old_status} is not an integer: {type(old_status)}"
  21. assert type(status['integer']) is int, \
  22. f"status['integer'] {status['integer']} is not an integer: {type(status['integer'])}"
  23. timestamp_when_okay = int(status['timestamp'])
  24. if status['integer'] == 0:
  25. seconds_in_hosp = model.extract_hospital_time(status['text'])
  26. timestamp_when_okay += seconds_in_hosp
  27. if old_status != status['integer']:
  28. calculate_next_opportunity = True
  29. write_file_next = True
  30. send_message = True
  31. # print('write_file_next: {}'.format(write_file_next))
  32. if calculate_next_opportunity:
  33. message_text = status['text']
  34. message_integer = status['integer']
  35. if write_file_next:
  36. # summary = {'text': status["status"], 'roman': status["roman"], 'integer': status["integer"]}
  37. pprint(status)
  38. summary_json = json.dumps(status, indent=2)
  39. print(summary_json)
  40. write_file = open(f'status-{player_id}.json', 'w')
  41. write_file.write(summary_json)
  42. write_file.close()
  43. write_file.close()
  44. if send_message:
  45. # pass
  46. view.send_message(status)