コード例 #1
0
def match_history_data(history, account_id):
    """
    this will take a player history and decide which matches need to be downloaded and pass
    them to a multimatch api call this will auto call the function to parse a single players match history
    """
    url = '/multi_match/all/matchids/'
    plus = False
    count = 0
    needed = []
    for m in history:
        if not match.checkfile(m[0]):
            if plus:
                url = url + '+' + str(m[0])
            else:
                url = url + str(m[0])
                plus = True
            count += 1
            needed.append(m)
    if count > 0:
        data = api_call.get_json(url)
        if data is not None:
            match.multimatch(data, needed)
            return get_player_from_matches(history, account_id)
        else:
            return get_player_from_matches(history, account_id)
    else:
        return get_player_from_matches(history, account_id)
コード例 #2
0
ファイル: player.py プロジェクト: ColBW/honbot-django
def match_history_data(history, account_id):
    """
    this will take a player history and decide which matches need to be downloaded and pass
    them to a multimatch api call this will auto call the function to parse a single players match history
    """
    url = '/multi_match/all/matchids/'
    plus = False
    count = 0
    needed = []
    for m in history:
        if not match.checkfile(m[0]):
            if plus:
                url = url + '+' + str(m[0])
            else:
                url = url + str(m[0])
                plus = True
            count += 1
            needed.append(m)
    if count > 0:
        data = api_call.get_json(url)
        if data is not None:
            match.multimatch(data, needed)
            return get_player_from_matches(history, account_id)
        else:
            return get_player_from_matches(history, account_id)
    else:
        return get_player_from_matches(history, account_id)
コード例 #3
0
def get_chat(match_id):
    """
    handles the initial download/check of the .log file
    """
    # get proper url and change to .zip use match first or backup plan with php (slow)
    if path.exists(directory + 'm' + str(match_id) + '.log'):
        return parse_chat_from_log(match_id)
    if checkfile(match_id):
        url = get_download(match_id)
        url = url[:-9] + 'zip'
        # download file
        r = requests.get(url)
        if r.status_code == 404:
            return None
        with open(directory + str(match_id)+".zip", "wb") as code:
            code.write(r.content)
        z = zipfile.ZipFile(directory + str(match_id) + '.zip')
        z.extract(z.namelist()[0], directory)
        z.close()
        # cleanup zip
        remove(directory + str(match_id) + '.zip')
        return parse_chat_from_log(match_id)
    else:
        # this method is janky. hence all the 404 checks to back out quickly if things go south
        try:
            r = requests.get('http://replaydl.heroesofnewerth.com/replay_dl.php?file=&match_id=' + match_id, timeout=2)
            if r.status_code == 404:
                return None
            url = r.url[:-9] + 'zip'
            r = requests.get(url)
            if r.status_code == 404:
                return None
            with open(directory + str(match_id)+".zip", "wb") as code:
                code.write(r.content)
            z = zipfile.ZipFile(directory + str(match_id) + '.zip')
            z.extract(z.namelist()[0], directory)
            z.close()
            # cleanup zip
            remove(directory + str(match_id) + '.zip')
            return parse_chat_from_log(match_id)
        except:
            return None