Exemplo n.º 1
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)
Exemplo n.º 2
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