Exemple #1
0
def players(request, name):
    """
    controls the player show
    """
    while "undefined" in name:
        name = name[:-10]
    url = '/player_statistics/casual/nickname/' + name
    data = api_call.get_json(url)
    if data is not None:
        statsdict = data
        s = player.player_math(statsdict)
        ### Get Match history ### api.heroesofnewerth.com/match_history/ranked/accountid/123456/?token=yourtoken
        url = '/match_history/casual/nickname/' + name
        data = api_call.get_json(url)
        history = []
        if data is not None:
            history = match.recent_matches(data, 9)
        ### Get Match History Data ###
        history_detail = player.match_history_data(history, s['id'])
        ### deliver to view ###
        t = loader.get_template('player.html')
        c = Context({'nick': name, 'stats': s, 'mdata': history_detail})
        return HttpResponse(t.render(c))
    else:
        t = loader.get_template('error.html')
        c = Context({'id': name})
        return HttpResponse(t.render(c))
Exemple #2
0
def players(request, name):
    """
    controls the player show
    """
    while "undefined" in name:
        name = name[:-10]
    url = '/player_statistics/casual/nickname/' + name
    data = api_call.get_json(url)
    if data is not None:
        statsdict = data
        s = player.player_math(statsdict)
        ### Get Match history ### api.heroesofnewerth.com/match_history/ranked/accountid/123456/?token=yourtoken
        url = '/match_history/casual/nickname/' + name
        data = api_call.get_json(url)
        history = []
        if data is not None:
            history = match.recent_matches(data, 9)
        ### Get Match History Data ###
        history_detail = player.match_history_data(history, s['id'])
        ### deliver to view ###
        t = loader.get_template('player.html')
        c = Context({'nick': name, 'stats': s, 'mdata': history_detail})
        return HttpResponse(t.render(c))
    else:
        t = loader.get_template('error.html')
        c = Context({'id': name})
        return HttpResponse(t.render(c))
Exemple #3
0
def update_player(pid, mode):
    if mode == 'rnk':
        url = "/player_statistics/ranked/accountid/" + str(pid)
    elif mode == 'cs':
        url = '/player_statistics/casual/accountid/' + str(pid)
    elif mode == 'acc':
        url = '/player_statistics/public/accountid/' + str(pid)
    data = api_call.get_json(url)
    p = player_math(data, mode)
    player_save(p, mode)
Exemple #4
0
def banner_view(request, name):
    location = directory + str(name) + ".png"
    # check file exists
    if path.isfile(location):
        # check file age
        now = time()
        fileCreation = path.getctime(location)
        day_ago = now - 60*60*24
        if fileCreation < day_ago:
            remove(location)
            return banner_view(request, name)
        else:
            # older than day remove
            response = HttpResponse(mimetype="image/png")
            img = Image.open(location)
            img.save(response, 'png')
            return response
    else:
        p = PlayerStats.objects.filter(nickname=name)
        url = '/player_statistics/ranked/nickname/' + name
        if p.exists():
            tdelta = datetime.now() - datetime.strptime(str(p.values()[0]['updated']), "%Y-%m-%d %H:%M:%S")
            if tdelta.seconds + (tdelta.days * 86400) < 1000:
                s = p.values()[0]
                response = HttpResponse(mimetype="image/png")
                img = banner(s)
                img.save(response, 'png')
                img.save(directory + str(name) + ".png")
                return response
        data = get_json(url)
        if data is not None:
            statsdict = data
            s = player_math(statsdict, "rnk")
            player_save(s, "rnk")
            response = HttpResponse(mimetype="image/png")
            img = banner(s)
            img.save(response, 'png')
            img.save(directory + str(name) + ".png")
            return response
        else:
            response = HttpResponse()
            response.status_code = 404
            return response