-
Notifications
You must be signed in to change notification settings - Fork 2
/
foragingList.py
197 lines (179 loc) · 8.32 KB
/
foragingList.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import json
import sys
import copy
import string
import math
from version import version
#import pywikibot
from cddaWiki import *
#documentation
#Usage: python [location of pywikibotinstall]\pwb.py foragingList.py
# Then input your password, and wait for the page to be updated.
for it in range(0, len(list_item_files)):
with open(list_item_files[it]) as data_file:
new_data = json.load(data_file)
check_duplicates (data, new_data)
data = merge_json_data(data, new_data)
setAbstractIds()
fill_ID_to_item()
for it in range(0, len(list_itemgroup_files)):
with open(list_itemgroup_files[it]) as data_file:
new_data = json.load(data_file)
check_duplicates (itemgroup_data, new_data)
itemgroup_data = merge_json_data(itemgroup_data, new_data)
ID_masterlist = list()
for it in range(0, len(data)):
ID_masterlist.append(data[it]["id"])
ID_masterlist = sorted(ID_masterlist, key=string.lower)
def itemgroupRow(item_id, group_entry, prob):
retval = [ "" ]
id = ID_To_Item_Int(item_id)
retval.append("{{row/ItemGroup|name=")
retval.append(str(getValue(id, 'name')))
retval.append("|color=")
retval.append(str(getValue(id, 'color')))
retval.append("|symbol=")
retval.append(str(getValue(id, 'symbol')))
retval.append("|id=")
retval.append(item_id)
retval.append("|prob=")
retval.append(str(prob))
if('count-min' in group_entry):
retval.append("|min=")
retval.append(str(group_entry['count-min']))
if('count-max' in group_entry):
retval.append("|max=")
retval.append(str(group_entry['count-max']))
retval.append("}}\n")
return retval
def itemgroupToList(id_name, max_prob = 0.0): #id_name should be the name of the itemgroup id.
#Recursive function to easily make long lists of all possible drops.
retval = [ "" ]
entries_are_groups = False
probs = 0.0
for it in range(0, len(itemgroup_data)):
if(itemgroup_data[it]['id'] == id_name):
retval.append("<!--Start of group: ")
retval.append(itemgroup_data[it]['id'])
retval.append(" \n-->")
itemgroup = itemgroup_data[it]
subtype = 'old' #if substype is not set, it defaults to the 'old' subtype, which according to ITEM_SPAWN.md is the same as 'Distribution'
if('subtype' in itemgroup):
if(itemgroup['subtype'] == 'distribution'):
subtype = 'distribution'
elif(itemgroup['subtype'] == 'collection'):
subtype = 'collection'
if('entries' in itemgroup): #the list of items/item_groups that can drop can be called items or entries.
entries = itemgroup['entries']
elif('items' in itemgroup):
entries = itemgroup['items']
elif('groups' in itemgroup):
entries = itemgroup['groups']
entries_are_groups = True
if(subtype == 'old' or subtype == 'distribution'):#if the subtype is the distribution, calculate the total amount of probablities.
for ite in range(0, len(entries)):
if('prob' in entries[ite]):
max_prob += entries[ite]['prob']
elif(type(entries[ite]) is list):
max_prob += entries[ite][1]
else: #items without a prob listed have a default of 100
max_prob += 100.0
for ite in range(0, len(entries)):
#calculate prob for this entry.
if('prob' in entries[ite]):
prob = entries[ite]['prob']
elif(type(entries[ite]) is list):
prob = entries[ite][1]
else: #items without a prob listed have a default of 100
prob = 100.0
if(subtype == 'old' or subtype == 'distribution'):
prob = int(math.ceil((prob / max_prob)*10000.0))/100.0
#print entry
if(entries_are_groups):
id = 'error in group entry'
if(type(entries[ite]) is list):
if(InItemgroupData(entries[ite][0])):
id = entries[ite][0]
elif('item' in entries[ite]):
if(InItemgroupData(entries[ite]['item'])):
id = entries[ite]['item'][0]
else:
if(InItemgroupData(entries[ite]['item'])):
id = entries[ite]['item']
retval.extend(itemgroupToList(id, prob))
else:
if(type(entries[ite]) is list):
if(ID_To_Item_Int(entries[ite][0]) == -1):
retval.append("missing ")
retval.extend(itemgroupRow(entries[ite][0], entries[ite], prob))
elif('item' in entries[ite]):
retval.extend(itemgroupRow(entries[ite]['item'], entries[ite], prob))
elif('group' in entries[ite]):
if(InItemgroupData(entries[ite]['group'])):
retval.extend(itemgroupToList(entries[ite]['group'], prob))
else:
retval.append("List not found")
else:
retval.append(str(entries[ite]))
probs += prob
retval.append("<!-- End of group -->")
return retval
header = '''<!--Automatically generated using https://github.com/Soyweiser/CDDA-Wiki-Scripts/blob/master/foragingList.py foragingList.py -->'''
footer = '''</table>
<noinclude>Automatically generated by [https://github.com/Soyweiser/CDDA-Wiki-Scripts/blob/master/foragingList.py The foragingList.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+'\n</noinclude>'
springText = [ "" ]
springText.append("{{header/ItemGroup}}\n")
springText.append(header)
springText.extend(itemgroupToList('forage_spring'))
springText.append(footer)
springText = "".join(springText)
springText.replace("\n", "\\n")
summerText = [ "" ]
summerText.append("{{header/ItemGroup}}\n")
summerText.append(header)
summerText.extend(itemgroupToList('forage_summer'))
summerText.append(footer)
summerText = "".join(summerText)
summerText.replace("\n", "\\n")
autumnText = [ "" ]
autumnText.append("{{header/ItemGroup}}\n")
autumnText.append(header)
autumnText.extend(itemgroupToList('forage_autumn'))
autumnText.append(footer)
autumnText = "".join(autumnText)
autumnText.replace("\n", "\\n")
winterText = [ "" ]
winterText.append("{{header/ItemGroup}}\n")
winterText.append(header)
winterText.extend(itemgroupToList('forage_winter'))
winterText.append(footer)
winterText = "".join(winterText)
winterText.replace("\n", "\\n")
trashText = [ "" ]
trashText.append("{{header/ItemGroup}}\n")
trashText.append(header)
trashText.extend(itemgroupToList('trash_forest'))
trashText.append(footer)
trashText = "".join(trashText)
trashText.replace("\n", "\\n")
print trashText
'''
site = pywikibot.Site('en', 'cddawiki')
page = pywikibot.Page(site, 'Template:ItemGroup/forage_spring')
page.text = springText
page.save('Updated text automatically via the https://github.com/Soyweiser/CDDA-Wiki-Scripts foragingList.py script')
page = pywikibot.Page(site, 'Template:ItemGroup/forage_summer')
page.text = summerText
page.save('Updated text automatically via the https://github.com/Soyweiser/CDDA-Wiki-Scripts foragingList.py script')
page = pywikibot.Page(site, 'Template:ItemGroup/forage_autumn')
page.text = autumnText
page.save('Updated text automatically via the https://github.com/Soyweiser/CDDA-Wiki-Scripts foragingList.py script')
page = pywikibot.Page(site, 'Template:ItemGroup/forage_winter')
page.text = winterText
page.save('Updated text automatically via the https://github.com/Soyweiser/CDDA-Wiki-Scripts foragingList.py script')
page = pywikibot.Page(site, 'Template:ItemGroup/trash_forest')
page.text = trashText
page.save('Updated text automatically via the https://github.com/Soyweiser/CDDA-Wiki-Scripts foragingList.py script')
'''
exit()