From e9a09b7b26b5ff80a233d87aa1828e5dbd8aa6b0 Mon Sep 17 00:00:00 2001 From: jon85p Date: Sun, 11 Dec 2016 17:19:33 -0500 Subject: [PATCH] :wrench: API limit solved :heavy_plus_sign: User auth added --- GHLUBL.py | 15 +++++++++++++-- README.md | 3 ++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/GHLUBL.py b/GHLUBL.py index 8b25431..113f1ac 100755 --- a/GHLUBL.py +++ b/GHLUBL.py @@ -5,6 +5,8 @@ import optparse import os import csv +import getpass +from time import sleep def find_between(s, first, last, starting=0): @@ -51,7 +53,7 @@ def find_users(htmls): def main(): parser = optparse.OptionParser(sys.argv[0] + ' -c city -o output') parser.add_option('-c', dest='coption', type='string', - help='City for search') + help='City for search (multiple with "")') parser.add_option('-o', dest='ooption', type='string', help='Output file in .csv format') (options, args) = parser.parse_args() @@ -93,10 +95,19 @@ def main(): exit(0) print('Looking info for each user...') dict_list = [] + # Use auth user for API limit + user_auth = input('>>GitHub user: ') + pwd_auth = getpass.getpass('>>Password: ') for cont, user in enumerate(users): - r = requests.get('https://api.github.com/users/' + user) + r = requests.get('https://api.github.com/users/' + user, + auth=(user_auth, pwd_auth)) + if 'Bad credentials' in r.text: + print('Bad credentials, exiting...') + exit(0) dicc = r.json() print(str(cont + 1), '/', str(len(users)), sep='') + # Limit API + sleep(1) dict_list.append(dicc) print('Saving csv file', output_filename) try: diff --git a/README.md b/README.md index 5fa683b..c6c94ad 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # GHLUBL GitHub Lookup Users By Location -⚠️ Rate API Limit Problem +Example: +
GHLUBL.py -c "Hong Kong" -o output.csv