|
|
@@ -1,62 +1,33 @@
|
|
|
#! venv/bin/python
|
|
|
import json
|
|
|
-import re
|
|
|
-import sys
|
|
|
+# import sys
|
|
|
from pprint import pprint
|
|
|
|
|
|
import model
|
|
|
-import view
|
|
|
-
|
|
|
-
|
|
|
-def extract_hospital_time(this_message_text, this_message_integer):
|
|
|
- in_hospital = False
|
|
|
- time_text = ''
|
|
|
- hours = 0
|
|
|
- minutes = 0
|
|
|
- if this_message_integer == 0:
|
|
|
- if 'hospital' in this_message_text[0]:
|
|
|
- in_hospital = True
|
|
|
- time_text = this_message_text[0][15:]
|
|
|
- print(time_text)
|
|
|
- m = re.match(regex, time_text)
|
|
|
- if m:
|
|
|
- if m.group('hours'):
|
|
|
- hours = m.group('hours')
|
|
|
- if m.group('minutes'):
|
|
|
- minutes = m.group('minutes')
|
|
|
- print(f'Extracted {hours} hrs and {minutes} mins')
|
|
|
+# import view
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
- regex = re.compile(r'( (?P<hours>\d+) hrs)? (?P<minutes>\d+) mins ')
|
|
|
for player_id in [4, 15]:
|
|
|
status = model.get_loot_level(player_id)
|
|
|
# print(status)
|
|
|
- extract_hospital_time(status['text'], status['integer'])
|
|
|
- old_status = 0
|
|
|
+ # seconds = extract_hospital_time(status['text'], status['integer'])
|
|
|
write_file_next = False
|
|
|
- try:
|
|
|
- old_status_file = open(f'status-{player_id}.json', 'r')
|
|
|
- if old_status_file.mode == 'r':
|
|
|
- old_status_raw = old_status_file.read()
|
|
|
- if old_status_raw:
|
|
|
- old_status_json = json.loads(old_status_raw)
|
|
|
- old_status = int(old_status_json['integer'])
|
|
|
- else:
|
|
|
- write_file_next = True
|
|
|
- old_status_file.close()
|
|
|
- except FileNotFoundError:
|
|
|
- empty_status_file = open(f'status-{player_id}.json', 'w+')
|
|
|
- print('Created new file ... Exiting')
|
|
|
- empty_status_file.close()
|
|
|
- sys.exit(1)
|
|
|
- # print(old_status)
|
|
|
+ # 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[1] {}'.format(old_status, status[1]))
|
|
|
+ # 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'])
|
|
|
+ timestamp_when_okay += seconds_in_hosp
|
|
|
if old_status != status['integer']:
|
|
|
calculate_next_opportunity = True
|
|
|
write_file_next = True
|
|
|
@@ -77,4 +48,5 @@ if __name__ == '__main__':
|
|
|
write_file.close()
|
|
|
|
|
|
if send_message:
|
|
|
- view.send_message(status)
|
|
|
+ pass
|
|
|
+ # view.send_message(status)
|