-
Notifications
You must be signed in to change notification settings - Fork 0
/
redirect.py
86 lines (77 loc) · 3.59 KB
/
redirect.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
86
#! /usr/bin/env python3
from sys import argv
from datetime import datetime
import json
import re
import util
from globals import URL, TODO, DATA, SKILLS, ACCESSORIES
from wikiUtil import _exportPage
def getWeaponName(sprite: str):
nameId = None
for skill in SKILLS.values():
if nameId:
break
for s in skill['sprites']:
if s and s == sprite[:-5].lower().replace(' ', '_'):
nameId = skill['name_id']
if nameId and nameId in DATA:
return "File:Weapon " + util.cleanStr(DATA[nameId]) + (" V2" if sprite.find("ar") != -1 else "") + ".png"
def getAccessoryName(sprite: str):
if sprite in ACCESSORIES:
return f"File:Accessory {util.cleanStr(util.getName(ACCESSORIES[sprite]['id_tag']))}.png"
def redirect(name: str, redirect: str):
result = _exportPage(redirect or name.replace(".webp", ".png"),
"#REDIRECT [[" + name + "]]", create=True)
if 'error' in result and result['error']['code'] == 'articleexists':
print(f"Redirect already exist: {redirect or name.replace('.webp', '.png')}")
elif 'edit' in result and result['edit']['result'] == 'Success':
print(f"Redirect {name} to {redirect or name.replace('.webp', '.png')}")
else:
print(json.dumps(result, indent=2))
def main(start=None):
result = util.fehBotLogin().get(url=URL, params={
"action": "query",
"list": "allimages",
"aisort": "timestamp",
"aistart": start if start else datetime.utcnow().strftime('%Y-%m-%dT00:00:00Z'),
"aiprop": "",
"ailimit": "max",
"format": "json"
}).json()
for image in result['query']['allimages']:
file = image['title']
name = None
if re.match(r"Map[_ ][A-Z]\w\d{3}\.webp", image['name']):
name = file.replace(".webp", ".png")
elif re.match(r"TT[_ ]\d{6}(\s\d{2})?\.webp", image['name']):
if 'MID_SEQUENTIAL_MAP_TERM_' + image['name'][3:-5] in DATA:
name = "File:Banner " + util.cleanStr(DATA['MID_SEQUENTIAL_MAP_TERM_' + image['name'][3:-5]]) + ".png"
else:
print(TODO + "TT banner: " + image['title'])
elif re.match(r"Wep[_ ][a-z]{2}\d{3}([_ ]up)?\.webp", image['name']):
wp = getWeaponName(image['name'])
if wp and (image['name'].find("up") != -1 or image['name'].find("mg") != -1):
#Do not automatically redirect refine weapon and tomes
print(TODO + image['name'] + " to " + str(wp))
elif wp:
name = wp
else:
print(TODO + "Unknow weapon: " + image['title'])
elif re.match(r"Acc[_ ][1-4][_ ]\d{4}[_ ]\d\.webp", image['name']):
name = getAccessoryName(image['name'][:-5])
if not name:
print(TODO + "Unknow accessory: " + image['title'])
elif re.search(r"[_ ](Btl)?Face[_ ]?(FC|C|D|Smile|Pain|Cool|Anger|Cry|Blush)?\d*\.webp$", image['name']):
name = file.replace(".webp", ".png")
elif re.match(r"GC[_ ]\d{6}([_ ]\d{2})?\.webp", image['name']):
print(TODO + "Grand conquest map: " + image['title'])
elif re.match(r"Talk[_ ].+\.webp", image['name']):
name = file.replace(".webp", ".png")
elif re.match(r"EvBg[_ ].+\.webp", image['name']):
name = "File:Talk " + image['name'].replace(".webp", ".png")
elif image['name'][-5:] == '.webp':
print("Other webp file: " + image['title'])
if name:
redirect(file, name)
if __name__ == "__main__":
main(argv[1] if len(argv) == 2 else None)