-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathvods_into_ms.py
84 lines (71 loc) · 2.25 KB
/
vods_into_ms.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
import mwparserfromhell
from mwrogue.esports_client import EsportsClient
from mwcleric.auth_credentials import AuthCredentials
summary = 'Semi-automatically migrating MD pages to Data namespace (Python)'
pagename = 'OPL/2018 Season/Split 1'
credentials = AuthCredentials(user_file="me")
site = EsportsClient('lol', credentials=credentials) # Set wiki
limit = -1
startat = -1
pages_var = [ pagename ]
# with open('pages.txt', encoding="utf-8") as f:
# pages = f.readlines()
# pages_var = [page.strip() for page in pages]
param_lookup = {
'pb' : 'vodpb',
'game' : 'vodstart',
'post' : 'vodpost',
'hl' : 'vodhl',
'int' : 'vodinterview'
}
param_list = [ 'pb', 'game', 'post', 'int', 'hl' ]
def add_param(game, name, value):
if name in param_lookup:
name = param_lookup[name]
game.add(name, value)
lmt = 0
for pagename in pages_var:
if lmt == limit:
break
lmt += 1
if lmt < startat:
print("Skipping page %s" % pagename)
else:
page = site.client.pages[pagename + '/VODs']
text = page.text()
wikitext = mwparserfromhell.parse(text)
all_data = []
for template in wikitext.filter_templates():
if template.name.matches('VODLine'):
new_params = []
for param in template.params:
if param.name.strip() in param_list:
new_params.append(param)
all_data.append(new_params)
data_page = site.client.pages['Data:' + pagename]
data_text = data_page.text()
data_wikitext = mwparserfromhell.parse(data_text)
i = 0
for template in data_wikitext.filter_templates(recursive = False):
j = 1
s = str(j)
if template.name.matches('MatchSchedule'):
try:
while template.has('game' + s):
sub_template_wikicode = mwparserfromhell.parse(template.get('game' + s).value.strip())
sub_template = sub_template_wikicode.filter_templates()[0]
for param in all_data[i]:
add_param(sub_template, param.name.strip(), param.value.strip())
template.add('game' + s, str(sub_template_wikicode))
j = j + 1
s = str(j)
i = i + 1
except IndexError as e:
print(str(i))
break
data_text_new = str(data_wikitext)
if data_text_new != text:
print('Saving page %s...' % data_page.name)
data_page.save(data_text_new, summary=summary)
else:
print('Skipping page %s...' % data_page.name)