nonebot-plugin-acgnshow/nonebot_plugin_acgnshow/util.py

22 lines
523 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
import random
import datetime
from .config import BGIMAGE_PATH
def choose_random_bgimage() -> str:
"""
从背景图片文件夹中随机选择一张图片返回图片的uri地址
"""
randomfile = random.choice(os.listdir(BGIMAGE_PATH))
randomurl = (BGIMAGE_PATH / randomfile).as_uri()
return randomurl
def convert_timestamp(timestamp) -> str:
"""
将时间戳转换为日期格式
"""
return datetime.datetime.fromtimestamp(timestamp).strftime("%Y-%m-%d %H:%M:%S")