Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -26,7 +26,7 @@ def get_credit_summary(api_key):
|
|
26 |
}
|
27 |
try:
|
28 |
response = requests.get(API_ENDPOINT, headers=headers)
|
29 |
-
response.raise_for_status()
|
30 |
return response.json()
|
31 |
except requests.exceptions.RequestException as e:
|
32 |
logging.error(f"获取额度信息失败,API Key:{api_key},错误信息:{e}")
|
@@ -54,12 +54,16 @@ scheduler = BackgroundScheduler()
|
|
54 |
# 添加定时任务,每小时执行一次 load_keys 函数
|
55 |
scheduler.add_job(load_keys, 'interval', hours=1)
|
56 |
|
57 |
-
# 启动调度器
|
58 |
-
scheduler.start()
|
59 |
-
|
60 |
-
# 为了保持程序运行,添加一个循环
|
61 |
if __name__ == '__main__':
|
|
|
62 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
while True:
|
64 |
time.sleep(120)
|
65 |
except (KeyboardInterrupt, SystemExit):
|
|
|
26 |
}
|
27 |
try:
|
28 |
response = requests.get(API_ENDPOINT, headers=headers)
|
29 |
+
response.raise_for_status()
|
30 |
return response.json()
|
31 |
except requests.exceptions.RequestException as e:
|
32 |
logging.error(f"获取额度信息失败,API Key:{api_key},错误信息:{e}")
|
|
|
54 |
# 添加定时任务,每小时执行一次 load_keys 函数
|
55 |
scheduler.add_job(load_keys, 'interval', hours=1)
|
56 |
|
|
|
|
|
|
|
|
|
57 |
if __name__ == '__main__':
|
58 |
+
logging.info(f"===== Application Startup at {time.strftime('%Y-%m-%d %H:%M:%S')} =====")
|
59 |
try:
|
60 |
+
# 启动调度器
|
61 |
+
scheduler.start()
|
62 |
+
|
63 |
+
# 手动触发一次 load_keys 任务
|
64 |
+
load_keys()
|
65 |
+
logging.info("首次加载 keys 已手动触发执行")
|
66 |
+
|
67 |
while True:
|
68 |
time.sleep(120)
|
69 |
except (KeyboardInterrupt, SystemExit):
|