Browse Source

kimi 余额监测

luojunhui 4 months ago
parent
commit
22b4e28bf6
1 changed files with 17 additions and 6 deletions
  1. 17 6
      kimi_balance_monitor.py

+ 17 - 6
kimi_balance_monitor.py

@@ -2,11 +2,12 @@
 @author: luojunhui
 """
 import requests
+import traceback
 
 from applications import bot
 from applications.decoratorApi import retryOnTimeout
 
-BALANCE_LIMIT_THRESHOLD = 200
+BALANCE_LIMIT_THRESHOLD = 200.0
 
 
 @retryOnTimeout(retries=5, delay=5)
@@ -24,17 +25,27 @@ def check_kimi_balance():
     response = requests.request("GET", url, headers=headers, data=payload, timeout=10)
     if response.status_code == 200:
         response_json = response.json()
-        balance = response_json['data']['available_balance']
-        if balance < BALANCE_LIMIT_THRESHOLD:
+        try:
+            balance = response_json['data']['available_balance']
+            if balance < BALANCE_LIMIT_THRESHOLD:
+                bot(
+                    title="kimi余额小于 {} 块".format(BALANCE_LIMIT_THRESHOLD),
+                    detail={
+                        "balance": balance
+                    }
+                )
+        except Exception as e:
+            error_stack = traceback.format_exc()
             bot(
-                title="kimi余额小于 {} 块".format(BALANCE_LIMIT_THRESHOLD),
+                title="kimi余额接口处理失败,数据结构异常",
                 detail={
-                    "balance": balance
+                    "error": str(e),
+                    "error_msg": error_stack
                 }
             )
     else:
         bot(
-            title="kimi余额校验失败",
+            title="kimi余额接口调用失败",
             detail={
                 "response": response.text
             }