コード例 #1
0
ファイル: item.py プロジェクト: parkjoon/csgo-emporium
def ensure_item_added(name, class_id, instance_id, image):
    try:
        item_price = steam.market().get_item_price(name)
    except SteamAPIError:
        log.exception("Failed to get price for item '%s'" % name)

    with Cursor() as c:
        c.execute("SELECT id FROM items WHERE name=%s", (name, ))
コード例 #2
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)
コード例 #3
0
ファイル: jobs.py プロジェクト: parkjoon/csgo-emporium
def process_item(name, image, data):
    with Cursor() as c:
        pdata = c.execute("SELECT id, price FROM items WHERE name=%s", (name, )).fetchone()

        if pdata:
            return (pdata.id, float(pdata.price))

        try:
            i_vol, i_low, i_med = steam.market(730).get_item_price(name)
        except SteamAPIError:
            log.exception("Failed to get price for item '%s'" % name)

        new = c.execute("INSERT INTO items (name, price, meta) VALUES (%s, %s, %s) RETURNING id", (
            name, i_low, Cursor.json({
                "image": image,
                "descriptions": data
            })
        )).fetchone()
        return (new.id, i_low)
コード例 #4
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)