def create_user(steamid, group=UserGroup.NORMAL): """ Attempts to create a user based on their steamid, and optionally a group. This expectes to fail if the steamid already exists, and will raise `psycopg2.IntegrityError` when it does. """ with Cursor() as c: now = datetime.utcnow() return c.execute(CREATE_USER_QUERY, (steamid, True, now, now, group, Cursor.json(DEFAULT_SETTINGS))).fetchone().id
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)
def create_match(user, game, teams, meta, lock_date, match_date, public_date, view_perm=UserGroup.NORMAL): validate_match_team_data(teams) with Cursor() as c: c.execute(CREATE_MATCH_SQL, { "game": game, "teams": teams, "meta": meta, "results": Cursor.json({}), "lock_date": lock_date, "match_date": match_date, "public_date": public_date, "view_perm": view_perm, "active": False, "created_at": datetime.utcnow(), "created_by": user }) return c.fetchone().id