Пример #1
0
    def get_heroes_list(self, language="english"):  # TODO: add images
        json_url = "http://" + self.address + "/jsfeed/heropickerdata?l=" + language
        data = sp.get_json(json_url)  # main data ready.

        # From HTML, we get pics and STR/AGI/INT and Radiant/Dire types
        html_url = "http://" + self.address + "/heroes?l=" + language
        heroes_sections_path = [
            "body",
            "center",
            "bodyContainer",
            "centerColContainer",
            "centerColContent",
            "redboxOuter",
            "redboxContent",
            "heroPickerInner",
        ]
        hero_sections = sp.naviget(heroes_sections_path, sp.get_html(html_url))

        hero_classes = ("STR", "AGI", "INT")
        hero_sides = ("Radiant", "Dire")
        section_names = ["heroCol" + pos for pos in ("Left", "Middle", "Right")]

        for (hero_class, section_name) in zip(hero_classes, section_names):
            thus_named_sections = hero_sections.find_all(class_=section_name)
            for (side, section) in zip(hero_sides, thus_named_sections):
                for hero_item in section.find_all("a"):
                    id = hero_item["id"][5:]  # link_invoker -> invoker
                    data[id]["icon_small"] = sp.naviget("heroHoverSmall", hero_item)["src"]
                    data[id]["icon"] = sp.naviget("heroHoverLarge", hero_item)["src"]
                    data[id]["class"] = hero_class
                    data[id]["side"] = side

        return data
Пример #2
0
 def retreive_abilities(self):
     # TODO: languages
     # TODO: fancy parsing of those
     whole_bunch = sp.get_json("http://www.dota2.com/jsfeed/heropediadata?feeds=abilitydata&l=russian")[
         "abilitydata"
     ]
     heroes = set(sp.get_json("http://www.dota2.com/jsfeed/heropickerdata?l=russian").keys())
     hero_abilities = {hero: {} for hero in heroes}
     for ability_name_full in whole_bunch:
         ability_name_words = ability_name_full.split("_")
         for word_count in range(1, len(ability_name_words)):
             hero_id = "_".join(ability_name_words[:word_count])
             if hero_id in heroes:
                 break
         ability = whole_bunch[ability_name_full]
         if hero_id not in heroes:
             hero_id = ability["hurl"].lower()
         hero_abilities[hero_id][ability["dname"]] = ability
     self.hero_abilities = hero_abilities