mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-05-15 10:22:26 +12:00
Adds a small script to shows github's releases download stats (using: make stats)
This commit is contained in:
parent
b37dc9715c
commit
447fbb4a2a
84
libs/gh-release-stats.py
Normal file
84
libs/gh-release-stats.py
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# --!-- coding: utf8 --!--
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import json
|
||||||
|
|
||||||
|
url = "https://api.github.com/repos/{user}/{repo}/releases"
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description='Get download count for github releases.')
|
||||||
|
parser.add_argument('user', type=str, help='The github user.')
|
||||||
|
parser.add_argument('repo', type=str, help='The repo of given user.')
|
||||||
|
parser.add_argument("-d", "--details", action="store_true")
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
url = url.format(user=args.user,
|
||||||
|
repo=args.repo)
|
||||||
|
|
||||||
|
def getJSON(URL):
|
||||||
|
import urllib.request
|
||||||
|
with urllib.request.urlopen(URL) as url:
|
||||||
|
data = json.loads(url.read().decode())
|
||||||
|
return data
|
||||||
|
|
||||||
|
def humanReadable(n):
|
||||||
|
s = ["", "K", "M", "B", "T"]
|
||||||
|
f = 1000.
|
||||||
|
hrs = n
|
||||||
|
i = 0
|
||||||
|
while hrs > 500:
|
||||||
|
hrs = hrs / f
|
||||||
|
i += 1
|
||||||
|
hrs = round(hrs, 1)
|
||||||
|
return "{}{}".format(hrs, s[i])
|
||||||
|
|
||||||
|
|
||||||
|
def humanReadableSize(size):
|
||||||
|
s = ["B", "KB", "MB", "GB", "TB"]
|
||||||
|
f = 1024.
|
||||||
|
hrs = size
|
||||||
|
i = 0
|
||||||
|
while hrs > 500:
|
||||||
|
hrs = hrs / f
|
||||||
|
i += 1
|
||||||
|
hrs = round(hrs, 1)
|
||||||
|
return "{} {}".format(hrs, s[i])
|
||||||
|
|
||||||
|
releases = getJSON(url)
|
||||||
|
|
||||||
|
total = 0
|
||||||
|
|
||||||
|
for r in releases:
|
||||||
|
name = r["name"]
|
||||||
|
tag = r["tag_name"]
|
||||||
|
author = r["author"]["login"]
|
||||||
|
time = r["created_at"]
|
||||||
|
|
||||||
|
name = "{} ({})".format(name, tag) if name else tag
|
||||||
|
|
||||||
|
tot = 0
|
||||||
|
details = []
|
||||||
|
for a in r["assets"]:
|
||||||
|
nameA = a["name"]
|
||||||
|
size = a["size"]
|
||||||
|
download_count = a["download_count"]
|
||||||
|
tot += download_count
|
||||||
|
|
||||||
|
details.append(" * {} ({}): {} hits".format(
|
||||||
|
nameA, humanReadableSize(size), humanReadable(download_count))
|
||||||
|
)
|
||||||
|
|
||||||
|
txt = "{}: {} hits".format(name, humanReadable(tot))
|
||||||
|
print(txt)
|
||||||
|
if args.details:
|
||||||
|
print("-" * len(txt))
|
||||||
|
[print(d) for d in details]
|
||||||
|
print("")
|
||||||
|
|
||||||
|
total += tot
|
||||||
|
|
||||||
|
txt = "Total downloads: {} hits".format(humanReadable(total))
|
||||||
|
print("=" * len(txt))
|
||||||
|
print(txt)
|
||||||
|
print("=" * len(txt))
|
3
makefile
3
makefile
|
@ -36,6 +36,9 @@ i18n: $(QMs)
|
||||||
pyinstaller:
|
pyinstaller:
|
||||||
python3 /usr/local/bin/pyinstaller manuskript.spec
|
python3 /usr/local/bin/pyinstaller manuskript.spec
|
||||||
|
|
||||||
|
stats:
|
||||||
|
python3 libs/gh-release-stats.py olivierkes manuskript -d
|
||||||
|
|
||||||
%_rc.py : %.qrc
|
%_rc.py : %.qrc
|
||||||
pyrcc5 "$<" -o "$@"
|
pyrcc5 "$<" -o "$@"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue