Skip to content

Commit

Permalink
feat: send nightly release body
Browse files Browse the repository at this point in the history
  • Loading branch information
shitlime committed Feb 7, 2024
1 parent 66ccc44 commit 7b4f082
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
26 changes: 11 additions & 15 deletions modules/scheduler/TrimeNightlyUpload/get_trime_nightly.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

github_api_trime_release = "https://api.github.com/repos/osfans/trime/releases?prerelease=true"

async def get_nightly_download_link():
async def get_nightly_info():
"""
访问github api获取信息,组装成下载链接返回
"""
Expand All @@ -28,22 +28,17 @@ async def get_nightly_download_link():
if time.date() != datetime.datetime.now().date():
raise OutdatedAssetsException("不是今天的nightly build")
# 所有 release 文件信息
assets = nightly['assets']
return [ a['browser_download_url'] for a in assets ]
return {'assets': { a['name']: a['browser_download_url'] for a in nightly['assets'] },
'body': nightly['body']}
else:
return r.start

async def get_all_file_info() -> dict:
links = await get_nightly_download_link()
if type(links) == list:
# 生成字典格式: {文件名: 下载链接}
d = {}
for l in links:
d[l.split("/")[-1]] = l
print(d)
return d
async def get_info() -> dict:
infos = await get_nightly_info()
if type(infos) == dict:
return infos
else:
print(f"获取trime nightly下载链接出错!状态码:{links}")
print(f"获取trime nightly下载链接出错!状态码:{infos}")

async def get_file_bytes(url: str):
"""
Expand All @@ -53,10 +48,11 @@ async def get_file_bytes(url: str):
return await r.read()

async def test():
info = await get_all_file_info()
data = await get_file_bytes(list(info.items())[0][1])
info = await get_info()
data = await get_file_bytes(list(info['assets'].items())[0][1])
print(data)
print(len(data))
print(info['body'])

if __name__ == "__main__":
loop = asyncio.get_event_loop()
Expand Down
20 changes: 16 additions & 4 deletions modules/scheduler/TrimeNightlyUpload/trime_nightly_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from graia.ariadne.message.element import Plain

from .OutdatedAssetsException import OutdatedAssetsException
from .get_trime_nightly import get_all_file_info, get_file_bytes
from .get_trime_nightly import get_info, get_file_bytes

channel = Channel.current()
channel.meta["name"]="同文每夜构建"
Expand All @@ -28,18 +28,20 @@
@channel.use(SchedulerSchema(timer=timers.crontabify("3 0 * * *")))
async def upload_trime_nightly(app: Ariadne):
# 获取nightly build信息,每120s请求一次,最多60次
file_info = None
all_info = None
count = 1
while file_info is None and count <= 60:
while all_info is None and count <= 60:
try:
file_info = await get_all_file_info()
all_info = await get_info()
except OutdatedAssetsException as e:
print(f"{e.message}{count}次 120s后重新获取")
await asyncio.sleep(120)
finally:
count += 1

# 上传到群文件
file_info = all_info['assets']
body = all_info['body']
for file_name, file_url in file_info.items():
data = await get_file_bytes(file_url)
path_pattern = r"同文原版.+Nightly.+"
Expand All @@ -58,3 +60,13 @@ async def upload_trime_nightly(app: Ariadne):
name=name)
print(f"{file_name}上传完成")
break

# 发送release body
for group_num in enable_group:
group = await app.get_group(group_num)
await app.send_message(
target=group,
message=MessageChain(
Plain(body)
)
)

0 comments on commit 7b4f082

Please sign in to comment.