Skip to content

Instantly share code, notes, and snippets.

@myui
Last active December 15, 2016 18:05
Show Gist options
  • Save myui/3d70f6be5349b1ac151a513f7eef7190 to your computer and use it in GitHub Desktop.
Save myui/3d70f6be5349b1ac151a513f7eef7190 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
# sort list.txt | uniq | grep -v '#' | grep -v 'noreply' | grep -v 'local' | grep -e '\.' | grep -v 'internal' | grep -v 'contact'
import os
import sys
import requests
import time
from github3 import login
from tqdm import tqdm
URL = "https://api.github.com/users/{name}/events/public?access_token={token}"
token = os.environ['STARGAZER_ACCESS_TOKEN']
gh = login(token=token)
repo = gh.repository('myui', 'hivemall')
def extract_email(name):
url = URL.format(name=name, token=token)
li = requests.get(url).json()
time.sleep(1) # sleep 1 sec to avoid API rate limit
try:
for d in li:
if d['type'] == 'PushEvent':
return d['payload']['commits'][0]['author']['email']
except:
return None
return None
def print_user(u):
if u.email is None:
email = extract_email(u.login)
if email is not None:
print email
# print "{}|{}|{}|{}|{}".format(u.login,u.name.encode('utf-8'),email,u.company.encode('utf-8'),u.location.encode('utf-8'))
return 1
else:
print u.email
return 1
return 0
def gh_rate_limit_remaining():
return gh.ratelimit_remaining
# print "login|name|email|company|location"
print '# Stargazers'
print >> sys.stderr, "API limit remaining: " + str(gh_rate_limit_remaining())
print >> sys.stderr, '# Stargazers'
cnt = 0
for x in tqdm(repo.iter_stargazers()):
u = gh.user(x)
cnt += print_user(u)
print >> sys.stderr, "Found: " + str(cnt)
print '# Forked Users'
print >> sys.stderr, "API limit remaining: " + str(gh_rate_limit_remaining())
print >> sys.stderr, '# Forked users'
cnt = 0
for fork in tqdm(repo.iter_forks()):
u = fork.owner
cnt += print_user(u)
print >> sys.stderr, "Found: " + str(cnt)
print '# Watchers'
print >> sys.stderr, "API limit remaining: " + str(gh_rate_limit_remaining())
print >> sys.stderr, '# Watchers'
cnt = 0
for u in tqdm(repo.iter_subscribers()):
cnt += print_user(u)
print >> sys.stderr, "Found: " + str(cnt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment