| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- #! venv/bin/python
- import json
- # import sys
- import math
- from pprint import pprint
- import arrow
- import model
- import view
- if __name__ == '__main__':
- for player_id in [4, 15]:
- status = model.get_loot_level(player_id)
- # print(status)
- # seconds = extract_hospital_time(status['text'], status['integer'])
- write_file_next = False
- # Get data from stored json file
- old_status_json, old_status = model.get_json_file(player_id)
- if old_status_json == -1 or old_status == -1:
- write_file_next = True
- calculate_next_opportunity = False
- send_message = False
- # print('if old_status {} != status[\'integer\'] {}'.format(old_status, status['integer']))
- assert type(old_status) is int, f"old_status {old_status} is not an integer: {type(old_status)}"
- assert type(status['integer']) is int, \
- f"status['integer'] {status['integer']} is not an integer: {type(status['integer'])}"
- timestamp_when_okay = int(status['timestamp'])
- if status['integer'] == 0:
- seconds_in_hosp = model.extract_hospital_time(status['text'], _debug=True)
- timestamp_when_okay += seconds_in_hosp
- if old_status != status['integer']:
- calculate_next_opportunity = True
- write_file_next = True
- send_message = True
- # print('write_file_next: {}'.format(write_file_next))
- if calculate_next_opportunity:
- message_text = status['text']
- message_integer = status['integer']
- if write_file_next:
- # summary = {'text': status["status"], 'roman': status["roman"], 'integer': status["integer"]}
- pprint(status)
- summary_json = json.dumps(status, indent=2)
- print(summary_json)
- write_file = open(f'status-{player_id}.json', 'w')
- write_file.write(summary_json)
- write_file.close()
- write_file.close()
- seconds_to_go, attack_time = model.calculate_time_to_next_attack(player_id)
- player_name = status['name']
- attack_time_object = arrow.get(attack_time)
- attack_time_time = attack_time_object.format('hh:mm A')
- minutes_to_go = math.floor(seconds_to_go / 60)
- t = f'In < {minutes_to_go} mins ({attack_time_time}) {player_name} [{player_id}] reaches level IV'
- print(t)
- status['time_string'] = t
- if minutes_to_go < 20 and minutes_to_go % 5 == 0 and minutes_to_go != 0:
- name_alert = status['name']
- id_alert = status['id']
- url_alert = f'https://www.torn.com/profiles.php?XID={id_alert}'
- alert = f'@here Alert: {minutes_to_go} mins to attack [{name_alert} \[{id_alert}\]]({url_alert}). ' + \
- f'Be there at {attack_time_time}!'
- print('Sending alert')
- view.send_alert(alert)
- if send_message:
- view.send_message(status)
|