forked from Soyweiser/CDDA-Wiki-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
materialresistances.py
43 lines (35 loc) · 2 KB
/
materialresistances.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
import json
import pywikibot
#documentation
#Usage: python [location of pywikibotinstall]\pwb.py materialresistances.py
# Then input your password, and wait for the pages to be updated.
# Updates the following pages: Template:Matbashres, Template:Matfireres, Template:Matcutres, Template:Matelecres, Template:Matacidres
with open('data/json/materials.json') as data_file:
data = json.load(data_file)
resistance_list = [ "bash_resist", "fire_resist", "cut_resist", "elec_resist", "acid_resist" ]
pagename_list = [ "bash", "fire", "cut", "elec", "acid" ]
inlinetext_list = [ "bash", "fire", "cut", "electricity", "acid" ]
site = pywikibot.Site('en', 'cddawiki')
for ite in range(0, len(resistance_list)):
output = [ "<includeonly>{{#switch:{{lc:{{{1}}}}}\n" ]
for it in range(0, len(data)):
output.append(" |")
output.append(data[it]['ident'])
output.append(" = ")
output.append(str(data[it][resistance_list[ite]]))
output.append("\n")
output.append(''' |#default={{{1|0}}}
}}</includeonly><noinclude>
Template that returns the ''' + inlinetext_list[ite] +''' resistance of the passed material.
* Source: [https://raw.github.com/CleverRaven/Cataclysm-DDA/master/data/json/materials.json materials.json]
* Automatically generated by [https://github.com/Soyweiser/CDDA-Wiki-Scripts/blob/master/materialresistances.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.
[[Category:Templates|{{PAGENAME}}]]
</noinclude>
''')
text = "".join(output)
text.replace("\n", "\\n")
pageurl = "Template:Mat" + pagename_list[ite] + "res"
page = pywikibot.Page(site, pageurl)
page.text = text
page.save('Updated text automatically via the https://github.com/Soyweiser/CDDA-Wiki-Scripts materialresistances.py script')
exit()