Skip to content

Instantly share code, notes, and snippets.

@imosquera
Created May 3, 2020 18:02
Show Gist options
  • Save imosquera/26f0c42766400b5303d205e869faba15 to your computer and use it in GitHub Desktop.
Save imosquera/26f0c42766400b5303d205e869faba15 to your computer and use it in GitHub Desktop.
import unicodecsv as csv
import urllib
import sys
import json
import requests
users_url = "https://api.github.com/users/%s"
# Use the following query to export all the user logins
# SELECT
# actor.login
# FROM `githubarchive.month.*`
# WHERE repo.name like 'spinnaker/%'
# AND _TABLE_SUFFIX > '2020'
# AND type IN ('ForkEvent', 'PushEvent', 'WatchEvent', 'IssuesEvent', 'PullRequestReviewCommentEvent', 'PullRequestEvent')
# GROUP BY actor.login
#
#Generate New Token Here:
#https://github.com/settings/tokens
token = "YOUR TOKEN GOES HERE"
user_list = []
with open('logins.csv') as csvfile:
spamreader = csv.reader(csvfile)
for cnt, row, in enumerate(spamreader):
if cnt == 0:
continue #Skip header row
print(users_url % row[0])
u = requests.get(users_url % row[0], auth=("imosquera", token)).json()
try:
c = u.get("company")
if c is not None and len(c) >= 1 and c[0] == "@":
c = c[1:]
user_tuple = (u["login"], c)
except:
print("error parsing")
print(u)
user_list.append(user_tuple)
print cnt
with open('names.csv', "w") as csvfile:
w = csv.writer(csvfile, encoding='utf-8')
fieldnames = ["login", "company"]
w.writerow(fieldnames)
w.writerows(user_list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment