Преглед изворни кода

Starting to add alert in JSON object

Foppe Hemminga пре 6 година
родитељ
комит
d73a002315
3 измењених фајлова са 14 додато и 5 уклоњено
  1. 2 1
      main.py
  2. 5 3
      model.py
  3. 7 1
      status-4.json

+ 2 - 1
main.py

@@ -41,7 +41,8 @@ if __name__ == '__main__':
 
         if write_file_next:
             # summary = {'text': status["status"], 'roman': status["roman"], 'integer': status["integer"]}
-            pprint(status)
+            if status['integer'] <= 2:
+                status['alert'] = {'15': False, '10': False, '5': False, '0': False}
             summary_json = json.dumps(status, indent=2)
             print(summary_json)
             write_file = open(f'status-{player_id}.json', 'w')

+ 5 - 3
model.py

@@ -46,8 +46,10 @@ def _get_status(this_id):
     this_status = this_json
     # pprint(this_status)
     status_return = None
+    if 'alert' not in this_status:
+        this_status['alert'] = {'15': False, '10': False, '5': False, '0': False}
     if this_status:
-        status_return = this_status['status'], this_status['name'], this_status['timestamp']
+        status_return = this_status['status'], this_status['name'], this_status['timestamp'], this_status['alert']
     return status_return
 
 
@@ -72,14 +74,14 @@ def _from_roman_to_integer(roman_number):
 
 def get_loot_level(this_id):
     this_loot_level = 0
-    this_status_status, this_status_name, this_status_timestamp = _get_status(this_id)
+    this_status_status, this_status_name, this_status_timestamp, this_status_alert = _get_status(this_id)
     if this_status_status and len(this_status_status) > 1:
         if this_status_status[0] == 'Okay' and 'Loot level' in this_status_status[1]:
             this_loot_level = this_status_status[1][11:].strip()
     # print(this_loot_level)
     this_integer = _from_roman_to_integer(this_loot_level)
     this_status_dict = {"id": this_id, "name": this_status_name, "integer": this_integer, "roman": this_loot_level,
-                        "text": this_status_status, "timestamp": this_status_timestamp}
+                        "text": this_status_status, "timestamp": this_status_timestamp, "alert": this_status_alert}
     return this_status_dict
 
 

+ 7 - 1
status-4.json

@@ -7,5 +7,11 @@
     "Okay",
     "Loot level III"
   ],
-  "timestamp": 1570057202
+  "timestamp": 1570057202,
+  "alert":  {
+    "15": false,
+    "10": false,
+    "5": false,
+    "0": false
+  }
 }