From ab1fe9926ab4009459960a84010fe9cfff373847 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Sat, 28 Jul 2012 13:59:29 -0400 Subject: [PATCH] Split up that one huge function into three. --- earwigbot/tasks/drn_clerkbot.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/earwigbot/tasks/drn_clerkbot.py b/earwigbot/tasks/drn_clerkbot.py index c8f72c7..13f9b4c 100644 --- a/earwigbot/tasks/drn_clerkbot.py +++ b/earwigbot/tasks/drn_clerkbot.py @@ -246,7 +246,10 @@ class DRNClerkBot(Task): log = u"Unsure of how to deal with case {0} (title: {1})" self.logger.error(log.format(case.id, case.title)) return notices + self.save_case_updates(conn, case) + return notices + def save_case_updates(self, conn, case): if case.status != case.original_status: case.last_action = case.status new = self.ALIASES[case.status][0] @@ -256,14 +259,19 @@ class DRNClerkBot(Task): case.body = re.sub(search, repl, case.body) if case.new: - with conn.cursor() as cursor: - query = "INSERT INTO case VALUES (?, ?, ?, ?, ?, ?, ?, ?)" - cursor.execute(query, (case.id, case.title, case.status, - case.last_action, case.file_time, - case.close_time, case.parties_notified, - case.very_old_notified)) - return notices + self.save_new_case(conn, case) + else: + self.save_existing_case(conn, case) + def save_new_case(self, conn, case): + args = (case.id, case.title, case.status, case.last_action, + case.file_time, case.close_time, case.parties_notified, + case.very_old_notified) + with conn.cursor() as cursor: + query = "INSERT INTO case VALUES (?, ?, ?, ?, ?, ?, ?, ?)" + cursor.execute(query, args) + + def save_existing_case(self, conn, case): with conn.cursor(oursql.DictCursor) as cursor: query = "SELECT * FROM case WHERE case_id = ?" cursor.execute(query, (case.id,)) @@ -286,7 +294,6 @@ class DRNClerkBot(Task): args.append(case.id) query = "UPDATE case SET {0} WHERE case_id = ?".format(changes) cursor.execute(query, args) - return notices def clerk_new_case(self, case, volunteers, signatures): notices = self.notify_parties(case)