Prechádzať zdrojové kódy

Looks like time predictions work

Foppe Hemminga 6 rokov pred
rodič
commit
be3416fd9f
6 zmenil súbory, kde vykonal 48 pridanie a 14 odobranie
  1. 11 1
      main.py
  2. 26 4
      model.py
  3. 1 0
      requirements.txt
  4. 5 5
      status-15.json
  5. 4 4
      status-4.json
  6. 1 0
      view.py

+ 11 - 1
main.py

@@ -3,6 +3,8 @@ import json
 # import sys
 from pprint import pprint
 
+import arrow
+
 import model
 import view
 
@@ -47,6 +49,14 @@ if __name__ == '__main__':
             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 = int(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 send_message:
-            # pass
             view.send_message(status)

+ 26 - 4
model.py

@@ -2,6 +2,7 @@ import json
 # from pprint import pprint
 import re
 
+import arrow
 from dotenv import load_dotenv
 import os
 import random
@@ -133,8 +134,29 @@ def extract_hospital_time(this_message_text):
     return hours * 60 * 60 + minutes * 60 + seconds
 
 
-"""
 def calculate_time_to_next_attack(this_player_id):
-    pass
-    # this_status_json, this_status = _read_json_file(this_player_id)
-"""
+    this_status_json, this_status_integer = _read_json_file(this_player_id)
+    if this_status_json == -1 or this_status_integer == -1:
+        return -1
+    seconds_till_level_iv = 0
+    starting_time = int(this_status_json['timestamp'])
+    if this_status_integer >= 0:
+        status_text = this_status_json['text']
+        seconds_till_level_iv += extract_hospital_time(status_text)
+    if this_status_integer >= 1:
+        seconds_till_level_iv += 30 * 60
+    if this_status_integer >= 2:
+        seconds_till_level_iv += 90 * 60
+    if this_status_integer >= 3:
+        seconds_till_level_iv += 210 * 60
+    if this_status_integer == 4:
+        seconds_till_level_iv = 0
+    apocalypse_time = starting_time + seconds_till_level_iv
+    time_now = arrow.utcnow().timestamp
+    diff = apocalypse_time - time_now
+    print(diff)
+    diff_in_minutes = int(diff//60)
+    print(
+        f'starting time {starting_time}, seconds_till_level_iv {seconds_till_level_iv}, apocalypse_time {apocalypse_time}')
+    return diff, apocalypse_time
+

+ 1 - 0
requirements.txt

@@ -1,3 +1,4 @@
+arrow
 roman
 # dotenv
 python-dotenv

+ 5 - 5
status-15.json

@@ -1,11 +1,11 @@
 {
   "id": 15,
   "name": "Leslie",
-  "integer": 0,
-  "roman": 0,
+  "integer": 3,
+  "roman": "III",
   "text": [
-    "In hospital for 1 hrs 4 mins ",
-    "Defeated by <a href=\"profiles.php?XID=681394\">WAGABUND</a>"
+    "Okay",
+    "Loot level III"
   ],
-  "timestamp": 1570022087
+  "timestamp": 1570052435
 }

+ 4 - 4
status-4.json

@@ -1,11 +1,11 @@
 {
   "id": 4,
   "name": "Duke",
-  "integer": 3,
-  "roman": "III",
+  "integer": 2,
+  "roman": "II",
   "text": [
     "Okay",
-    "Loot level III"
+    "Loot level II"
   ],
-  "timestamp": 1570019197
+  "timestamp": 1570052434
 }

+ 1 - 0
view.py

@@ -16,6 +16,7 @@ def send_message(status):
     name = status['name']
     its_id = status['id']
     status_text = f"[{name} \[{its_id}\]](https://www.torn.com/profiles.php?XID={its_id}) → Loot level changed to "+roman.toRoman(status['integer'])
+    status_text += "\n" + status['time_string']
     this_json = {'content': status_text}
     pprint(this_json)
     for webhook in webhooks: