Skip to content

Commit 1e213bd

Browse files
committed
Use requests respectful
1 parent 3a2abd6 commit 1e213bd

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

datauploader/api/rest.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import json
2-
import requests
3-
42

53
from ohapi import api
64

7-
85
from datauploader.api.helpers import write_jsonfile_to_tmp_dir, download_to_json, get_commit_date
6+
from demotemplate.settings import rr
97

108
# sort order is most recently created first
119
# max page size = 100 (may not be respected or vary, but this is the max max)
@@ -69,14 +67,14 @@ def get_rate_limit_remaining(github_access_token, type="core"):
6967
"""
7068

7169
auth_header = get_auth_header(github_access_token)
72-
response = requests.get(GITHUB_RATE_LIMIT_ENDPOINT, headers=auth_header)
70+
response = rr.get(GITHUB_RATE_LIMIT_ENDPOINT, headers=auth_header, realms=['github'])
7371
rate_limit_info = json.loads(response.content)['resources'][type]
7472
return rate_limit_info['remaining'], rate_limit_info['reset']
7573

7674

7775
def get_user_info(github_access_token):
7876
auth_header = get_auth_header(github_access_token)
79-
response = requests.get(GITHUB_USER_INFO_ENDPOINT, headers=auth_header)
77+
response = rr.get(GITHUB_USER_INFO_ENDPOINT, headers=auth_header, realms=['github'])
8078
return json.loads(response.content)
8179

8280

@@ -86,7 +84,7 @@ def get_user_repos(github_access_token):
8684
url = GITHUB_REPOS_ENDPOINT
8785
while True:
8886
cnt += 1
89-
response = requests.get(url, headers=get_auth_header(github_access_token))
87+
response = rr.get(url, headers=get_auth_header(github_access_token), realms=['github'])
9088
results += json.loads(response.content)
9189
next = response.links.get('next')
9290
if not next:
@@ -108,7 +106,7 @@ def get_repo_commits_for_user(github_access_token, repo, username, sync_after_da
108106

109107
while not reached_previous_data:
110108
cnt += 1
111-
response = requests.get(url, headers=get_auth_header(github_access_token))
109+
response = rr.get(url, headers=get_auth_header(github_access_token), realms=['github'])
112110
commits = json.loads(response.content)
113111

114112
if latest_commit_date is None and len(commits) > 0:

demotemplate/settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@
8282
},
8383
safety_threshold=5)
8484

85-
# This creates a Realm called "github" that allows 150 requests per minute maximum.
85+
# This creates a Realm called "github" that allows 5000 requests per hour maximum
86+
# so as to stay within the github API limit (assuming only 1 worker is active, of course)
8687

8788
rr = RespectfulRequester()
8889
rr.register_realm("github", max_requests=5000, timespan=3600)

0 commit comments

Comments
 (0)