-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmmx.py
executable file
·79 lines (69 loc) · 2.27 KB
/
mmx.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python3
"""Xiaomi.eu downloads scraper"""
import asyncio
import json
import os
import re
import sys
import xml.etree.ElementTree as eT
from aiohttp import ClientSession
async def fetch(session, url):
""" Fetch website page """
async with session.get(url) as response:
return await response.text()
async def load_eu_data():
"""
load Xiaomi.eu devices downloads
"""
eu_url = "https://sourceforge.net/projects/miuimix/rss?path=/"
async with ClientSession() as session:
stable = eT.fromstring(await fetch(session, f'{eu_url}/weekly'))
weekly = eT.fromstring(await fetch(session, f'{eu_url}/stable'))
stable_links = [i.find('link').text for i in stable[0].findall('item')]
weekly_links = [i.find('link').text for i in weekly[0].findall('item')]
return [*stable_links, *weekly_links]
async def load_eu_codenames():
"""
load Xiaomi.eu devices codenames
"""
GITHUB_ORG = "https://raw.githubusercontent.com/XiaomiFirmwareUpdater"
async with ClientSession() as session:
raw = await fetch(session, f'{GITHUB_ORG}/xiaomi_devices/eu/devices.json')
models = json.loads(raw)
return models
async def get_eu(codename, eu_data, devices):
"""
fetch latest xiaomi_eu links for a device
"""
stable_link = ""
weekly_link = ""
device = sys.argv[1]
try:
stable_link = [i for i in eu_data if re.search(f"{device}_", i)
and re.search(f'{device}_V', i)][0]
except IndexError:
pass
try:
weekly_link = [i for i in eu_data if re.search(f"{device}_", i)
and not re.search(f'{device}_V', i)][0]
except IndexError:
pass
links = [stable_link, weekly_link]
return links
eu_data = asyncio.run(load_eu_data())
devices = asyncio.run(load_eu_codenames())
device = "lavender"
url = asyncio.run(get_eu(device, eu_data, devices))
stable_link = url[0]
weekly_link = url[1]
VERSION = sys.argv[2]
if VERSION == "stable":
file = "url"
with open(file, 'w+') as load:
print("stable link: " + stable_link)
load.write(stable_link)
elif VERSION == "beta":
file = "url"
with open(file, 'w+') as load:
print("weekly link: " + weekly_link)
load.write(weekly_link)