-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcards.py
42 lines (32 loc) · 1.07 KB
/
cards.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
import requests
def get_cards(token, page='1'):
url = 'https://ak.hypergryph.com/user/api/inquiry/gacha?page='\
+ page +'&token=' + token + '&channelId=1'
res = requests.get(url)
if res.status_code != 200:
raise Exception('Get cards failed')
return res.json()['data']
# Extract information for each chars
def process_cards(lists):
cards = []
for li in lists:
for char in li['chars']:
cards.append({
'ts': li['ts'],
'pool': li['pool'],
'name': char['name'],
'rarity': char['rarity'],
'isNew': char['isNew'],
})
return cards
# Convert to card list
def convert_cards(token):
cards = []
pagination = get_cards(token)['pagination']
while pagination['current'] <= pagination['total']:
# Get cards list
lists = get_cards(token, str(pagination['current']))['list']
cards.extend(process_cards(lists))
print('Page: ', pagination['current'])
pagination['current'] += 1
return cards