コード例 #1
0
ファイル: api.py プロジェクト: parkjoon/csgo-emporium
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")
コード例 #2
0
ファイル: sessions.py プロジェクト: parkjoon/csgo-emporium
 def __init__(self, id=None):
     self._id = id or request.cookies.get("s")
     if self._id and redis.exists("session:%s" % self._id):
         log.debug('loading session %s', self._id)
         self._data = json.loads(redis.get("session:%s" % self._id))
     else:
         self._id = None
         self._data = {}
     self._changed = False
コード例 #3
0
ファイル: user.py プロジェクト: parkjoon/csgo-emporium
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
コード例 #4
0
ファイル: queue.py プロジェクト: parkjoon/csgo-emporium
def handle_inventory_jobs(job):
    inv_key = "inv:%s" % job["steamid"]

    if redis.exists(inv_key):
        result = {"success": True, "inventory": json.loads(redis.get(inv_key)), "type": "inventory"}
        log.debug("inventory job hit cache")
    else:
        try:
            log.debug("inventory job missed cache")
            inv = steam.market(730).get_inventory(job["steamid"])
            redis.set(inv_key, json.dumps(inv))
            result = {"success": True, "inventory": inv, "type": "inventory"}
        except:
            log.exception("Failed to process job %s")
            result = {"success": False, "inventory": {}, "type": "inventory"}

    WebPush(job["user"]).send(result)
コード例 #5
0
ファイル: jobs.py プロジェクト: parkjoon/csgo-emporium
def handle_inventory_job(job):
    inv_key = 'inv:%s' % job['steamid']

    if redis.exists(inv_key):
        inv = json.loads(redis.get(inv_key))
        pending = get_pending_items(job['user'])

        inv = filter(lambda i: (False and pending.remove(i['id'])) if i['id'] in pending else True, inv)

        result = {"success": True, "inventory": inv, "type": "inventory"}
        return WebPush(job['user']).send(result)

    try:
        inv = steam.market(730).get_inventory(job["steamid"])
        inv = process_inventory(inv)
        redis.set(inv_key, json.dumps(inv))
        result = {"success": True, "inventory": inv, "type": "inventory"}
    except SteamAPIError:
        log.exception("Failed to load inventory:")
        result = {"success": False, "inventory": {}, "type": "inventory"}

    WebPush(job['user']).send(result)