-
Notifications
You must be signed in to change notification settings - Fork 152
/
Copy pathupdate_game_data.py
61 lines (50 loc) · 1.57 KB
/
update_game_data.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import os
import requests
import requests_cache
import re
import json
# requests_cache.install_cache('ryujinx_issue', expire_after=114514)
game_re = re.compile(r'^(.*?) - ([\da-zA-Z]{16})$')
gh_token = os.environ.get('gh_token')
headers = {
'Authorization': f'Bearer {gh_token}'
} if gh_token else {}
def update_with_page(game_data, page):
resp = requests.get(f'https://api.github.com/repos/Ryujinx/Ryujinx-Games-List/issues?page={page}',
headers=headers)
# print(resp.headers)
print(f'handle page {page}')
issues = resp.json()
print(f'issues size: {len(issues)}')
if not issues:
return False
for issue in issues:
title = issue['title']
groups = game_re.findall(title)
if not groups:
continue
title, game_id = groups[0]
game_data[game_id] = title
return True
def update_all():
page = 0
game_data = {}
while True:
page += 1
if not update_with_page(game_data, page):
break
if game_data:
with open('game_data.json', 'w', encoding='utf-8') as f:
json.dump(game_data, f, ensure_ascii=False, indent=2)
def update_latest():
import os
if not os.path.exists('game_data.json'):
game_data = {}
else:
with open('game_data.json', 'r', encoding='utf-8') as f:
game_data = json.load(f)
update_with_page(game_data, 1)
with open('game_data.json', 'w', encoding='utf-8') as f:
json.dump(game_data, f, ensure_ascii=False, indent=2)
if __name__ == '__main__':
update_latest()