Skip to content

Commit cd171b4

Browse files
authored
Skip PyPI if all 3 recent are 0 (#233)
Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
1 parent 918eaba commit cd171b4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

fetch_stats.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,12 @@ def fetch_pypi_stats(packages: list[str], output: Path, pepy_api_key: str | None
261261
new_pkg = fetch_pypi_package_stats(pkg, pepy_api_key)
262262
old_pkg = old_packages.get(pkg, {})
263263
safe_merge(new_pkg, old_pkg, ("total",), pkg, allow_zero=False)
264-
safe_merge(new_pkg, old_pkg, ("last_day", "last_week", "last_month"), pkg)
264+
# If all recent stats are 0, likely API failure — keep existing values
265+
if all(new_pkg.get(k, 0) == 0 for k in ("last_day", "last_week", "last_month")):
266+
for k in ("last_day", "last_week", "last_month"):
267+
new_pkg[k] = old_pkg.get(k, 0)
268+
else:
269+
safe_merge(new_pkg, old_pkg, ("last_day", "last_week", "last_month"), pkg)
265270
stats.append(new_pkg)
266271

267272
data = {

0 commit comments

Comments
 (0)