def update_num_gildings(update_trophy=True, user_id=None): """Returns total number of link, comment, and user gildings""" query = (select([gold_table.c.paying_id, sa_count(gold_table.c.trans_id)]) .where(gold_table.c.trans_id.like('X%')) .group_by(gold_table.c.paying_id) .order_by(sa_count(gold_table.c.trans_id).desc()) ) if user_id: query = query.where(gold_table.c.paying_id == str(user_id)) rows = ENGINE.execute(query) total_updated = 0 for paying_id, count in rows: try: a = Account._byID(int(paying_id), data=True) a.num_gildings = count a._commit() total_updated += 1 #if 'server seconds paid' for are public, update gilding trophies if update_trophy and a.pref_public_server_seconds: add_to_trophy_queue(a, "gilding") except: g.log.debug("update_num_gildings: paying_id %s is invalid" % paying_id) g.log.debug("update_num_gildings: updated %s accounts" % total_updated)
def update_num_gildings(update_trophy=True, user_id=None): """Returns total number of link, comment, and user gildings""" query = (select([gold_table.c.paying_id, sa_count(gold_table.c.trans_id) ]).where(gold_table.c.trans_id.like('X%')).group_by( gold_table.c.paying_id).order_by( sa_count(gold_table.c.trans_id).desc())) if user_id: query = query.where(gold_table.c.paying_id == str(user_id)) rows = ENGINE.execute(query) total_updated = 0 for paying_id, count in rows: try: a = Account._byID(int(paying_id), data=True) a.num_gildings = count a._commit() total_updated += 1 #if 'server seconds paid' for are public, update gilding trophies if update_trophy and a.pref_public_server_seconds: add_to_trophy_queue(a, "gilding") except: g.log.debug("update_num_gildings: paying_id %s is invalid" % paying_id) g.log.debug("update_num_gildings: updated %s accounts" % total_updated)
def gold_buyers_on(date): start_date = datetime.datetime.combine(date, datetime.time.min) end_date = datetime.datetime.combine(date, datetime.time.max) NON_REVENUE_STATUSES = ("declined", "chargeback", "fudge") date_expr = func.timezone(TIMEZONE.zone, gold_table.c.date) query = (select([distinct(gold_table.c.account_id)]) .where(~ gold_table.c.status.in_(NON_REVENUE_STATUSES)) .where(date_expr >= start_date) .where(date_expr <= end_date) .where(gold_table.c.pennies > 0) ) rows = ENGINE.execute(query) return [int(account_id) for (account_id,) in rows.fetchall() if account_id]