def main(crsid, postgres_settings): logger.info("Creating half price ticket for %s", crsid) logging_setup.add_postgresql_handler(postgres_settings) logging_setup.add_syslog_handler() logging_setup.add_smtp_handler() conn = psycopg2.connect(connection_factory=utils.PostgreSQLConnection, **postgres_settings) user = users.get_raven_user(crsid, pg=conn) if user is None: conn.commit() lookup_data = lookup.get_crsid(crsid) user = users.new_raven_user(crsid, ["current"], lookup_data, pg=conn) if tickets.tickets(user_id=user["user_id"], expired=False, pg=conn): raise ValueError("User {0} already has some tickets" .format(user["user_id"])) ticket_id, = tickets.buy("standard", True, 1, user=user, pg=conn) with conn.cursor() as cur: cur.execute("UPDATE tickets " "SET waiting_list = FALSE, quota_exempt = TRUE, " " expires = NULL, expires_reason = NULL, " " price = 3450, notes = E'Ents half price ticket\n' " "WHERE ticket_id = %s", (ticket_id, )) conn.commit()
def prepare(postgres_settings, pairs): # This is a hack, to cover up a design flaw. logging_setup.add_syslog_handler() logging_setup.add_postgresql_handler(postgres_settings) logging_setup.add_smtp_handler() conn = psycopg2.connect(connection_factory=utils.PostgreSQLConnection, **postgres_settings) for user_id, ticket_id in pairs: with conn.cursor(True) as cur: cur.execute("SELECT * FROM tickets " "WHERE ticket_id = %s AND user_id = %s", (ticket_id, user_id)) assert cur.rowcount == 1 ticket = cur.fetchone() cur.execute("SELECT * FROM tickets " "WHERE user_id = %s AND surname = %s " "AND othernames = %s AND finalised IS NOT NULL", (user_id, ticket["surname"], ticket["othernames"])) if cur.rowcount != 2: print("Couldn't find standard ticket for", user_id, ticket_id) continue standard_ticket, b = cur.fetchall() if standard_ticket["ticket_id"] == ticket_id: standard_ticket = b if standard_ticket["waiting_list"] or standard_ticket["vip"] \ or not standard_ticket["paid"]: print("Bad standard ticket for", user_id, ticket_id) continue logger.info("Preparing waiting ticket %s to VIP upgrade %s", ticket_id, standard_ticket["ticket_id"], extra={"user_id": user_id}) notes = "Prepared to replace {0} " \ "(VIP upgrade waiting list release) on {1}\n" \ .format(standard_ticket["ticket_id"], datetime.utcnow()) cur.execute("UPDATE tickets " "SET price = 1000, notes = notes || %s " "WHERE ticket_id = %s AND user_id = %s", (notes, ticket_id, user_id)) notes = "Replaced by VIP ticket {0} from waiting list on {1}\n" \ .format(ticket_id, datetime.utcnow()) cur.execute("UPDATE tickets " "SET expires=utcnow(), " " expires_reason='admin-intervention', " " finalised=NULL, paid=NULL, " " notes = notes || %s " "WHERE ticket_id = %s AND user_id = %s", (notes, standard_ticket["ticket_id"], user_id)) conn.commit()
def purge(postgres_settings, pairs): logging_setup.add_syslog_handler() logging_setup.add_postgresql_handler(postgres_settings) logging_setup.add_smtp_handler() conn = psycopg2.connect(connection_factory=utils.PostgreSQLConnection, **postgres_settings) for user_id, ticket_id in pairs: tickets.purge_unpaid(user_id, ticket_id, pg=conn) conn.commit()
def release(postgres_settings, pairs): logging_setup.add_syslog_handler() logging_setup.add_postgresql_handler(postgres_settings) logging_setup.add_smtp_handler() conn = psycopg2.connect(connection_factory=utils.PostgreSQLConnection, **postgres_settings) for user_id, ticket_ids in pairs: tickets.waiting_release(user_id, ticket_ids, ask_pay_within=1, pg=conn) conn.commit()
def main(crsid, postgres_settings): logger.info("Creating raven user for %s", crsid) logging_setup.add_postgresql_handler(postgres_settings) logging_setup.add_syslog_handler() logging_setup.add_smtp_handler() conn = psycopg2.connect(connection_factory=utils.PostgreSQLConnection, **postgres_settings) user = users.get_raven_user(crsid, pg=conn) if user is None: conn.commit() lookup_data = lookup.get_crsid(crsid) user = users.new_raven_user(crsid, ["current"], lookup_data, pg=conn) conn.commit()
def main(postgres_settings, filename): logging_setup.add_syslog_handler() logging_setup.add_postgresql_handler(postgres_settings) logging_setup.add_smtp_handler() conn = psycopg2.connect(connection_factory=utils.PostgreSQLConnection, **postgres_settings) mailed = set() with open(filename) as f: for line in f: user_id = int(line.strip()) if user_id in mailed: logger.warning("Not double-mailing %s", user_id) continue mailed.add(user_id) send_mail(user_id, pg=conn) conn.commit()
def harass(postgres_settings, filename): logging_setup.add_syslog_handler() logging_setup.add_postgresql_handler(postgres_settings) logging_setup.add_smtp_handler() conn = psycopg2.connect(connection_factory=utils.PostgreSQLConnection, **postgres_settings) harassed = set() with open(filename) as f: for user_id, deadline in csv.reader(f): user_id = int(user_id) if user_id in harassed: logger.warning("Not double-harassing %s", user_id) continue harassed.add(user_id) deadline = datetime.strptime(deadline, "%Y-%m-%d").date() send_update(user_id, harass=True, deadline=deadline, pg=conn) conn.commit()
def main(crsid, postgres_settings): logger.info("Creating free VIP upgrade for %s", crsid) logging_setup.add_postgresql_handler(postgres_settings) logging_setup.add_syslog_handler() logging_setup.add_smtp_handler() conn = psycopg2.connect(connection_factory=utils.PostgreSQLConnection, **postgres_settings) lookup_data = lookup.get_crsid(crsid) user = users.new_raven_user(crsid, ["current"], lookup_data, pg=conn) ticket_id, = tickets.buy("vip", False, 1, user=user, pg=conn) with conn.cursor() as cur: cur.execute("UPDATE tickets " "SET expires = NULL, expires_reason = NULL, " " price = 6900 " "WHERE ticket_id = %s", (ticket_id, )) logging.info("Free VIP upgraded ticket %s", ticket_id) conn.commit()
from __future__ import unicode_literals, print_function import sys import os import logging root = os.path.join(os.path.dirname(__file__), '..') sys.path.insert(0, root) from snowball_ticketing.tickets.payments import main from snowball_ticketing import logging_setup logging.basicConfig(level=logging.DEBUG) logging_setup.add_smtp_handler() if len(sys.argv) != 4 or \ sys.argv[1] not in ('live', 'test') or \ sys.argv[3] not in ('dry-run', 'confirm'): print("Usage:", sys.argv[0], "live|test", "filename.csv", "dry-run|confirm") else: postgres_settings = { "live": { "dbname": "ticketing" }, "test": { "dbname": "ticketing-test" } }[sys.argv[1]]
import sys import os import logging root = os.path.join(os.path.dirname(__file__), '..') sys.path.insert(0, root) from snowball_ticketing.tickets.receipt import receipts_main from snowball_ticketing import logging_setup postgres = {"database": "ticketing"} logging_setup.add_postgresql_handler(postgres) logging_setup.add_syslog_handler() logging_setup.add_smtp_handler() receipts_main(postgres)
def prepare(postgres_settings, pairs): # This is a hack, to cover up a design flaw. logging_setup.add_syslog_handler() logging_setup.add_postgresql_handler(postgres_settings) logging_setup.add_smtp_handler() conn = psycopg2.connect(connection_factory=utils.PostgreSQLConnection, **postgres_settings) for user_id, ticket_id in pairs: with conn.cursor(True) as cur: cur.execute( "SELECT * FROM tickets " "WHERE ticket_id = %s AND user_id = %s", (ticket_id, user_id)) assert cur.rowcount == 1 ticket = cur.fetchone() cur.execute( "SELECT * FROM tickets " "WHERE user_id = %s AND surname = %s " "AND othernames = %s AND finalised IS NOT NULL", (user_id, ticket["surname"], ticket["othernames"])) if cur.rowcount != 2: print("Couldn't find standard ticket for", user_id, ticket_id) continue standard_ticket, b = cur.fetchall() if standard_ticket["ticket_id"] == ticket_id: standard_ticket = b if standard_ticket["waiting_list"] or standard_ticket["vip"] \ or not standard_ticket["paid"]: print("Bad standard ticket for", user_id, ticket_id) continue logger.info("Preparing waiting ticket %s to VIP upgrade %s", ticket_id, standard_ticket["ticket_id"], extra={"user_id": user_id}) notes = "Prepared to replace {0} " \ "(VIP upgrade waiting list release) on {1}\n" \ .format(standard_ticket["ticket_id"], datetime.utcnow()) cur.execute( "UPDATE tickets " "SET price = 1000, notes = notes || %s " "WHERE ticket_id = %s AND user_id = %s", (notes, ticket_id, user_id)) notes = "Replaced by VIP ticket {0} from waiting list on {1}\n" \ .format(ticket_id, datetime.utcnow()) cur.execute( "UPDATE tickets " "SET expires=utcnow(), " " expires_reason='admin-intervention', " " finalised=NULL, paid=NULL, " " notes = notes || %s " "WHERE ticket_id = %s AND user_id = %s", (notes, standard_ticket["ticket_id"], user_id)) conn.commit()