Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,35 @@
|
|
1 |
-
|
|
|
|
|
|
|
2 |
|
3 |
-
|
|
|
|
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
processed_data = data
|
19 |
-
|
20 |
-
return jsonify({'message': 'Success', 'data': processed_data})
|
21 |
|
22 |
-
|
23 |
-
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import time
|
3 |
+
import logging
|
4 |
+
from threading import Thread
|
5 |
|
6 |
+
# 配置日志记录器
|
7 |
+
logging.basicConfig(level=logging.INFO,
|
8 |
+
format='%(asctime)s - %(levelname)s - %(message)s')
|
9 |
|
10 |
+
def load_keys():
|
11 |
+
"""
|
12 |
+
从环境变量中加载 API 密钥,并在日志中输出。
|
13 |
+
"""
|
14 |
+
keys_str = os.environ.get("KEYS")
|
15 |
+
if keys_str:
|
16 |
+
keys = [key.strip() for key in keys_str.split(',')]
|
17 |
+
logging.info("已加载的 API 密钥:")
|
18 |
+
for key in keys:
|
19 |
+
logging.info(key)
|
20 |
+
else:
|
21 |
+
logging.warning("未找到名为 KEYS 的环境变量")
|
22 |
|
23 |
+
def scheduled_task():
|
24 |
+
"""
|
25 |
+
每小时执行一次的定时任务。
|
26 |
+
"""
|
27 |
+
while True:
|
28 |
+
load_keys()
|
29 |
+
# 休眠一小时
|
30 |
+
time.sleep(3600)
|
|
|
|
|
|
|
31 |
|
32 |
+
# 启动定时任务
|
33 |
+
thread = Thread(target=scheduled_task)
|
34 |
+
thread.daemon = True
|
35 |
+
thread.start()
|