Browse Source

Read cases from the database too.

tags/v0.1^2
Ben Kurtovic 12 years ago
parent
commit
93228d5b08
2 changed files with 24 additions and 7 deletions
  1. +22
    -6
      earwigbot/tasks/drn_clerkbot.py
  2. +2
    -1
      earwigbot/tasks/schema/drn_clerkbot.sql

+ 22
- 6
earwigbot/tasks/drn_clerkbot.py View File

@@ -66,11 +66,24 @@ class DRNClerkBot(Task):
def run(self, **kwargs):
"""Entry point for a task event."""
with self.db_access_lock:
conn = oursql.connect(**self.conn_data)
cases = read_database(conn)
page = self.bot.wiki.get_site().get_page(self.title)
text = page.get()
current = read_page(text)
current = read_page(cases, text)

def read_page(self, text):
def read_database(self, conn):
"""Return a list of _Cases from the database."""
cases = []
query = "SELECT case_id, case_title, case_status FROM case"
with conn.cursor() as cursor:
cursor.execute(query)
for id_, name, status in cursor:
cases.append(_Case(id_, title, status))
return cases

def read_page(self, cases, text):
"""Read the noticeboard content and update the list of _Cases."""
split = re.split("(^==\s*[^=]+?\s*==$)", text, flags=re.M|re.U)
cases = []
case = None
@@ -87,9 +100,9 @@ class DRNClerkBot(Task):
case.status = self.read_status(body)
if case:
cases.append(case)
return cases

def read_status(self, body):
"""Parse the current status from a case body."""
aliases = {
self.STATUS_NEW: ("",),
self.STATUS_OPEN: ("open", "active", "inprogress"),
@@ -110,7 +123,10 @@ class DRNClerkBot(Task):


class _Case(object):
def __init__(self):
self.title = None
"""A simple object representing a dispute resolution case."""
def __init__(self, id_, title, status):
self.id = id_
self.title = title
self.status = status

self.body = None
self.status = None

+ 2
- 1
earwigbot/tasks/schema/drn_clerkbot.sql View File

@@ -15,7 +15,8 @@ CREATE DATABASE `u_earwig_drn_clerkbot`
DROP TABLE IF EXISTS `case`;
CREATE TABLE `case` (
`case_id` int(10) unsigned NOT NULL,
`case_name` varchar(512) COLLATE utf8_unicode_ci DEFAULT NULL,
`case_title` varchar(512) COLLATE utf8_unicode_ci DEFAULT NULL,
`case_status` int(2) unsigned NOT NULL,
PRIMARY KEY (`case_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;



Loading…
Cancel
Save