Skip to content

Commit ffe0e05

Browse files
committed
Python: Convert get_download_count.sh to python
1 parent 2f80179 commit ffe0e05

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
import json
3+
import urllib.request
4+
5+
FDSURL = "https://api.github.com/repos/firemodels/fds/releases"
6+
SMVURL = "https://api.github.com/repos/firemodels/smv/releases"
7+
BUNDLE = "FDS-6.10.1_SMV-6.10.1"
8+
SMV = "SMV-6.10.5"
9+
LINUX = "_lnx.sh"
10+
OSX = "_osx.sh"
11+
WIN = "_win.exe"
12+
13+
14+
def get_downloads(filename: str, releases_url: str) -> int:
15+
"""
16+
Retrieve the download count for a given asset filename from a GitHub releases feed.
17+
Returns 0 if the asset cannot be found.
18+
"""
19+
request = urllib.request.Request(
20+
releases_url,
21+
headers={
22+
"Accept": "application/vnd.github+json",
23+
"User-Agent": "python-urllib"
24+
},
25+
)
26+
with urllib.request.urlopen(request, timeout=30) as response:
27+
releases = json.load(response)
28+
29+
for release in releases:
30+
for asset in release.get("assets", []):
31+
if asset.get("name") == filename:
32+
return int(asset.get("download_count", 0))
33+
return 0
34+
35+
36+
print("bundle downloads")
37+
print(f"FILE={BUNDLE}{LINUX} downloads={get_downloads(BUNDLE + LINUX, FDSURL)}")
38+
print(f"FILE={BUNDLE}{OSX} downloads={get_downloads(BUNDLE + OSX, FDSURL)}")
39+
print(f"FILE={BUNDLE}{WIN} downloads={get_downloads(BUNDLE + WIN, FDSURL)}")
40+
41+
print("")
42+
print("smokeview downloads")
43+
print(f"FILE={SMV}{LINUX} downloads={get_downloads(SMV + LINUX, SMVURL)}")
44+
print(f"FILE={SMV}{OSX} downloads={get_downloads(SMV + OSX, SMVURL)}")
45+
print(f"FILE={SMV}{WIN} downloads={get_downloads(SMV + WIN, SMVURL)}")
46+

0 commit comments

Comments
 (0)