Ver código fonte

Testing hospital time

Foppe Hemminga 6 anos atrás
pai
commit
042dbc7508
1 arquivos alterados com 28 adições e 0 exclusões
  1. 28 0
      main.py

+ 28 - 0
main.py

@@ -1,5 +1,6 @@
 #! venv/bin/python
 import json
+import re
 import sys
 from pprint import pprint
 
@@ -7,10 +8,31 @@ 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')
+
+
 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
         write_file_next = False
         try:
@@ -29,15 +51,21 @@ if __name__ == '__main__':
             empty_status_file.close()
             sys.exit(1)
         # print(old_status)
+        calculate_next_opportunity = False
         send_message = False
         # print('if old_status {} != status[1] {}'.format(old_status, status[1]))
         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'])}"
         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)