forked from ONI-Wiki-zh/BotNotIncluded
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshironeko_data.py
36 lines (31 loc) · 1.15 KB
/
shironeko_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
import pywikibot
import pandas as pd
if __name__ == '__main__':
site = pywikibot.Site("zh", "shironeko")
charCat = pywikibot.Category(site, "角色")
charPages = set()
for p in charCat.members(True, 0, content=True):
charPages.add(p)
charPages = sorted(charPages)
charTemps = set()
for i, p in enumerate(charPages):
temps = p.raw_extracted_templates
tempName = temps[0][0]
tempArgs = temps[0][1]
assert tempArgs["1"] == "gallery"
charTemps.add(tempName)
charTemps = sorted(charTemps)
charStats = {}
errors = []
for i, t in enumerate(charTemps):
if i % 10 == 0:
print(f"{i}/{len(charTemps)}")
p = pywikibot.Page(site, title=t, ns=site.namespaces.TEMPLATE.id)
if p.exists():
while p.isRedirectPage():
p = p.getRedirectTarget()
if len(p.raw_extracted_templates) == 0 or p.raw_extracted_templates[0][0] != 'Char/{{{1|default}}}':
errors.append(p)
continue
charStats[t] = p.raw_extracted_templates[0][1].copy()
df = pd.DataFrame.from_dict(charStats, orient="index")