Skip to content
This repository was archived by the owner on Jul 5, 2023. It is now read-only.

Commit 0a75de9

Browse files
committed
Use PyGithub to deal with Github API
1 parent 6cff6f8 commit 0a75de9

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

.github/workflows/stats.yml

-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ jobs:
4040
4141
- name: Generate statistics
4242
id: statistics
43-
continue-on-error: true
4443
run: |
4544
python -m venv venv
4645
source venv/bin/activate
@@ -51,7 +50,6 @@ jobs:
5150
5251
- name: Commit the statistics
5352
uses: stefanzweifel/git-auto-commit-action@v4
54-
if: steps.statistics.outcome == 'success'
5553
with:
5654
commit_message: Update ${{ env.stats_json }}
5755
commit_options: '--no-verify --signoff'

static/scripts/stats/counts.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from datetime import date
44

55
import condastats.cli
6-
import requests
6+
from github import Github
77

88

99
def _write_archive(archive_path, download_count):
@@ -49,8 +49,9 @@ def pypi_count(package, archive_pypi):
4949

5050
def github_count(user, package, archive_github):
5151
"""Download count through the GitHub repository."""
52-
r = requests.get(f'https://api.github.com/repos/{user}/{package}/releases')
53-
download_count = sum(sum(map(lambda d: d['download_count'], release['assets'])) for release in r.json())
52+
gh = Github()
53+
repo = gh.get_repo(f"{user}/{package}")
54+
download_count = sum(sum(map(lambda d: d.download_count, release.get_assets())) for release in repo.get_releases())
5455
_write_archive(archive_github, download_count)
5556
return download_count
5657

static/scripts/stats/requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
condastats==0.2.1
2-
requests==2.28.1
2+
PyGithub==1.57

0 commit comments

Comments
 (0)