Spaces:
Sleeping
Sleeping
File size: 2,152 Bytes
b9d0462 |
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
import json
import os
from datetime import datetime
import cachetools#缓存模块
#将config中导入的内容作为函数返回的结果加入缓存,通过定时更新缓存来更新config
ROTATE = 1 #TTLCache(maxsize = 1, ttl = ROTATE) 表示缓存的生存时间为ttl秒。 最大容量为maxsize个条目。
@cachetools.cached(cachetools.TTLCache(maxsize = 1, ttl = ROTATE))
def get_variables():
# 获取当前脚本的根目录路径
current_dir = os.path.dirname(os.path.abspath(__file__))
current_config_json = os.path.join(current_dir, "config.json")
def get_config_data()->json:
with open(current_config_json,'r')as f:
data = json.load(f)
return data
data = get_config_data()
#是否允许定时任务执行->方便开关任务
allow_scheduler = data['allow_scheduler']
#设置manga保存路径
manga_dir = data['manga_dir']
#设置mask保存路径
mask_dir = data['mask_dir']
#获取manga绝对路径
manga_abs_dir = os.path.join(current_dir, manga_dir)
#获取mask绝对路径
mask_abs_dir = os.path.join(current_dir, mask_dir)
#可以选择的两项,包括manga绝对路径和mask绝对路径
default_values = [manga_abs_dir, mask_abs_dir]
#需要执行任务的bili 容器space的url
# bili_space = ['https://rogerxavier-moviepy-with-manga-test.hf.space'
# ,'https://rogerxavier-moviepy-with-manga-bili-2.hf.space'
# ]
#不能加下划线,因为后面拼接的时候加了一个 且必须https
bili_spaces = ['https://rogerxavier-moviepy-with-manga-test.hf.space'
]
return {
"allow_scheduler": allow_scheduler,
"manga_dir": manga_dir,
"mask_dir": mask_dir,
"manga_abs_dir": manga_abs_dir,
"mask_abs_dir": mask_abs_dir,
"default_values": default_values,
"bili_spaces": bili_spaces,
"current_config_json":current_config_json,
"current_dir":current_dir
}
from utils import * #写在这里防止循环引用的时候utils中导入manga_abs_dir出错
|