-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_sponsors.py
46 lines (42 loc) · 1.35 KB
/
update_sponsors.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
41
42
43
44
45
46
from urllib.request import urlopen, Request
import sys
import json
def main(token: str):
sponsors = []
after = "null"
has_next_page = True
while has_next_page:
query = """
query {
organization (login:"Amulet-Team") {
sponsors(first: 100, after: AFTER) {
nodes {
... on User { login }
... on Organization { login }
}
pageInfo {
endCursor
hasNextPage
}
}
}
}
""".replace("AFTER", after)
req = urlopen(Request(
"https://api.github.com/graphql",
json.dumps({"query": query}).encode(),
headers={
"Authorization": "bearer " + token
}
))
with req as f:
response = json.loads(f.read().decode())
sponsor_node = response["data"]["organization"]["sponsors"]
sponsors.extend(user["login"] for user in sponsor_node["nodes"])
page_info = sponsor_node["pageInfo"]
after = f'"{page_info["endCursor"]}"'
has_next_page = page_info["hasNextPage"]
with open("sponsors.json", "w") as f:
json.dump(sorted(sponsors), f)
if __name__ == "__main__":
main(sys.argv[1])