-
Notifications
You must be signed in to change notification settings - Fork 2
/
vitamins.py
110 lines (100 loc) · 5.58 KB
/
vitamins.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
99
100
101
102
103
104
105
106
107
108
109
110
import json
import sys
import string
import pywikibot
from version import version
from name_hacks import effects_name, has_effects_name
#Updates the various vitamin information on the wiki (Template:Vitaminslist). Also creates links to the various vitamin deficiency related diseases.
#Data is automatically copied to the wiki template page.
#Usage: python [location of pywikibotinstall]\pwb.py vitamins.py
# Then input your password, and wait for the page to be updated.
with open('data/json/vitamin.json') as data_file:
data = json.load(data_file)
with open('data/json/effects.json') as data_file:
data_effects = json.load(data_file)
header = '''<!--Automatically generated using https://github.com/Soyweiser/CDDA-Wiki-Scripts/blob/master/vitamins.py foragingList.py --><noinclude>* Source: [https://raw.github.com/CleverRaven/Cataclysm-DDA/master/data/json/vitamin.json vitamin.json]
* Source: [https://raw.github.com/CleverRaven/Cataclysm-DDA/master/data/json/effects.json effects.json]
* Automatically generated by [https://github.com/Soyweiser/CDDA-Wiki-Scripts/blob/master/vitamins.py The vitamins.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.
</noinclude>==Types of vitamins and vitamin like effects==
{| style="clear: both; margin: 0 auto; width: 100%; font-size: 100%" class="toccolours"
! colspan="4" style="background: #430950" | [[Vitamins|<span style="color: #afff90">Vitamins</span>]]
|-
! style="padding: 0.2em; width: 24em; text-align: left; background: #d8c3dd" | Vitamin name (minimum and maximum range)
! style="text-align: left; background: #d8c3dd" | Reduction speed
! style="text-align: left; background: #d8c3dd" | Excess effects (ranges)
! style="text-align: left; background: #d8c3dd" | Deficiency
'''
footer = '''
|}<noinclude>
'''
footer+= version+"[[Category:Templates]]\n</noinclude>"
def effect(x): #check if effect has a name in the name hacks effect_names list, if it has return that, if it hasn't return the first non-zero element of the effects_types (effects.json) name field.
if (has_effects_name(x)):
return effects_name(x)
else:
for it in range(0, len(data_effects)):
if (data_effects[it]["type"] == "effect_type" and data_effects[it]["id"] == x):
if (isinstance(data_effects[it]["name"], list)):
for ite in range(0, len(data_effects[it]["name"])):
if(len(str(data_effects[it]["name"][ite])) > 0):
return str(data_effects[it]["name"][ite])
else: #just going to assume it is a string.
return str(data_effects[it]["name"])
def generatePage (): #generates all the vitamins page, by looping over all the vitamins (type = vitamin) in the vitamin.json file.
output = [ "" ]
output.append(header)
for it in range(0, len(data)):
if(data[it]["type"] == "vitamin"):
output.extend("|-\n| <!--")
output.extend(str(data[it]["id"]))
output.extend("-->'''")
output.extend(str(data[it]["name"]["str"]))
output.extend("''' (")
output.extend(str(data[it]["min"]))
if ("max" in data[it]):
output.extend(", ")
output.extend(str(data[it]["max"]))
output.extend(")\n| ")
output.extend(str(data[it]["rate"]))
output.extend("\n| ")
if ("excess" in data[it]):
output.extend("[[")
output.extend(str(effect(data[it]["excess"])))
output.extend("]]")
if ("disease_excess" in data[it]):
output.extend(": [ levels: ")
for ite in range(0, len(data[it]["disease_excess"])): #im going to assume that this list always contains elements of size 2.
if (ite > 0):
output.append(", ")
output.extend(" (")
output.extend(str(data[it]["disease_excess"][ite][0]))
output.extend(", ")
output.extend(str(data[it]["disease_excess"][ite][1]))
output.extend(")")
output.extend(" ]")
output.extend("\n| ")
if ("deficiency" in data[it]):
output.extend("[[")
output.extend(effect(data[it]["deficiency"]))
output.extend("]]")
if ("disease" in data[it]):
output.extend(": [ levels: ")
for ite in range(0, len(data[it]["disease"])): #im going to assume that this list always contains elements of size 2.
if (ite > 0):
output.append(", ")
output.extend(" (")
output.extend(str(data[it]["disease"][ite][0]))
output.extend(", ")
output.extend(str(data[it]["disease"][ite][1]))
output.extend(")")
output.extend(" ]")
output.extend("\n")
output.append(footer)
output = "".join(output)
output.replace("\n", "\\n")
return output
site = pywikibot.Site('en', 'cddawiki')
page = pywikibot.Page(site, 'Template:Vitaminslist')
page.text = generatePage ()
page.save('Updated text automatically via the https://github.com/Soyweiser/CDDA-Wiki-Scripts vitamin.py script')
exit()