MCPcopy Create free account
hub / github.com/C3ting/ARL / github_client

Function github_client

app/services/githubSearch.py:124–146  ·  view source on GitHub ↗
(url, params=None, cnt=0)

Source from the content-addressed store, hash-verified

122
123
124def github_client(url, params=None, cnt=0):
125 headers = {
126 "Authorization": "Bearer {}".format(Config.GITHUB_TOKEN),
127 "Accept": "application/vnd.github.v3+json"
128 }
129 time.sleep(2.5)
130 conn = http_req(url, params=params, headers=headers)
131 data = conn.json()
132 if conn.status_code != 200:
133 message = data.get("message", "Github 错误")
134 if cnt < 3:
135 cnt += 1
136 if "You have triggered an abuse detection mechanism" in message \
137 or "API rate limit exceeded for user ID" in message\
138 or "You have exceeded a secondary rate limit" in message:
139 sleep_time = 20 + 15*cnt
140 logger.info("rate-limit retry {} {}, time sleep {}".format(cnt, params, sleep_time))
141 time.sleep(sleep_time)
142 return github_client(url, params=params, cnt=cnt)
143
144 raise Exception(message)
145
146 return data
147
148
149class GithubSearch(object):

Callers 3

contentMethod · 0.70
commit_dateMethod · 0.70
github_search_codeFunction · 0.70

Calls 2

http_reqFunction · 0.90
getMethod · 0.45

Tested by

no test coverage detected