🐛 Try to fix 404 file
This commit is contained in:
parent
f5f22816ed
commit
7921e259e2
@ -52,12 +52,27 @@ def compare() -> List[Module]:
|
||||
return data
|
||||
|
||||
|
||||
async def download(url: str, name: str) -> str:
|
||||
async def download(url: str, name: str, pack_name: str) -> (str, str):
|
||||
content = await client.get(url)
|
||||
if content.status_code == 404:
|
||||
content = (await client.get(f"https://modules.lsposed.org/module/{pack_name}.json")).json()
|
||||
data = Module(content)
|
||||
url = None
|
||||
if data.releases:
|
||||
if data.releases[0].releaseAssets:
|
||||
url = data.releases[0].releaseAssets[0].url
|
||||
mime = data.releases[0].releaseAssets[0].name.split(".")[-1:][0]
|
||||
name = data.name.replace('.', '_') + "-" + data.latestRelease + "." + mime
|
||||
if url:
|
||||
content = await client.get(url)
|
||||
if content.status_code == 404:
|
||||
raise FileNotFoundError
|
||||
else:
|
||||
raise FileNotFoundError
|
||||
content = content.content
|
||||
with open(f"data{sep}{name}", 'wb') as f:
|
||||
f.write(content)
|
||||
return f"data{sep}{name}"
|
||||
return f"data{sep}{name}", url
|
||||
|
||||
|
||||
def from_name_to_module(name: str) -> Optional[Module]:
|
||||
|
@ -34,26 +34,30 @@ async def run_every_30_minute():
|
||||
track_msg = gen_update_msg(i)
|
||||
msg = None
|
||||
if track_msg.url:
|
||||
file = await download(track_msg.url, track_msg.name)
|
||||
try:
|
||||
msg = await send_track_msg(file, track_msg)
|
||||
except FloodWait as e:
|
||||
print(f"Send document flood - Sleep for {e.x} second(s)")
|
||||
await sleep(uniform(0.5, 1.0))
|
||||
msg = await send_track_msg(file, track_msg)
|
||||
except ButtonUrlInvalid:
|
||||
print(f"Send button error")
|
||||
msg = await app.send_document(channel_id, file,
|
||||
caption=track_msg.text,
|
||||
force_document=True,
|
||||
parse_mode="html", )
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
try:
|
||||
remove(file)
|
||||
file, url = await download(track_msg.url, track_msg.name, i.name)
|
||||
track_msg.url = url
|
||||
try:
|
||||
msg = await send_track_msg(file, track_msg)
|
||||
except FloodWait as e:
|
||||
print(f"Send document flood - Sleep for {e.x} second(s)")
|
||||
await sleep(uniform(0.5, 1.0))
|
||||
msg = await send_track_msg(file, track_msg)
|
||||
except ButtonUrlInvalid:
|
||||
print(f"Send button error")
|
||||
msg = await app.send_document(channel_id, file,
|
||||
caption=track_msg.text,
|
||||
force_document=True,
|
||||
parse_mode="html", )
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
try:
|
||||
remove(file)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
else:
|
||||
track_msg.url = None
|
||||
if not track_msg.url:
|
||||
try:
|
||||
msg = await send_track_msg(None, track_msg)
|
||||
except FloodWait as e:
|
||||
|
Loading…
Reference in New Issue
Block a user