-
Notifications
You must be signed in to change notification settings - Fork 2
/
bionicsList.py
98 lines (86 loc) · 3.86 KB
/
bionicsList.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
87
88
89
90
91
92
93
94
95
96
97
98
import json
import sys
import string
import pywikibot
from version import version
from cddaWiki import GetName
#Data is automatically copied to the wiki template pages.
#Usage: python [location of pywikibotinstall]\pwb.py bionicsList.py
# Then input your password, and wait for the pages to be updated.
#Hint: after running this, manually check if there are any additions/removals needed from Template:CBMbar
with open('data/json/bionics.json') as data_file:
data = json.load(data_file)
with open('data/json/items/bionics.json') as data_file:
data1 = json.load(data_file)
with open('data/json/items/obsolete.json') as data_file:
obsolete = json.load(data_file)
def isObsoleteID(id):
for it in range(0, len(obsolete)):
if('id' in obsolete[it]):
if( id == obsolete[it]['id']):
return True
return False
ID_bionic = list()
ID_bionic_faulty = list()
for iterator in range(0, len(data)):
ignore = False
if('id' in data[iterator]):
if(isObsoleteID(data[iterator]['id'])):
ignore = True
if(not ignore):
if('flags' in data[iterator]):
if('BIONIC_FAULTY' in data[iterator]['flags']): #only add bionics that are not faulty to this list.
ID_bionic_faulty.append(GetName(data[iterator]["name"]))
else:
ID_bionic.append(GetName(data[iterator]["name"]))
else:
ID_bionic.append(GetName(data[iterator]["name"]))
for iterator in range(0, len(data1)): #the previous loop does not add some cbms, this loop will add the missing ones.
ignore = False
if('id' in data1[iterator]):
if(isObsoleteID(data1[iterator]['id'])):
ignore = true
if(not 'abstract' in data1[iterator] and not ignore): #don't add abstract bionics.
excluded = True
for iter in range(0, len(data)):
if(data[iter]['id'] == data1[iterator]['id']):
excluded = False
break
if(excluded):
ID_bionic.append(GetName(data1[iterator]["name"]))
ID_bionic = sorted(ID_bionic, key=string.lower)
ID_bionic_faulty = sorted(ID_bionic_faulty, key=string.lower)
output = [ "" ]
output_faulty = [ "" ]
footer = '''
<noinclude>Automatically generated by [https://github.com/Soyweiser/CDDA-Wiki-Scripts The bionicsList.py script]. Any edits made to this can and will be overwritten. Please contact [[User:Soyweiser|Soyweiser]] if you want make changes to this page. Especially as any changes made here probably also means there have been changes in other pages. And there are tools to update those a little bit quicker.\n
[[Category:Templates]]\n'''
footer+=version+"</noinclude>"
output.append("{{header/Bionics}}\n")
output_faulty.append("{{header/FaultyBionics}}\n")
output.append("<!--Automatically generated using https://github.com/Soyweiser/CDDA-Wiki-Scripts -->\n\n")
output_faulty.append("<!--Automatically generated using https://github.com/Soyweiser/CDDA-Wiki-Scripts -->\n\n")
for it in range(0, len(ID_bionic)):
output.append("{{:")
output.append(ID_bionic[it])
output.append("}}\n")
for it in range(0, len(ID_bionic_faulty)):
output_faulty.append("{{:")
output_faulty.append(ID_bionic_faulty[it])
output_faulty.append("}}\n")
output.append("</table>\n")
output.append(footer)
output_faulty.append("</table>\n")
output_faulty.append(footer)
text = "".join(output)
text.replace("\n", "\\n")
faultytext = "".join(output_faulty)
faultytext.replace("\n", "\\n")
site = pywikibot.Site('en', 'cddawiki')
page = pywikibot.Page(site, 'Template:List/bionics')
page.text = text
page.save('Updated text automatically via the https://github.com/Soyweiser/CDDA-Wiki-Scripts bionicsList.py script')
page = pywikibot.Page(site, 'Template:List/faultybionics')
page.text = faultytext
page.save('Updated text automatically via the https://github.com/Soyweiser/CDDA-Wiki-Scripts bionicsList.py script')
exit()