فهرست منبع

Refactor `id` into `player_id` and minor change in output

Foppe Hemminga 6 سال پیش
والد
کامیت
cbc2fd9858
3فایلهای تغییر یافته به همراه9 افزوده شده و 15 حذف شده
  1. 7 6
      main.py
  2. 0 8
      status.json
  3. 2 1
      view.py

+ 7 - 6
main.py

@@ -8,13 +8,13 @@ import view
 
 
 if __name__ == '__main__':
-    for id in [4, 15]:
-        status = model.get_loot_level(id)
+    for player_id in [4, 15]:
+        status = model.get_loot_level(player_id)
         # print(status)
         old_status = 0
         write_file_next = False
         try:
-            old_status_file = open(f'status-{id}.json', 'r')
+            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:
@@ -24,7 +24,7 @@ if __name__ == '__main__':
                     write_file_next = True
             old_status_file.close()
         except FileNotFoundError:
-            empty_status_file = open(f'status-{id}.json', 'w+')
+            empty_status_file = open(f'status-{player_id}.json', 'w+')
             print('Created new file ... Exiting')
             empty_status_file.close()
             sys.exit(1)
@@ -32,7 +32,8 @@ if __name__ == '__main__':
         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'])}"
+        assert type(status['integer']) is int, \
+            f"status['integer'] {status['integer']} is not an integer: {type(status['integer'])}"
         if old_status != status['integer']:
             write_file_next = True
             send_message = True
@@ -42,7 +43,7 @@ if __name__ == '__main__':
             pprint(status)
             summary_json = json.dumps(status, indent=2)
             print(summary_json)
-            write_file = open(f'status-{id}.json', 'w')
+            write_file = open(f'status-{player_id}.json', 'w')
             write_file.write(summary_json)
             write_file.close()
             write_file.close()

+ 0 - 8
status.json

@@ -1,8 +0,0 @@
-{
-  "integer": 0,
-  "roman": 0,
-  "text": [
-    "In hospital for 1 hrs 51 mins ",
-    "Defeated by <a href=\"profiles.php?XID=2157516\">AlexSosa</a>"
-  ]
-}

+ 2 - 1
view.py

@@ -14,7 +14,8 @@ def send_message(status):
     webhooks_json = os.environ["DISCORD_TOKENS"]
     webhooks = json.loads(webhooks_json)
     name = status['name']
-    status_text = f"{name} Loot level changed to "+roman.toRoman(status['integer'])
+    its_id = status['id']
+    status_text = f"{name} [{its_id}] → Loot level changed to "+roman.toRoman(status['integer'])
     this_json = {'content': status_text}
     pprint(this_json)
     for webhook in webhooks: