]> git.tdb.fi Git - poefilter.git/blobdiff - scrape-item-data.py
Correctly merge icon and light beam appearances
[poefilter.git] / scrape-item-data.py
index f5f67b488593515d4b708d3d30351d5df0cd9170..84def9232b6cf2ddaedc1e3353ed00e17d82f58a 100755 (executable)
@@ -38,14 +38,15 @@ class Item:
                return 0
 
        def check_upgrade(self, other):
-               if self.droplevel<=other.droplevel:
-                       return
                if not self.is_compatible(other):
                        return
 
                mods = self.compare_mods(other)
                attrs = self.compare_attrs(other)
 
+               if self.droplevel<other.droplevel and (mods<0 or attrs<0):
+                       return
+
                if not other.upgrades["mods"]:
                        if mods>0 or (mods==0 and attrs>0):
                                other.upgrades["mods"] = self
@@ -135,7 +136,8 @@ class ItemDataParser(html.parser.HTMLParser):
                        self.mod_names = []
                elif tag=="td":
                        self.column += 1
-                       self.in_cell = True
+                       if self.in_items_table:
+                               self.in_cell = True
                elif tag=="h1":
                        self.in_heading = True
 
@@ -150,6 +152,10 @@ class ItemDataParser(html.parser.HTMLParser):
                                        self.current_item.check_upgrade(it)
                elif tag=="h1":
                        self.in_heading = False
+               elif tag=="html":
+                       for i in range(1, len(self.items)):
+                               for j in range(i):
+                                       self.items[j].check_upgrade(self.items[i])
 
        def handle_data(self, data):
                data = data.strip()
@@ -158,8 +164,10 @@ class ItemDataParser(html.parser.HTMLParser):
 
                if self.in_heading:
                        self.current_heading = data
+                       if self.current_heading=="Staff":
+                               self.current_heading = "Stave"
                        self.headings.append(self.current_heading)
-               elif self.in_items_table and self.in_cell:
+               elif self.in_cell:
                        if self.mod_row:
                                if self.column==1:
                                        self.mod_names.append(data)
@@ -312,6 +320,13 @@ def main():
                        out.write('\t\tbase_type "{}";\n'.format(it.name))
                out.write("\t};\n};\n")
 
+       for b in ("best", "second"):
+               out.write('category "armor.{}_at_level"\n'.format(b))
+               out.write('{\n\tor\n\t{\n')
+               for t in types.keys():
+                       out.write('\t\tcategory "armor.{}.{}_at_level";\n'.format(t, b))
+               out.write("\t};\n};\n")
+
        out.write('category "armor"\n{\n\tor\n\t{\n')
        for h in p.headings:
                out.write('\t\tclass "{}";\n'.format(h))
@@ -332,6 +347,13 @@ def main():
                for i in range(1, 3):
                        write_best_category(out, "weapon.{}".format(h.lower().replace(' ', '_')), items, i)
 
+       for b in ("best", "second"):
+               out.write('category "weapon.{}_at_level"\n'.format(b))
+               out.write('{\n\tor\n\t{\n')
+               for h in p.headings:
+                       out.write('\t\tcategory "weapon.{}.{}_at_level";\n'.format(h.lower().replace(' ', '_'), b))
+               out.write("\t};\n};\n")
+
        out.write('category "weapon"\n{\n\tor\n\t{\n')
        for h in p.headings:
                out.write('\t\tclass "{}";\n'.format(h))