From 21bd21edf560eb3bbacc238348a398ba9519206b Mon Sep 17 00:00:00 2001 From: Surya Umapathy Date: Thu, 15 Dec 2022 12:10:38 +0530 Subject: [PATCH] Refactor: Using personal token instead of password --- credentials.json | 2 +- get_github_data.py | 28 +++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/credentials.json b/credentials.json index 8f81624..ce01819 100644 --- a/credentials.json +++ b/credentials.json @@ -1,4 +1,4 @@ { "username": , - "password": + "password": } \ No newline at end of file diff --git a/get_github_data.py b/get_github_data.py index 2a65e0e..2248d56 100644 --- a/get_github_data.py +++ b/get_github_data.py @@ -7,11 +7,17 @@ from requests.auth import HTTPBasicAuth credentials = json.loads(open('credentials.json').read()) -authentication = HTTPBasicAuth(credentials['username'], credentials['password']) -data = requests.get('https://api.github.com/users/' + credentials['username'], auth = authentication) +data = requests.get('https://api.github.com/users/' + credentials['username'], +headers={ + "X-GitHub-Api-Version": "2022-11-28", + "Accept": "application/vnd.github+json", + "Authorization": "Bearer " + credentials['password'] + }) data = data.json() +print(data) + print("Information about user {}:\n".format(credentials['username'])) print("Name: {}".format(data['name'])) print("Email: {}".format(data['email'])) @@ -25,7 +31,11 @@ page_no = 1 repos_data = [] while (True): - response = requests.get(url, auth = authentication) + response = requests.get(url, headers={ + "X-GitHub-Api-Version": "2022-11-28", + "Accept": "application/vnd.github+json", + "Authorization": "Bearer " + credentials['password'] + }) response = response.json() repos_data = repos_data + response repos_fetched = len(response) @@ -64,7 +74,11 @@ print("Collecting language data") for i in range(repos_df.shape[0]): - response = requests.get(repos_df.loc[i, 'Languages URL'], auth = authentication) + response = requests.get(repos_df.loc[i, 'Languages URL'], headers={ + "X-GitHub-Api-Version": "2022-11-28", + "Accept": "application/vnd.github+json", + "Authorization": "Bearer " + credentials['password'] + }) response = response.json() if response != {}: languages = [] @@ -84,7 +98,11 @@ url = repos_df.loc[i, 'Commits URL'] page_no = 1 while (True): - response = requests.get(url, auth = authentication) + response = requests.get(url, headers={ + "X-GitHub-Api-Version": "2022-11-28", + "Accept": "application/vnd.github+json", + "Authorization": "Bearer " + credentials['password'] + }) response = response.json() print("URL: {}, commits: {}".format(url, len(response))) for commit in response: