Example #1
0
def auth_route_avatar(id):
    key = "avatar:%s" % id
    if redis.exists(key):
        buffered = StringIO(redis.get(key))
    else:
        with Cursor() as c:
           user = c.execute("SELECT steamid FROM users WHERE id=%s", (id, )).fetchone()

           if not user:
               raise APIError("Invalid User ID")

        data = steam.getUserInfo(user.steamid)

        try:
            r = requests.get(data.get('avatarfull'))
            r.raise_for_status()
        except Exception:
            return "", 500

        # Cached for 1 hour
        buffered = StringIO(r.content)
        redis.setex(key, r.content, (60 * 60))

    buffered.seek(0)
    return send_file(buffered, mimetype="image/jpeg")
Example #2
0
def gache_nickname(steamid):
    """
    Gets a steam nickname either from the cache, or the steam API. It
    then ensures it's cached for 2 hours.
    """
    nick = redis.get("nick:%s" % steamid)
    if not nick:
        nick = steam.getUserInfo(steamid)['personaname']
        redis.setex("nick:%s" % steamid, nick, 60 * 120)

    if not isinstance(nick, unicode):
        nick = nick.decode("utf-8")

    return nick