-
Notifications
You must be signed in to change notification settings - Fork 0
/
myfuncs.py
40 lines (31 loc) · 1.16 KB
/
myfuncs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import requests
import mydata
query = mydata.query
headers = mydata.headers
def make_request(json):
global headers
response = requests.post('https://api.github.com/graphql', json=json, headers=headers)
if response.status_code == 200:
return response.json()
else:
raise Exception(f"Query failed to run, returning code {response.status_code}. {json['query']}. "
f"{json['variables']}.")
def get_all_repos():
global query
json = {
"query": query, "variables": {}
}
result = make_request(json)
ans = result['data']['search']['nodes']
end_cursor = result['data']['search']['pageInfo']['endCursor']
query = query.replace("first:10", "first:10{AFTER}")
for i in range(0, 100):
if result['data']['search']['pageInfo']['hasNextPage']:
new_query = query.replace("{AFTER}", f", after:\"{end_cursor}\"")
json = {
"query": new_query, "variables": {}
}
result = make_request(json)
end_cursor = result['data']['search']['pageInfo']['endCursor']
ans += result['data']['search']['nodes']
return ans