|
49 | 49 | # i.e. are not named 'Adafruit_CircuitPython_'.
|
50 | 50 | PYPI_FORCE_NON_CIRCUITPYTHON = ["Adafruit-Blinka"]
|
51 | 51 |
|
| 52 | +# https://www.piwheels.org/json.html |
| 53 | +PIWHEELS_PACKAGES_URL = "https://www.piwheels.org/packages.json" |
52 | 54 |
|
53 |
| -def pypistats_get(repo_name): |
54 |
| - # get download stats for the last week |
55 |
| - api_url = "https://pypistats.org/api/packages/" + repo_name + "/recent" |
56 |
| - pypi_stats_last_week = requests.get(api_url, timeout=30) |
57 |
| - if not pypi_stats_last_week.ok: |
58 |
| - # return "Failed to retrieve data ({})".format(pypi_stats.text) |
59 |
| - return None, None |
60 |
| - pypi_dl_last_week = pypi_stats_last_week.json()["data"]["last_week"] |
61 |
| - |
62 |
| - # get total download stats |
63 |
| - pypi_dl_total = 0 |
64 |
| - api_url = "https://pypistats.org/api/packages/" + repo_name + "/overall?mirrors=false" |
65 |
| - pypi_stats_total = requests.get(api_url, timeout=30) |
66 |
| - if pypi_stats_total.ok: |
67 |
| - for data in pypi_stats_total.json()["data"]: |
68 |
| - pypi_dl_total += data["downloads"] |
69 |
| - |
70 |
| - return pypi_dl_last_week, pypi_dl_total |
| 55 | + |
| 56 | +def piwheels_stats(): |
| 57 | + stats = {} |
| 58 | + response = requests.get(PIWHEELS_PACKAGES_URL) |
| 59 | + if response.ok: |
| 60 | + packages = response.json() |
| 61 | + stats = { |
| 62 | + pkg: {"total": dl_all, "month": dl_month} |
| 63 | + for pkg, dl_month, dl_all, *_ in packages if pkg.startswith("adafruit") |
| 64 | + } |
| 65 | + |
| 66 | + return stats |
71 | 67 |
|
72 | 68 | def get_pypi_stats():
|
73 | 69 | successful_stats = {}
|
74 | 70 | failed_stats = []
|
75 | 71 | repos = common_funcs.list_repos()
|
| 72 | + dl_stats = piwheels_stats() |
76 | 73 | for repo in repos:
|
77 | 74 | if (repo["owner"]["login"] == "adafruit" and repo["name"].startswith("Adafruit_CircuitPython")):
|
78 | 75 | if common_funcs.repo_is_on_pypi(repo):
|
79 |
| - pypi_dl_last_week, pypi_dl_total = pypistats_get(repo["name"].replace("_", "-").lower()) |
80 |
| - if pypi_dl_last_week is None: |
| 76 | + pkg_name = repo["name"].replace("_", "-").lower() |
| 77 | + if pkg_name in dl_stats: |
| 78 | + successful_stats[repo["name"]] = (dl_stats[pkg_name]["month"], dl_stats[pkg_name]["total"]) |
| 79 | + else: |
81 | 80 | failed_stats.append(repo["name"])
|
82 |
| - continue |
83 |
| - successful_stats[repo["name"]] = (pypi_dl_last_week, pypi_dl_total) |
84 | 81 |
|
85 | 82 | for lib in PYPI_FORCE_NON_CIRCUITPYTHON:
|
86 |
| - pypi_dl_last_week, pypi_dl_total = pypistats_get(lib.lower()) |
87 |
| - if pypi_dl_last_week is None: |
88 |
| - failed_stats.append(lib) |
89 |
| - continue |
90 |
| - successful_stats[lib] = (pypi_dl_last_week, pypi_dl_total) |
| 83 | + pkg_name = lib.lower() |
| 84 | + if pkg_name in dl_stats: |
| 85 | + successful_stats[lib] = (dl_stats[pkg_name]["month"], dl_stats[pkg_name]["total"]) |
| 86 | + else: |
| 87 | + failed_stats.append(repo["name"]) |
91 | 88 |
|
92 | 89 | return successful_stats, failed_stats
|
93 | 90 |
|
@@ -142,9 +139,9 @@ def run_stat_check():
|
142 | 139 |
|
143 | 140 | pypi_downloads = {}
|
144 | 141 | pypi_failures = []
|
145 |
| - downloads_list = [["| Library", "| Last Week", "| Total |"], |
| 142 | + downloads_list = [["| Library", "| Last Month", "| Total |"], |
146 | 143 | ["|:-------", "|:--------:", "|:-----:|"]]
|
147 |
| - output_handler("Adafruit CircuitPython Library PyPi downloads:") |
| 144 | + output_handler("Adafruit CircuitPython Library Piwheels downloads:") |
148 | 145 | output_handler()
|
149 | 146 | pypi_downloads, pypi_failures = get_pypi_stats()
|
150 | 147 | for stat in sorted(pypi_downloads.items(), key=operator.itemgetter(1,1), reverse=True):
|
|
0 commit comments