在请求中使用异步代替同步防止进程阻塞,优化部分代码样式

This commit is contained in:
远野千束 2024-08-15 18:22:29 +08:00
parent fc5931bf33
commit e82edfcae6

View File

@ -1,10 +1,14 @@
from .config import BGIMAGE_PATH from .config import BGIMAGE_PATH
import random import random
import datetime import datetime
def choose_random_bgimage(): def choose_random_bgimage():
randomfile = random.choice(list(BGIMAGE_PATH.iterdir())) randomfile = random.choice(list(BGIMAGE_PATH.iterdir()))
randomurl = randomfile.as_uri() randomurl = randomfile.as_uri()
return randomurl return randomurl
def convert_timestamp(timestamp): def convert_timestamp(timestamp):
obj = datetime.datetime.fromtimestamp(timestamp) obj = datetime.datetime.fromtimestamp(timestamp)
formatted_time = obj.strftime('%Y-%m-%d %H:%M:%S') formatted_time = obj.strftime('%Y-%m-%d %H:%M:%S')