main.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #! venv/bin/python
  2. import json
  3. # import sys
  4. from pprint import pprint
  5. import arrow
  6. import model
  7. import view
  8. if __name__ == '__main__':
  9. for player_id in [4, 15]:
  10. status = model.get_loot_level(player_id)
  11. # print(status)
  12. # seconds = extract_hospital_time(status['text'], status['integer'])
  13. write_file_next = False
  14. # Get data from stored json file
  15. old_status_json, old_status = model.get_json_file(player_id)
  16. if old_status_json == -1 or old_status == -1:
  17. write_file_next = True
  18. calculate_next_opportunity = False
  19. send_message = False
  20. # print('if old_status {} != status[\'integer\'] {}'.format(old_status, status['integer']))
  21. assert type(old_status) is int, f"old_status {old_status} is not an integer: {type(old_status)}"
  22. assert type(status['integer']) is int, \
  23. f"status['integer'] {status['integer']} is not an integer: {type(status['integer'])}"
  24. timestamp_when_okay = int(status['timestamp'])
  25. if status['integer'] == 0:
  26. seconds_in_hosp = model.extract_hospital_time(status['text'])
  27. timestamp_when_okay += seconds_in_hosp
  28. if old_status != status['integer']:
  29. calculate_next_opportunity = True
  30. write_file_next = True
  31. send_message = True
  32. # print('write_file_next: {}'.format(write_file_next))
  33. if calculate_next_opportunity:
  34. message_text = status['text']
  35. message_integer = status['integer']
  36. if write_file_next:
  37. # summary = {'text': status["status"], 'roman': status["roman"], 'integer': status["integer"]}
  38. pprint(status)
  39. summary_json = json.dumps(status, indent=2)
  40. print(summary_json)
  41. write_file = open(f'status-{player_id}.json', 'w')
  42. write_file.write(summary_json)
  43. write_file.close()
  44. write_file.close()
  45. seconds_to_go, attack_time = model.calculate_time_to_next_attack(player_id)
  46. player_name = status['name']
  47. attack_time_object = arrow.get(attack_time)
  48. attack_time_time = attack_time_object.format('hh:mm A')
  49. minutes_to_go = int(seconds_to_go//60)
  50. t = f'In < {minutes_to_go} mins ({attack_time_time}) {player_name} [{player_id}] reaches level IV'
  51. print(t)
  52. status['time_string'] = t
  53. if send_message:
  54. view.send_message(status)