-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import re | ||
import asyncio | ||
import aiohttp | ||
|
||
trime_nightly_release = "https://github.com/osfans/trime/releases/tag/nightly" | ||
|
||
async def get_nightly_commit_hash(): | ||
""" | ||
访问github获取信息,组装成下载链接返回 | ||
""" | ||
commit_hash_pattern = r'data-hovercard-type="commit".+?href="/osfans/trime/commit/(.{8})' | ||
async with aiohttp.ClientSession() as session: | ||
async with session.get(trime_nightly_release) as r: | ||
if r.status == 200: | ||
html = await r.read() | ||
html = html.decode('utf-8') | ||
commit_hash = re.search(commit_hash_pattern, html).group(1) | ||
return commit_hash | ||
else: | ||
return r.start | ||
|
||
def generate_nightly_download_link(commit_hash: str) -> list: | ||
url_preix = "https://github.com/osfans/trime/releases/download/nightly/" | ||
return [f"{url_preix}com.osfans.trime-nightly-0-g{commit_hash}-arm64-v8a-release.apk", | ||
f"{url_preix}com.osfans.trime-nightly-0-g{commit_hash}-armeabi-v7a-release.apk", | ||
f"{url_preix}com.osfans.trime-nightly-0-g{commit_hash}-x86-release.apk", | ||
f"{url_preix}com.osfans.trime-nightly-0-g{commit_hash}-x86_64-release.apk"] | ||
|
||
async def get_all_file_info() -> dict: | ||
commit_hash = await get_nightly_commit_hash() | ||
if type(commit_hash) == str: | ||
link = generate_nightly_download_link(commit_hash) | ||
# 生成字典格式: {文件名: 下载链接} | ||
d = {} | ||
for l in link: | ||
d[l.split("/")[-1]] = l | ||
print(d) | ||
return d | ||
else: | ||
print(f"获取trime nightly commit hash出错!状态码:{commit_hash}") | ||
|
||
async def get_file_bytes(url: str): | ||
""" | ||
通过链接下载文件数据,返回bytes | ||
""" | ||
async with aiohttp.request("GET", url=url) as r: | ||
return await r.read() | ||
|
||
async def test(): | ||
commit_hash = await get_nightly_commit_hash() | ||
if type(commit_hash) == str: | ||
link = generate_nightly_download_link(commit_hash) | ||
print('\n'.join(link)) | ||
data = await get_file_bytes(link[0]) | ||
print(data) | ||
|
||
if __name__ == "__main__": | ||
loop = asyncio.get_event_loop() | ||
loop.run_until_complete(test()) |
37 changes: 37 additions & 0 deletions
37
modules/scheduler/TrimeNightlyUpload/trime_nightly_upload.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import datetime | ||
|
||
from bot_init import BOT | ||
from graia.saya import Channel | ||
from graia.scheduler import timers | ||
from graia.ariadne.app import Ariadne | ||
from graia.scheduler.saya import SchedulerSchema | ||
from graia.ariadne.message.chain import MessageChain | ||
from graia.ariadne.message.element import Plain | ||
|
||
from .get_trime_nightly import get_all_file_info, get_file_bytes | ||
|
||
channel = Channel.current() | ||
channel.meta["name"]="同文每夜构建" | ||
channel.meta["author"]="Shitlime" | ||
channel.meta["description"]=""" | ||
定时上传trime nightly build | ||
""" | ||
|
||
config = BOT.get_modules_config("TrimeNightlyUpload") | ||
|
||
# 配置: | ||
enable_group = config["enable_group"] # list | ||
|
||
@channel.use(SchedulerSchema(timer=timers.crontabify("11 0 * * *"))) | ||
async def upload_trime_nightly(app: Ariadne): | ||
file_info = get_all_file_info() | ||
for file_name, file_url in file_info: | ||
data = await get_file_bytes(file_url) | ||
path = f"同文原版(Nightly Build,每夜版){datetime.datetime.today()}" | ||
name = file_name + ".删后缀喵" | ||
for group_num in enable_group: | ||
await app.upload_file( | ||
data=data, | ||
target=group_num, | ||
path=path, | ||
name=name) |