Spaces:
Running
Running
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() | |