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