mirror of
https://github.com/ClovertaTheTrilobita/SanYeCao-Nonebot.git
synced 2026-04-01 22:04:51 +00:00
refactor(file_operations): 优化文件路径处理和文件读取方式- 将 Path() / 用法替换为 os.path.join(),以兼容不同操作系统
- 修正文件打开方式,使用 open(file, "rb") 替代 file.open("rb")
- 更新多个文件中的路径处理逻辑,提高代码的可移植性
This commit is contained in:
parent
94136e7e1f
commit
7827d3a8b2
4 changed files with 18 additions and 18 deletions
|
|
@ -23,9 +23,9 @@ async def save_img(data: bytes):
|
||||||
|
|
||||||
async def get_ln_image():
|
async def get_ln_image():
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
file = Path() / temp_path / f"{now.date()}轻小说.png"
|
file = os.path.join(temp_path , f"{now.date()}轻小说.png")
|
||||||
if os.path.exists(file):
|
if os.path.exists(file):
|
||||||
with file.open("rb") as image_file:
|
with open(file,"rb") as image_file:
|
||||||
return image_file.read()
|
return image_file.read()
|
||||||
|
|
||||||
await Wenku8.login()
|
await Wenku8.login()
|
||||||
|
|
|
||||||
|
|
@ -98,9 +98,9 @@ class Report:
|
||||||
async def get_report_image(cls) -> bytes:
|
async def get_report_image(cls) -> bytes:
|
||||||
"""获取数据"""
|
"""获取数据"""
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
file = Path() / temp_path / f"{now.date()}日报.png"
|
file = os.path.join(temp_path,f"{now.date()}日报.png")
|
||||||
if os.path.exists(file):
|
if os.path.exists(file):
|
||||||
with file.open("rb") as image_file:
|
with open(file,"rb") as image_file:
|
||||||
return image_file.read()
|
return image_file.read()
|
||||||
zhdata = ZhDate.from_datetime(now)
|
zhdata = ZhDate.from_datetime(now)
|
||||||
result = await asyncio.gather(
|
result = await asyncio.gather(
|
||||||
|
|
|
||||||
|
|
@ -85,9 +85,9 @@ async def dispose_html(response):
|
||||||
|
|
||||||
async def get_yuc_wiki_image(template_name,width,height):
|
async def get_yuc_wiki_image(template_name,width,height):
|
||||||
|
|
||||||
file = Path() / yuc_wiki_path / f"{template_name}.jpeg"
|
file = os.path.join(yuc_wiki_path, f"{template_name}.jpeg")
|
||||||
if os.path.exists(file):
|
if os.path.exists(file):
|
||||||
with file.open("rb") as image_file:
|
with open(file,"rb") as image_file:
|
||||||
return image_file.read()
|
return image_file.read()
|
||||||
|
|
||||||
image_bytes = await template_to_pic(
|
image_bytes = await template_to_pic(
|
||||||
|
|
|
||||||
|
|
@ -1,41 +1,41 @@
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
path = os.getcwd()+'/src/resources'
|
path = os.path.join(os.getcwd(), '/src/resources')
|
||||||
|
|
||||||
|
|
||||||
# 塔罗牌图片路径
|
# 塔罗牌图片路径
|
||||||
image_local_qq_image_path = path+'/image/qq_image'
|
image_local_qq_image_path = os.path.join(path,'/image/qq_image')
|
||||||
os.makedirs(image_local_qq_image_path, exist_ok=True)
|
os.makedirs(image_local_qq_image_path, exist_ok=True)
|
||||||
# 个人图片路径
|
# 个人图片路径
|
||||||
image_local_path= path+"/image/MaoYuNa"
|
image_local_path= os.path.join(path,"/image/MaoYuNa")
|
||||||
os.makedirs(image_local_path, exist_ok=True)
|
os.makedirs(image_local_path, exist_ok=True)
|
||||||
# 塔罗牌图片路径
|
# 塔罗牌图片路径
|
||||||
tarots_img_path = path+'/image/tarot/TarotImages/'
|
tarots_img_path = os.path.join(path,'/image/tarot/TarotImages/')
|
||||||
os.makedirs(tarots_img_path, exist_ok=True)
|
os.makedirs(tarots_img_path, exist_ok=True)
|
||||||
# 摸摸头图片路径
|
# 摸摸头图片路径
|
||||||
rua_png = path+'/image/rua/'
|
rua_png = os.path.join(path,'/image/rua/')
|
||||||
os.makedirs(rua_png, exist_ok=True)
|
os.makedirs(rua_png, exist_ok=True)
|
||||||
# 喜报、悲报图片路径
|
# 喜报、悲报图片路径
|
||||||
good_bad = path+'/image/good_bad_news/'
|
good_bad = os.path.join(path,'/image/good_bad_news/')
|
||||||
os.makedirs(good_bad, exist_ok=True)
|
os.makedirs(good_bad, exist_ok=True)
|
||||||
#谁说 生成图片路径
|
#谁说 生成图片路径
|
||||||
who_say_path = path+'/image/who_say/'
|
who_say_path = os.path.join(path,'/image/who_say/')
|
||||||
os.makedirs(who_say_path, exist_ok=True)
|
os.makedirs(who_say_path, exist_ok=True)
|
||||||
#yuc_wiki 动漫wiki
|
#yuc_wiki 动漫wiki
|
||||||
yuc_wiki_path = path + '/image/yuc_wiki/'
|
yuc_wiki_path = os.path.join(path , '/image/yuc_wiki/')
|
||||||
os.makedirs(yuc_wiki_path, exist_ok=True)
|
os.makedirs(yuc_wiki_path, exist_ok=True)
|
||||||
# 字体路径
|
# 字体路径
|
||||||
font_path = path + '/font/'
|
font_path = os.path.join(path , '/font/')
|
||||||
os.makedirs(font_path, exist_ok=True)
|
os.makedirs(font_path, exist_ok=True)
|
||||||
# 临时数据路径
|
# 临时数据路径
|
||||||
temp_path = path + '/temp/'
|
temp_path = os.path.join(path , '/temp/')
|
||||||
os.makedirs(temp_path, exist_ok=True)
|
os.makedirs(temp_path, exist_ok=True)
|
||||||
# 日志路径
|
# 日志路径
|
||||||
log_path = path+'/log/'
|
log_path = os.path.join(path,'/log/')
|
||||||
os.makedirs(log_path, exist_ok=True)
|
os.makedirs(log_path, exist_ok=True)
|
||||||
# 视频路径
|
# 视频路径
|
||||||
video_path = path+'/video/'
|
video_path = os.path.join(path,'/video/')
|
||||||
os.makedirs(video_path, exist_ok=True)
|
os.makedirs(video_path, exist_ok=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue