8 def __init__(self, name):
10 self.reward_kind = None
13 def __init__(self, name):
20 def is_upgrade_for(self, other):
21 aps = self.amount/self.duration
22 other_aps = other.amount/other.duration
23 return (aps>other_aps and self.amount>other.amount)
25 class WikiParser(html.parser.HTMLParser):
27 super(WikiParser, self).__init__()
29 self.in_items_table = False
34 self.current_item = None
36 def handle_starttag(self, tag, attrs):
39 if n=="class" and "wikitable" in v:
40 self.in_items_table = True
43 self.current_item = None
46 if self.in_items_table:
53 if n=="class" and "c-item-hoverbox__display" in v:
56 def handle_endtag(self, tag):
58 self.in_items_table = False
65 def handle_data(self, data):
75 self.current_item = self.create_item(data)
77 self.items.append(self.current_item)
78 elif self.current_item:
79 self.handle_value(self.column, data)
81 def create_item(self, name):
84 def handle_value(self, column, data):
87 class DivinationCardsParser(WikiParser):
88 def handle_starttag(self, tag, attrs):
89 super(DivinationCardsParser, self).handle_starttag(tag, attrs)
91 if tag=="span" and not self.ignore_data:
92 if self.in_cell and self.current_item and not self.current_item.reward_kind and self.column==3:
96 self.current_item.reward_kind = "currency"
98 self.current_item.reward_kind = "unique"
100 self.current_item.reward_kind = "rare"
101 elif "-magic" in v or "-mod" in v:
102 self.current_item.reward_kind = "magic"
104 self.current_item.reward_kind = "skillgem"
106 def handle_endtag(self, tag):
107 super(DivinationCardsParser, self).handle_endtag(tag)
110 if self.current_item and not self.current_item.reward_kind:
111 self.current_item.reward_kind = "other"
113 def create_item(self, name):
116 def handle_value(self, column, data):
119 self.current_item.reward_kind = "links"
121 self.current_item.reward_kind = "map"
123 class FlasksParser(WikiParser):
124 def __init__(self, utility=False):
125 super(FlasksParser, self).__init__()
127 self.utility = utility
129 def handle_endtag(self, tag):
130 super(FlasksParser, self).handle_endtag(tag)
133 if self.current_item:
134 for it in self.items:
135 if not it.upgrade and self.current_item.is_upgrade_for(it):
136 it.upgrade = self.current_item
138 def create_item(self, name):
139 if name.endswith("Flask"):
142 def handle_value(self, column, data):
144 self.current_item.droplevel = int(data)
145 elif column==3 and not self.utility:
146 self.current_item.amount = int(data)
147 elif (column==4 and not self.utility) or (column==3 and self.utility):
148 self.current_item.duration = float(data)
150 def scrape_flasks(out, url, kind):
151 r = requests.get(url)
153 p.feed(codecs.decode(r.content, r.encoding))
155 out.write('category "flask.{}.best_at_level"\n'.format(kind))
156 out.write('{\n\tclass "Flask";\n\tor\n\t{\n')
158 out.write("\t\tand\n\t\t{\n")
159 out.write('\t\t\tbase_type "{}";\n'.format(it.name))
161 out.write("\t\t\titem_level {} {};\n".format(it.droplevel, it.upgrade.droplevel-1))
163 out.write("\t\t\tmin_item_level {};\n".format(it.droplevel))
164 out.write("\t\t};\n")
165 out.write("\t};\n};\n")
168 r = requests.get("https://pathofexile.gamepedia.com/List_of_divination_cards")
169 p = DivinationCardsParser()
170 p.feed(codecs.decode(r.content, r.encoding))
175 by_reward.setdefault(it.reward_kind, []).append(it)
177 out = open("cards.txt", "w")
178 for r, il in by_reward.items():
179 out.write('category "card.{}"\n'.format(r))
180 out.write('{\n\tclass "Card";\n\tor\n\t{\n')
182 out.write('\t\tbase_type "{}";\n'.format(it.name))
183 out.write("\t};\n};\n")
185 out = open("flasks.txt", "w")
186 scrape_flasks(out, "https://pathofexile.gamepedia.com/Life_Flasks", "life")
187 scrape_flasks(out, "https://pathofexile.gamepedia.com/Mana_Flasks", "mana")
188 scrape_flasks(out, "https://pathofexile.gamepedia.com/Hybrid_Flasks", "hybrid")
190 p = FlasksParser(True)
191 r = requests.get("https://pathofexile.gamepedia.com/Utility_Flasks")
192 p.feed(codecs.decode(r.content, r.encoding))
193 r = requests.get("https://pathofexile.gamepedia.com/Critical_Utility_Flasks")
194 p.feed(codecs.decode(r.content, r.encoding))
196 out.write('category "flask.utility"\n{\n\tclass "Flask";\n\tor\n\t{\n')
198 out.write('\t\tbase_type "{}";\n'.format(it.name))
199 out.write("\t};\n};\n")
201 if __name__=="__main__":