9 def __init__(self, name, kind):
14 self.upgrades = {"attrs":None, "mods":None}
16 def is_compatible(self, other):
17 return self.kind==other.kind
19 def compare_mods(self, other):
21 for n, v in self.mods.items():
22 ov = other.mods.get(n, 0)
28 for on, ov in other.mods.items():
29 v = self.mods.get(on, 0)
37 def compare_attrs(self, other):
40 def check_upgrade(self, other):
41 if self.droplevel<=other.droplevel:
43 if not self.is_compatible(other):
46 mods = self.compare_mods(other)
47 attrs = self.compare_attrs(other)
49 if not other.upgrades["mods"]:
50 if mods>0 or (mods==0 and attrs>0):
51 other.upgrades["mods"] = self
52 if not other.upgrades["attrs"]:
53 if attrs>0 or (attrs==0 and mods>0):
54 other.upgrades["attrs"] = self
57 def __init__(self, name, kind):
58 super(Armor, self).__init__(name, kind)
62 self.energy_shield = 0
64 def is_compatible(self, other):
65 if (self.armor!=0)!=(other.armor!=0):
67 if (self.evasion!=0)!=(other.evasion!=0):
69 if (self.energy_shield!=0)!=(other.energy_shield!=0):
72 return super(Armor, self).is_compatible(other)
74 def compare_attrs(self, other):
75 if self.armor<other.armor:
77 if self.evasion<other.evasion:
79 if self.energy_shield<other.energy_shield:
82 if self.armor>other.armor:
84 if self.evasion>other.evasion:
86 if self.energy_shield>other.energy_shield:
92 def __init__(self, name, kind):
93 super(Weapon, self).__init__(name, kind)
98 def compare_attrs(self, other):
99 if self.dps<other.dps:
101 if self.dps>other.dps:
106 class ItemDataParser(html.parser.HTMLParser):
108 super(ItemDataParser, self).__init__()
110 self.in_items_table = False
114 self.current_item = None
115 self.in_heading = False
117 self.current_heading = None
122 def handle_starttag(self, tag, attrs):
125 if n=="class" and v=="itemDataTable":
126 self.in_items_table = True
130 if n=="class" and v.endswith("_mod"):
134 self.current_item = None
140 self.in_heading = True
142 def handle_endtag(self, tag):
144 self.in_items_table = False
148 if self.current_item and self.mod_row:
149 for it in self.items:
150 self.current_item.check_upgrade(it)
152 self.in_heading = False
154 def handle_data(self, data):
160 self.current_heading = data
161 self.headings.append(self.current_heading)
162 elif self.in_items_table and self.in_cell:
165 self.mod_names.append(data)
169 value = int(data.split(" to ", 1)[1])
172 name = self.mod_names[self.mod_index]
173 if name!="From Armour Movement Speed +%":
174 self.current_item.mods[name] = value
178 self.current_item = self.create_item(data, self.current_heading)
179 self.items.append(self.current_item)
181 self.current_item.droplevel = int(data)
183 self.handle_value(self.column, data)
185 def create_item(self, name, kind):
188 def handle_value(self, column, data):
191 class ArmorDataParser(ItemDataParser):
192 def create_item(self, name, kind):
193 return Armor(name, kind)
195 def handle_value(self, column, data):
197 self.current_item.armor = int(data)
199 self.current_item.evasion = int(data)
201 self.current_item.energy_shield = int(data)
203 class WeaponDataParser(ItemDataParser):
204 def create_item(self, name, kind):
205 return Weapon(name, kind)
207 def handle_value(self, column, data):
209 self.current_item.speed = float(data)
211 self.current_item.dps = float(data)
213 def get_upgrade_level(item, steps):
215 for p in item.upgrades.keys():
217 for i in range(steps):
218 upgrade = upgrade.upgrades.get(p)
221 level = max(level, upgrade.droplevel)
224 def write_best_category(out, prefix, items, steps):
225 best = ["best", "second"]
227 out.write('category "{}.{}_at_level"\n'.format(prefix, best[steps-1]))
228 out.write("{\n\tor\n\t{\n")
230 upgrade_level = get_upgrade_level(it, steps)
231 out.write("\t\tand\n\t\t{\n")
233 out.write('\t\t\tbase_type "{}";\n'.format(it.name))
234 out.write("\t\t\titem_level {} {};\n".format(it.droplevel, upgrade_level-1))
236 out.write('\t\t\tbase_type "{}";\n'.format(it.name))
237 out.write("\t\t\tmin_item_level {};\n".format(it.droplevel))
238 out.write("\t\t};\n")
239 out.write("\t};\n};\n")
241 def print_debug(items):
244 for u in it.upgrades.values():
253 if it.name not in upgrades and it.name not in printed:
262 if it.name in printed:
267 print(" level: {}".format(it.droplevel))
268 if isinstance(it, Armor):
269 print(" armor: {}".format(it.armor))
270 print(" evasion: {}".format(it.evasion))
271 print(" energy shield: {}".format(it.energy_shield))
272 elif isinstance(it, Weapon):
273 print(" dps: {}".format(it.dps))
274 for n, v in it.mods.items():
275 print(" {}: {}".format(n, v))
276 for t, u in it.upgrades.items():
278 print(" upgrade {}: {}".format(t, u.name))
279 if u.name not in printed:
283 parser = argparse.ArgumentParser()
284 parser.add_argument("-g", "--debug", action="store_true", dest="debug")
285 args = parser.parse_args()
287 r = requests.get("https://www.pathofexile.com/item-data/armour")
288 p = ArmorDataParser()
289 p.feed(codecs.decode(r.content, r.encoding))
294 types = {"robe": lambda i: (not i.armor and not i.evasion and i.energy_shield),
295 "cloth": lambda i: (not i.armor and i.evasion and i.energy_shield),
296 "leather": lambda i: (not i.armor and i.evasion and not i.energy_shield),
297 "scale": lambda i: (i.armor and i.evasion and not i.energy_shield),
298 "plate": lambda i: (i.armor and not i.evasion and not i.energy_shield),
299 "chain": lambda i: (i.armor and not i.evasion and i.energy_shield)}
301 out = open("armor.txt", "w")
303 for t, f in types.items():
304 items = [i for i in p.items if f(i)]
306 for i in range(1, 3):
307 write_best_category(out, "armor.{}".format(t), items, i)
309 out.write('category "armor.{}"\n'.format(t))
310 out.write("{\n\tor\n\t{\n")
312 out.write('\t\tbase_type "{}";\n'.format(it.name))
313 out.write("\t};\n};\n")
315 out.write('category "armor"\n{\n\tor\n\t{\n')
317 out.write('\t\tclass "{}";\n'.format(h))
318 out.write("\t};\n};\n")
320 r = requests.get("https://www.pathofexile.com/item-data/weapon")
321 p = WeaponDataParser()
322 p.feed(codecs.decode(r.content, r.encoding))
327 out = open("weapons.txt", "w")
330 items = [i for i in p.items if i.kind==h]
332 for i in range(1, 3):
333 write_best_category(out, "weapon.{}".format(h.lower().replace(' ', '_')), items, i)
335 out.write('category "weapon"\n{\n\tor\n\t{\n')
337 out.write('\t\tclass "{}";\n'.format(h))
338 out.write("\t};\n};\n")
340 if __name__=="__main__":