-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlivers.py
85 lines (62 loc) · 2.33 KB
/
livers.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/python3
# script to dump all json data into file
import requests
import time
import json
def getLiverData(url):
response = requests.get(url)
data = response.json()['pageProps']['liver']
return data
def main():
urlPrefix = 'https://www.nijisanji.jp/_next/data/AssLCig6Qu-ghaLHbaxgh/members/'
allLivers = ["kuzuha"]
response = requests.get('https://www.nijisanji.jp/_next/data/AssLCig6Qu-ghaLHbaxgh/members/kuzuha.json')
initialLiver = response.json()['pageProps']['liver']
liversData = {"kuzuha":
{
"name": initialLiver['name'],
"slug": initialLiver['slug'],
"affiliation": initialLiver['affiliation'][0],
"english_name": initialLiver['english_name'],
"youtube_ch": initialLiver['social_links']['youtube'],
"twitter": initialLiver['social_links']['twitter']
}
}
livers = response.json()['pageProps']['livers']['contents']
for liver in livers:
if liver['slug'] == "kuzuha":
continue
time.sleep(2)
newData = {}
url = urlPrefix+liver['slug']+".json"
liverData = getLiverData(url)
if liver['slug'] not in liversData:
jpName = liver['name']
slug = liver['slug']
enName = liverData['english_name']
affiliation = liverData['affiliation'][0]
socials = liverData['social_links']
youtube = ""
twitter = ""
if 'youtube' in socials:
youtube = socials['youtube']
if 'twitter' in socials:
twitter = socials['twitter']
newData = {
"name": jpName,
"slug": slug,
"english_name": enName,
"affiliation": affiliation,
"youtube_ch": youtube,
"twitter": twitter
}
allLivers.append(slug)
liversData[slug] = newData
with open("livers.txt", "w") as f:
for liver in allLivers:
f.write(liver+":")
json.dump(liversData[liver], f)
if liver != allLivers[-1]:
f.write('\n')
if __name__ == "__main__":
main()