]> git.tdb.fi Git - poefilter.git/commitdiff
Add debug output to the item data scraper
authorMikko Rasa <tdb@tdb.fi>
Thu, 16 Aug 2018 14:35:17 +0000 (17:35 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 16 Aug 2018 14:35:17 +0000 (17:35 +0300)
scrape-item-data.py

index 71e573a2c96b74c76d2ca4812564cf91d2a6c6cc..f5f67b488593515d4b708d3d30351d5df0cd9170 100755 (executable)
@@ -3,6 +3,7 @@
 import requests
 import html.parser
 import codecs
+import argparse
 
 class Item:
        def __init__(self, name, kind):
@@ -237,11 +238,59 @@ def write_best_category(out, prefix, items, steps):
                out.write("\t\t};\n")
        out.write("\t};\n};\n")
 
+def print_debug(items):
+       upgrades = set()
+       for it in items:
+               for u in it.upgrades.values():
+                       if u:
+                               upgrades.add(u.name)
+
+       printed = set()
+
+       queue = []
+       while 1:
+               for it in items:
+                       if it.name not in upgrades and it.name not in printed:
+                               queue.append(it)
+                               break
+
+               if not queue:
+                       break
+
+               while queue:
+                       it = queue.pop(0)
+                       if it.name in printed:
+                               continue
+                       printed.add(it.name)
+
+                       print(it.name)
+                       print("  level: {}".format(it.droplevel))
+                       if isinstance(it, Armor):
+                               print("  armor: {}".format(it.armor))
+                               print("  evasion: {}".format(it.evasion))
+                               print("  energy shield: {}".format(it.energy_shield))
+                       elif isinstance(it, Weapon):
+                               print("  dps: {}".format(it.dps))
+                       for n, v in it.mods.items():
+                               print("  {}: {}".format(n, v))
+                       for t, u in it.upgrades.items():
+                               if u:
+                                       print("  upgrade {}: {}".format(t, u.name))
+                                       if u.name not in printed:
+                                               queue.insert(0, u)
+
 def main():
+       parser = argparse.ArgumentParser()
+       parser.add_argument("-g", "--debug", action="store_true", dest="debug")
+       args = parser.parse_args()
+
        r = requests.get("https://www.pathofexile.com/item-data/armour")
        p = ArmorDataParser()
        p.feed(codecs.decode(r.content, r.encoding))
 
+       if args.debug:
+               print_debug(p.items)
+
        types = {"robe": lambda i: (not i.armor and not i.evasion and i.energy_shield),
                "cloth": lambda i: (not i.armor and i.evasion and i.energy_shield),
                "leather": lambda i: (not i.armor and i.evasion and not i.energy_shield),
@@ -272,6 +321,9 @@ def main():
        p = WeaponDataParser()
        p.feed(codecs.decode(r.content, r.encoding))
 
+       if args.debug:
+               print_debug(p.items)
+
        out = open("weapons.txt", "w")
 
        for h in p.headings: