예제 #1
0
def get_hero_builds(hero):
    builds = []
    hero = normalize_hero_name(hero)
    link = 'https://www.icy-veins.com/heroes/' + hero + '-build-guide'
    soup = get_soup(link)

    builds_tags = soup.find_all('div', class_='heroes_tldr_talents')
    build_title_tags = soup.find_all('h4', class_='toc_no_parsing')

    build_titles = get_builds_titles(build_title_tags)

    for build_number, build_tag in enumerate(builds_tags):
        build = []
        talent_tiers = build_tag.find_all('span', class_= 'heroes_tldr_talent_tier_visual')

        # find out which block is painted with green (chosen talent)
        for tier in talent_tiers:
            children = tier.find_all('span')
            for j, child in enumerate(children):
                if('heroes_tldr_talent_tier_yes' in child['class']):
                    build.append(j+1)

        # append whole build to builds list
        builds.append(build[:])

    return builds, build_titles
예제 #2
0
def load_builds(hero):
    hero = normalize_hero_name(hero)
    filename = 'data/builds/' + hero + '.json'

    with open(filename, 'r') as fp:
        data = json.load(fp)

    print(data)
예제 #3
0
def update_hero_builds(hero):
    hero = normalize_hero_name(hero)
    print('Updating builds for ' + hero + '...', end='')
    builds, titles = get_hero_builds(hero)
    filename = 'data/builds/' + hero + '.json'

    with open(filename, 'w') as fp:
        for build, title in zip(builds, titles):
            json.dump(build, fp)
            json.dump(title, fp)

    print('OK')
예제 #4
0
def load_builds(hero):
    hero = normalize_hero_name(hero)
    filename = 'data/builds/' + hero + '.json'
    load_list = []
    builds = []
    builds_titles = []

    with open(filename, 'r') as fp:
        load_list = json.load(fp)

    for i in range(0, len(load_list) - 1, 2):
        builds.append(load_list[i])
        builds_titles.append(load_list[i + 1])

    return builds, builds_titles
예제 #5
0
def update_hero_builds(hero):
    dump_list = []
    hero = normalize_hero_name(hero)
    print('Updating builds for ' + hero + '...', end='')
    builds, titles = get_hero_builds(hero)
    filename = 'data/builds/' + hero + '.json'

    for build, title in zip(builds, titles):
        dump_list.append(build)
        dump_list.append(title)

    with open(filename, 'w') as fp:
        json.dump(dump_list, fp)

    print('OK')
예제 #6
0
def update_heroes_list():
    heroes_names = set()
    roles = ['assassin', 'support', 'warrior', 'specialist']

    for role in roles:
        link = 'https://www.icy-veins.com/heroes/' + role + '-hero-guides'
        soup = get_soup(link)

        hero_block_tags = soup.find_all(
            'div', class_='nav_content_block_entry_heroes_hero')
        for hero_block in hero_block_tags:
            name = normalize_hero_name(
                hero_block.find('span', class_='').contents[0])
            heroes_names.add(name)

    with open('data/heroes.json', 'w') as fp:
        json.dump(list(heroes_names), fp)