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 not self.is_compatible(other):
44 mods = self.compare_mods(other)
45 attrs = self.compare_attrs(other)
47 if self.droplevel<other.droplevel and (mods<0 or attrs<0):
50 if not other.upgrades["mods"]:
51 if mods>0 or (mods==0 and attrs>0):
52 other.upgrades["mods"] = self
53 if not other.upgrades["attrs"]:
54 if attrs>0 or (attrs==0 and mods>0):
55 other.upgrades["attrs"] = self
58 def __init__(self, name, kind):
59 super(Armor, self).__init__(name, kind)
63 self.energy_shield = 0
65 def is_compatible(self, other):
66 if (self.armor!=0)!=(other.armor!=0):
68 if (self.evasion!=0)!=(other.evasion!=0):
70 if (self.energy_shield!=0)!=(other.energy_shield!=0):
73 return super(Armor, self).is_compatible(other)
75 def compare_attrs(self, other):
76 if self.armor<other.armor:
78 if self.evasion<other.evasion:
80 if self.energy_shield<other.energy_shield:
83 if self.armor>other.armor:
85 if self.evasion>other.evasion:
87 if self.energy_shield>other.energy_shield:
93 def __init__(self, name, kind):
94 super(Weapon, self).__init__(name, kind)
99 def compare_attrs(self, other):
100 if self.dps<other.dps:
102 if self.dps>other.dps:
107 class ItemDataParser(html.parser.HTMLParser):
109 super(ItemDataParser, self).__init__()
111 self.in_items_table = False
115 self.current_item = None
116 self.in_heading = False
118 self.current_heading = None
123 def handle_starttag(self, tag, attrs):
126 if n=="class" and v=="itemDataTable":
127 self.in_items_table = True
131 if n=="class" and v.endswith("_mod"):
135 self.current_item = None
139 if self.in_items_table:
142 self.in_heading = True
144 def handle_endtag(self, tag):
146 self.in_items_table = False
150 if self.current_item and self.mod_row:
151 for it in self.items:
152 self.current_item.check_upgrade(it)
154 self.in_heading = False
156 for i in range(1, len(self.items)):
158 self.items[j].check_upgrade(self.items[i])
160 def handle_data(self, data):
166 self.current_heading = data
167 if self.current_heading=="Staff":
168 self.current_heading = "Stave"
169 self.headings.append(self.current_heading)
173 self.mod_names.append(data)
177 value = int(data.split(" to ", 1)[1])
180 name = self.mod_names[self.mod_index]
181 if name!="From Armour Movement Speed +%":
182 self.current_item.mods[name] = value
186 self.current_item = self.create_item(data, self.current_heading)
187 self.items.append(self.current_item)
189 self.current_item.droplevel = int(data)
191 self.handle_value(self.column, data)
193 def create_item(self, name, kind):
196 def handle_value(self, column, data):
199 class ArmorDataParser(ItemDataParser):
200 def create_item(self, name, kind):
201 return Armor(name, kind)
203 def handle_value(self, column, data):
205 self.current_item.armor = int(data)
207 self.current_item.evasion = int(data)
209 self.current_item.energy_shield = int(data)
211 class WeaponDataParser(ItemDataParser):
212 def create_item(self, name, kind):
213 return Weapon(name, kind)
215 def handle_value(self, column, data):
217 self.current_item.speed = float(data)
219 self.current_item.dps = float(data)
221 def get_upgrade_level(item, steps):
223 for p in item.upgrades.keys():
225 for i in range(steps):
226 upgrade = upgrade.upgrades.get(p)
229 level = max(level, upgrade.droplevel)
232 def write_best_category(out, prefix, items, steps):
233 best = ["best", "second"]
235 out.write('category "{}.{}_at_level"\n'.format(prefix, best[steps-1]))
236 out.write("{\n\tor\n\t{\n")
238 upgrade_level = get_upgrade_level(it, steps)
239 out.write("\t\tand\n\t\t{\n")
241 out.write('\t\t\tbase_type "{}";\n'.format(it.name))
242 out.write("\t\t\titem_level {} {};\n".format(it.droplevel, upgrade_level-1))
244 out.write('\t\t\tbase_type "{}";\n'.format(it.name))
245 out.write("\t\t\tmin_item_level {};\n".format(it.droplevel))
246 out.write("\t\t};\n")
247 out.write("\t};\n};\n")
249 def print_debug(items):
252 for u in it.upgrades.values():
261 if it.name not in upgrades and it.name not in printed:
270 if it.name in printed:
275 print(" level: {}".format(it.droplevel))
276 if isinstance(it, Armor):
277 print(" armor: {}".format(it.armor))
278 print(" evasion: {}".format(it.evasion))
279 print(" energy shield: {}".format(it.energy_shield))
280 elif isinstance(it, Weapon):
281 print(" dps: {}".format(it.dps))
282 for n, v in it.mods.items():
283 print(" {}: {}".format(n, v))
284 for t, u in it.upgrades.items():
286 print(" upgrade {}: {}".format(t, u.name))
287 if u.name not in printed:
291 parser = argparse.ArgumentParser()
292 parser.add_argument("-g", "--debug", action="store_true", dest="debug")
293 args = parser.parse_args()
295 r = requests.get("https://www.pathofexile.com/item-data/armour")
296 p = ArmorDataParser()
297 p.feed(codecs.decode(r.content, r.encoding))
302 types = {"robe": lambda i: (not i.armor and not i.evasion and i.energy_shield),
303 "cloth": lambda i: (not i.armor and i.evasion and i.energy_shield),
304 "leather": lambda i: (not i.armor and i.evasion and not i.energy_shield),
305 "scale": lambda i: (i.armor and i.evasion and not i.energy_shield),
306 "plate": lambda i: (i.armor and not i.evasion and not i.energy_shield),
307 "chain": lambda i: (i.armor and not i.evasion and i.energy_shield)}
309 out = open("armor.txt", "w")
311 for t, f in types.items():
312 items = [i for i in p.items if f(i)]
314 for i in range(1, 3):
315 write_best_category(out, "armor.{}".format(t), items, i)
317 out.write('category "armor.{}"\n'.format(t))
318 out.write("{\n\tor\n\t{\n")
320 out.write('\t\tbase_type "{}";\n'.format(it.name))
321 out.write("\t};\n};\n")
323 for b in ("best", "second"):
324 out.write('category "armor.{}_at_level"\n'.format(b))
325 out.write('{\n\tor\n\t{\n')
326 for t in types.keys():
327 out.write('\t\tcategory "armor.{}.{}_at_level";\n'.format(t, b))
328 out.write("\t};\n};\n")
330 out.write('category "armor"\n{\n\tor\n\t{\n')
332 out.write('\t\tclass "{}";\n'.format(h))
333 out.write("\t};\n};\n")
335 r = requests.get("https://www.pathofexile.com/item-data/weapon")
336 p = WeaponDataParser()
337 p.feed(codecs.decode(r.content, r.encoding))
342 out = open("weapons.txt", "w")
345 items = [i for i in p.items if i.kind==h]
347 for i in range(1, 3):
348 write_best_category(out, "weapon.{}".format(h.lower().replace(' ', '_')), items, i)
350 for b in ("best", "second"):
351 out.write('category "weapon.{}_at_level"\n'.format(b))
352 out.write('{\n\tor\n\t{\n')
354 out.write('\t\tcategory "weapon.{}.{}_at_level";\n'.format(h.lower().replace(' ', '_'), b))
355 out.write("\t};\n};\n")
357 out.write('category "weapon"\n{\n\tor\n\t{\n')
359 out.write('\t\tclass "{}";\n'.format(h))
360 out.write("\t};\n};\n")
362 if __name__=="__main__":