Last active
March 18, 2016 05:24
-
-
Save kxxoling/a8dc64fbe8bd6b1260e4 to your computer and use it in GitHub Desktop.
Used to count repo stars of some github user.
This file contains hidden or 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
from __future__ import print_function | |
import os | |
import requests | |
github_user = os.environ.get('githubuser') | |
api_url = 'https://api.github.com/users/{github_user}/repos?per_page=100'.format(github_user=github_user) | |
if github_user is None: | |
github_user = raw_input('No GitHub username detected, please enter it here: ') | |
def count_stars(url): | |
rsp = requests.get(url) | |
repos = rsp.json() | |
star_count = sum([repo['stargazers_count'] for repo in repos]) | |
return rsp, star_count | |
rsp, star_counted = count_stars(api_url) | |
if rsp.links: | |
last_url = rsp.links['last']['url'] | |
page_count = int(last_url.rsplit('=', 1)[-1]) | |
pages = [api_url+'&page=%d'%i for i in range(2, page_count+1)] | |
star_counted = sum([item[-1] for item in map(count_stars, pages)], star_counted) | |
print(star_counted) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use prompt to set username can be:
TMP="/tmp/counter.py"; curl https://gist.githubusercontent.com/kxxoling/a8dc64fbe8bd6b1260e4/raw/ > $TMP; python $TMP; rm $TMP