This repository has been archived by the owner on Oct 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_bundle.py
58 lines (52 loc) · 2.11 KB
/
gen_bundle.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
import asyncio
import json
from httpx import AsyncClient
async def get_latest_release(repo_url, prerelease = False):
async def get_version_url(release):
version = release['tag_name']
for asset in release["assets"]:
if asset["browser_download_url"].endswith(".jar") or\
asset["browser_download_url"].endswith(".apk"):
asset_url = asset['browser_download_url']
return version, asset_url
print(f"No asset found for the {version}")
return None, None
api_url = f"{repo_url}/releases"
response = await AsyncClient().get(api_url)
if response.status_code == 200:
releases = response.json()
if prerelease:
for release in releases:
if release["prerelease"]:
version, asset_url = await get_version_url(release)
return version, asset_url
else:
for release in releases:
if not release["prerelease"]:
version, asset_url = await get_version_url(release)
return version, asset_url
print(f"No release found for the {repo_url}")
return None, None
async def main():
with open('sources.json') as file:
sources = json.load(file)
for source, repo in sources.items():
patches_version, patches_asset_url = await get_latest_release(repo.get('patches'),
repo.get('prerelease', False))
integration_version, integration_asset_url = await get_latest_release(repo.get('integration'),
repo.get('prerelease', False))
info_dict = {
"patches": {
"version": patches_version,
"url": patches_asset_url
},
"integrations": {
"version": integration_version,
"url": integration_asset_url
}
}
with open(f'{source}-bundle.json', 'w') as file:
json.dump(info_dict, file, indent=2)
print(f"Latest release information saved to {source}-bundle.json")
if __name__ == "__main__":
asyncio.run(main())