Last active
April 29, 2024 23:06
-
-
Save qlrd/f65afbccf15c68d9c1853028b5e5d9ad to your computer and use it in GitHub Desktop.
Measure some download stats for selfcustody projects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import requests | |
import argparse | |
HEADERS = { | |
"Accept": 'application/vnd.github+json', | |
"X-GitHub-Api-Version": "2022-11-28", | |
} | |
parser = argparse.ArgumentParser( | |
prog='measure-selfcustody-downloads', | |
description='measure the release\'s download in selfcustody') | |
parser.add_argument('-p', '--project', default="krux", help="the project to be summarized (default: krux)") | |
parser.add_argument('-u', '--user', default="selfcustody", help="the user to search for the project (default: selfcustody)") | |
parser.add_argument('-f', '--format', default="json", help="the format to be printed [json, csv] (default: json)") | |
args = parser.parse_args() | |
def make_url(user: str, project: str) -> str: | |
"""Generate Github API url for selected user / project""" | |
return f"https://api.github.com/repos/{user}/{project}/releases" | |
COUNTS = {} | |
ignore_extensions = (".txt", ".sig", ".py", ".gpg", ".sha256") | |
URL = make_url(args.user, args.project) | |
req = requests.get(URL, headers=HEADERS) | |
releases = req.json() | |
for release in releases: | |
for asset in release["assets"]: | |
release_name = asset["name"] | |
if not asset["name"].endswith(ignore_extensions): | |
COUNTS[release_name] = asset["download_count"] | |
if args.format == "json": | |
data = json.dumps(COUNTS, indent=4, sort_keys=True) | |
print(data) | |
if args.format == "csv": | |
print("NAME,DOWNLOAD_COUNT") | |
for key, val in COUNTS.items(): | |
print(f"{key},{val}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Regex are complicated and doesn't always give the result we were expecting, I was having problems when using on seedsigner repo, here is what worked:
good test cases:
-u seedsigner -p seedsigner
-u cryptoadvance -p specter-diy