示例#1
0
def remove_object(item):
    drawer = ITEM_MAPS[item]
    open_drawer(drawer)
    ITEM_MAPS.pop(item)
    save_obj(ITEM_MAPS, ITEM_MAP_PICKLE_NAME)
    close_drawer(drawer)
    print("Removed " + item + " from drawer " + str(drawer))
示例#2
0
def remove_shorthand(shorthand, heroname, short_dict):
    if shorthand in short_dict:
        print("Shorthand '" + shorthand + "' not present.")
    else:
        del short_dict[shorthand]
        save_obj(short_dict, SHORTHAND_PICKLE_NAME)
    return short_dict
示例#3
0
def add_shorthand(heroname, shorthand, short_dict):
    if shorthand not in short_dict:
        short_dict[shorthand] = heroname
        save_obj(short_dict, SHORTHAND_PICKLE_NAME)
    else:
        print("Shorthand '" + shorthand + "' already present.")
    return short_dict
示例#4
0
def reset_shorthands(factory_zero=False):
    if factory_zero:
        short_dict = {}
        save_obj(short_dict, SHORTHAND_PICKLE_NAME)
    else:
        form_shorthands()
        short_dict = load_obj(SHORTHAND_PICKLE_NAME)
    return short_dict
示例#5
0
def get_meta():
    """ First get winrate for each skill bracket, then add overall winrate at the end. """
    meta_data = {}

    data_start = '<table class="sortable no-arrows r-tab-enabled">'
    data_end = "</table>"
    row_start = '<a href="/heroes/'
    row_end = '</div></div></td></tr>'
    url = "http://www.dotabuff.com/heroes/meta"
    response = requests.get(url, headers={'User-agent': 'your bot 0.1'})
    url_text = response.text
    search_block = html_searcher(data_start, data_end, url_text, False,
                                 True)[0]
    rows = html_search_all(row_start, row_end, search_block)
    rows = [row.split('%') for row in rows]
    rows = [[
        row[0][(row[0].find('>') + 1):],
        float(row[1]),
        float(row[3]),
        float(row[5]),
        float(row[7]),
        float(row[9])
    ] for row in rows]
    for row in rows:
        heroname = ''
        for char in row[0]:
            if char not in '0123456789.':
                heroname += char
        meta_data[heroname] = row[1:]

    overall_win_start = '<a class="link-type-hero"'
    overall_win_end = '<div class="bar bar-default"><div class="segment segment-win"'
    url_overall = "http://www.dotabuff.com/heroes/winning"
    response = requests.get(url_overall,
                            headers={'User-agent': 'your bot 0.1'})
    url_text_overall = response.text
    rows_overall = html_search_all(overall_win_start, overall_win_end,
                                   url_text_overall, True)
    rows_overall = [row[:-1] for row in rows_overall]
    rows_overall = [
        row.split('</a></td><td data-value="') for row in rows_overall
    ]
    for row in rows_overall:
        row[0] = row[0][(row[0].find('>') + 1):]
        row[1] = float(row[1][(row[1].find('>') + 1):])
        meta_data[row[0]] = meta_data[row[0]] + [row[1]]

    save_obj(meta_data, BRACKET_PICKLE_NAME)
示例#6
0
def pull_dotabuff(make_new_shorthand_list=False):
    hero_len = len(HEROES_LIST)
    hero_adv_dict = {}
    hero_winrate_dict = {}
    data_start = "<table class=\"sortable\">"
    data_end = "</table>"
    adv_start = "<td class=\"cell-xlarge\">"
    adv_cutoff = "<div class=\"bar bar-default\"><div class=\"segment segment-advantage\""
    winrate_start = "</dt></dl><dl><dd>"
    winrate_end = "</span></dd>"
    i = 1
    for hero in HEROES_LIST:
        url = hero.replace(" ", "-")
        url = url.lower()
        url = url.replace("'", "")
        url = "http://www.dotabuff.com/heroes/" + url
        response = requests.get(url + "/matchups",
                                headers={'User-agent': 'your bot 0.1'})
        url_text = response.text
        search_block = html_searcher(data_start, data_end, url_text, False,
                                     True)[0]
        advantages = html_search_all(adv_start, adv_cutoff, search_block)
        adv_block = []
        for entry in advantages:
            entry_name = entry[:-5]
            entry_name = entry_name.replace("1", "")
            entry_percent = entry[-5:-1]
            if (entry_name[-1] == '-'):
                entry_name = entry_name[:-1]
                entry_percent = '-' + entry_percent
            entry_tuple = (entry_name, entry_percent)
            adv_block.append(entry_tuple)
        hero_adv_dict[hero] = adv_block

        response = requests.get(url, headers={'User-agent': 'your bot 0.1'})
        url_text = response.text
        winrate = html_searcher(winrate_start, winrate_end, url_text, False,
                                False)[0]
        hero_winrate_dict[hero] = float(winrate[:-1])
        print('{:<20}'.format(hero) + "\t" + str(i) + "/" + str(hero_len))
        i += 1
    save_obj(hero_adv_dict, ADV_PICKLE_NAME)
    save_obj(hero_winrate_dict, OVERALL_PICKLE_NAME)
    if (load_obj(SHORTHAND_PICKLE_NAME) == {}):
        form_shorthands()
    print('\n\n\n')
示例#7
0
def main(args):
    args = format_args()
    if args.dotabuff:
        pull_dotabuff()
    if args.sort:
        if (args.sort in SORT_INPUTS):
            save_obj(args.sort, SORTING_PICKLE_NAME)
        else:
            print("Invalid sorting value, '" + args.sort +
                  "'. Continuing with previous value.")
            print("Acceptable sorting values are as follows: ")
            for entry in SORT_INPUTS:
                print(entry)
    if args.percent:
        save_obj(args.percent, THRESHOLD_PICKLE_NAME)
    if args.addshorthand:
        add_to_shorthands(args.addshorthand, load_obj(SORTING_PICKLE_NAME))
    if args.reset:
        save_obj(2.0, THRESHOLD_PICKLE_NAME)
        save_obj(SORT_INPUTS[-1], SORTING_PICKLE_NAME)
        form_shorthands()
    if args.meta:
        get_meta()
        meta_to_prune = load_obj(BRACKET_PICKLE_NAME)
        #Each desired skill bracket will go one beyond in each direction, to account for border games
        args.meta = args.meta.replace('overall', '6')
        args.meta = args.meta.replace('all', '6')
        args.meta = args.meta.replace('ns', '1,2,3')
        args.meta = args.meta.replace('vhs', '3')
        args.meta = args.meta.replace('hs', '4,5')
        desired_brackets = args.meta.split(',')
        brackets_to_remove = [1, 2, 3, 4, 5, 6]
        for entry in desired_brackets:
            brackets_to_remove.remove(int(entry))
        for hero in meta_to_prune:
            cur_hero = meta_to_prune[hero]
            pop_shift = 1
            for entry in brackets_to_remove:
                cur_hero.pop(entry - pop_shift)
                pop_shift += 1
        save_obj(meta_to_prune, BRACKET_PICKLE_NAME)
    else:
        save_obj({}, BRACKET_PICKLE_NAME)
    if args.zeta:
        return
    elif args.captain:
        captains_mode(args.captain)
    else:
        start_picks()
示例#8
0
def add_object(item, drawer):
    open_drawer(drawer)
    ITEM_MAPS[item] = drawer
    save_obj(ITEM_MAPS, ITEM_MAP_PICKLE_NAME)
    close_drawer(drawer)
    print("Added " + item + " to drawer " + str(drawer))
示例#9
0
def close_drawer(drawer_number):
    if (DRAWERS[drawer_number] == OPEN):
        print("Closed drawer " + str(drawer_number))
        DRAWERS[drawer_number] = CLOSED
    save_obj(DRAWERS, DRAWER_STATUS_PICKLE_NAME)
示例#10
0
def open_drawer(drawer_number):
    if (DRAWERS[drawer_number] == CLOSED):
        print("Opened drawer " + str(drawer_number))
        DRAWERS[drawer_number] = OPEN
    save_obj(DRAWERS, DRAWER_STATUS_PICKLE_NAME)
示例#11
0
def form_shorthands():
    short_dict = form_dict_from_comma_file(SHORTHAND_FILE)
    save_obj(short_dict, SHORTHAND_PICKLE_NAME)