def get_acks(self, wfile, report): conn = Util.get_db_conn() cur = conn.cursor() self.report_header( wfile, report, generate_links=True, msg="Report for week:", ) cur.execute("SELECT id, msg FROM ack WHERE inserted_at>%s AND inserted_at<%s", (report.start, report.end)) raw_acks = cur.fetchall() acks = [Ack(id=ack[0], msg=ack[1]) for ack in raw_acks] # Sort acks by the first word. Assuming that many of them start with # the name of a person, those will sort together. acks = sorted(acks, key=lambda ack: ack.msg.split()[0]) self.write(wfile, """ <p> Acks:<br> {0} """.format(self.render_acks(acks)) ) cur.close() conn.close()
def delete_bounty(self, bounty_id): conn = Util.get_db_conn() cur = conn.cursor() cur.execute("DELETE FROM bounties WHERE id=%s", (bounty_id, )) conn.commit() cur.close() conn.close()
def delete_ack(self, ack_id): conn = Util.get_db_conn() cur = conn.cursor() cur.execute("DELETE FROM ack WHERE id=%s", (ack_id, )) conn.commit() cur.close() conn.close()
def delete_eng_update(self, update_id): conn = Util.get_db_conn() cur = conn.cursor() cur.execute("DELETE FROM eng_updates WHERE id=%s", (update_id, )) conn.commit() cur.close() conn.close()
def close_bounty(self, bounty_id): conn = Util.get_db_conn() cur = conn.cursor() cur.execute("update bounties set active=false where id=%s", (bounty_id,)) conn.commit() cur.close() conn.close()
def insert_eng_update(self, user, eng_update): now = datetime.datetime.now(pytz.utc) conn = Util.get_db_conn() cur = conn.cursor() cur.execute( "INSERT INTO eng_updates (msg, inserted_at, user_email) VALUES (%s, %s, %s)", (eng_update, now, user)) conn.commit() cur.close() conn.close()
def get_my_acks(self, wfile, email, report): conn = Util.get_db_conn() cur = conn.cursor() cur.execute("SELECT id, msg FROM ack WHERE user_email=%s "+ "AND inserted_at>%s AND inserted_at<%s", (email, report.start, report.end)) acks = cur.fetchall() self.write(wfile, '<table border="1">') for ack in acks: self.render_ack(wfile, Ack(ack[0], ack[1])) self.write(wfile, "</table>") cur.close() conn.close()
def insert_acks(self, user, acks, haiku): ack_time = Util.adjust_ack_ts(datetime.datetime.now(pytz.utc)) conn = Util.get_db_conn() cur = conn.cursor() for ack in acks: cur.execute( "INSERT INTO ack (msg, inserted_at, user_email) VALUES (%s, %s, %s)", (ack, ack_time, user)) haiku = haiku.rstrip() if len(haiku) > 0: cur.execute( "INSERT INTO ack (msg, inserted_at, user_email) VALUES (%s, %s, %s)", (haiku, ack_time, user)) conn.commit() cur.close() conn.close()
def get_open_bounties(): conn = Util.get_db_conn() cur = conn.cursor() cur.execute("select id, author, created, updated, msg, active " + "from bounties where active = true order by updated desc") bounties_raw = cur.fetchall() bounties = [ Bounty(id=b[0], author=b[1], created=b[2], updated=b[3], msg=b[4], active=b[5]) for b in bounties_raw ] cur.close() conn.close() return bounties
def serve_acks(handler, verb): user_email = Auth.get_user_email(handler) handler.send_response(200) handler.send_header('Content-type', 'application/json') handler.end_headers() now = datetime.datetime.now(pytz.utc) report = Util.ReportWindow(now + datetime.timedelta(days=-7), now) conn = Util.get_db_conn() cur = conn.cursor() cur.execute("SELECT msg FROM ack WHERE inserted_at>%s AND inserted_at<%s", (report.start, report.end)) acks = cur.fetchall() handler.wfile.write( bytes(json.dumps({"acks": [ack[0] for ack in acks]}), "utf8")) cur.close() conn.close() return
def get_eng_updates(report, user_email): conn = Util.get_db_conn() cur = conn.cursor() if user_email is None: cur.execute( "SELECT id, msg FROM eng_updates WHERE " + "inserted_at>%s AND inserted_at<%s", (report.start, report.end)) else: cur.execute( "SELECT id, msg FROM eng_updates WHERE " + "inserted_at>%s AND inserted_at<%s AND user_email=%s", (report.start, report.end, user_email)) updates_raw = cur.fetchall() updates = [EngUpdate(id=upd[0], msg=upd[1]) for upd in updates_raw] cur.close() conn.close() return updates
def handle_add_bounty(self, data, user): msg = "" if b'bounty' in data: msg = data[b'bounty'][0].decode("utf-8") else: return False created_ts = datetime.datetime.now(pytz.utc) updated_ts = created_ts conn = Util.get_db_conn() cur = conn.cursor() cur.execute( "INSERT INTO bounties (author, created, updated, msg, active) " + "VALUES (%s, %s, %s, %s, %s)", (user, created_ts, updated_ts, msg, "true")) conn.commit() cur.close() conn.close() return True