From b414e5f1ca9738634ce93111bb95dff348ee7e36 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 8 Feb 2011 23:44:06 +0100 Subject: [PATCH 01/10] mensa: Ignore case in regex --- modules/mensa.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/mensa.py b/modules/mensa.py index 3c3a197..d86183a 100644 --- a/modules/mensa.py +++ b/modules/mensa.py @@ -32,8 +32,8 @@ class Module(ModuleBase): return def handle_data(data): - r = re.compile(r'.*?]*>(.*?).*?]*>(.*?)', re.DOTALL) - r2 = re.compile(r'.*?]*>(.*?)', re.DOTALL) + r = re.compile(r'.*?]*>(.*?).*?]*>(.*?)', re.DOTALL|re.IGNORECASE) + r2 = re.compile(r'.*?]*>(.*?)', re.DOTALL|re.IGNORECASE) def handle_data_row(data, pos): match = r.match(data, pos) @@ -59,7 +59,7 @@ class Module(ModuleBase): return (ret, match.end()) - match = re.compile(r'^.*?]*>.*?]*>.*?(\d+)\.(\d+)\. - \d+\.\d+\.(\d+).*?.*?]*>Freitag\s*(.*?).*$', re.DOTALL).match(data) + match = re.compile(r'^.*?]*>.*?]*>.*?(\d+)\.(\d+)\. - \d+\.\d+\.(\d+).*?.*?]*>Freitag\s*(.*?).*$', re.DOTALL|re.IGNORECASE).match(data) if not match: return False From ab10b2ae43036067efc106c091c5703db6f8adca Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 14 Feb 2011 02:02:00 +0100 Subject: [PATCH 02/10] mensa: Temporily disable Wok-Gericht --- modules/mensa.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/mensa.py b/modules/mensa.py index d86183a..4867670 100644 --- a/modules/mensa.py +++ b/modules/mensa.py @@ -75,7 +75,7 @@ class Module(ModuleBase): meals = [] pos = 0 - for i in range(0,6): + for i in range(0,5): row = handle_data_row(data, pos) if not row: @@ -122,10 +122,10 @@ class Module(ModuleBase): reply += 'Hauptgericht 2: %s (%s)\n' % meals[3][weekday] if meals[2][weekday][0]: reply += 'Vegetarisches Hauptgericht: %s (%s)\n' % meals[2][weekday] + #if meals[4][weekday][0]: + # reply += 'Wok: %s (%s)\n' % meals[4][weekday] if meals[4][weekday][0]: - reply += 'Wok: %s (%s)\n' % meals[4][weekday] - if meals[5][weekday][0]: - reply += 'Beilagen: %s (%s)\n' % meals[5][weekday] + reply += 'Beilagen: %s (%s)\n' % meals[4][weekday] return reply From b07ceef46be030b0c82855149b1fe5d55bc4cebb Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 7 Mar 2011 19:47:25 +0100 Subject: [PATCH 03/10] Made the mensa module a bit more flexible --- modules/mensa.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/modules/mensa.py b/modules/mensa.py index 4867670..d8ee447 100644 --- a/modules/mensa.py +++ b/modules/mensa.py @@ -79,7 +79,7 @@ class Module(ModuleBase): row = handle_data_row(data, pos) if not row: - return False + break meals.append(row[0]) pos = row[1] @@ -113,6 +113,12 @@ class Module(ModuleBase): stripunescape = (lambda item: (unescape(item[0].strip()), unescape(item[1].strip()))) meals = map(lambda item: map(stripunescape, item), meals) + if len(meals) == 0: + return False + + while len(meals) < 6: + meals.insert(len(meals)-1, [[None], [None], [None], [None], [None]]) + reply = 'Mensa-Menü für den %s\n\n' % day.strftime('%d.%m.%y') if meals[0][weekday][0]: reply += 'Eintopf: %s (%s)\n' % meals[0][weekday] @@ -122,10 +128,10 @@ class Module(ModuleBase): reply += 'Hauptgericht 2: %s (%s)\n' % meals[3][weekday] if meals[2][weekday][0]: reply += 'Vegetarisches Hauptgericht: %s (%s)\n' % meals[2][weekday] - #if meals[4][weekday][0]: - # reply += 'Wok: %s (%s)\n' % meals[4][weekday] if meals[4][weekday][0]: - reply += 'Beilagen: %s (%s)\n' % meals[4][weekday] + reply += 'Wok: %s (%s)\n' % meals[4][weekday] + if meals[5][weekday][0]: + reply += 'Beilagen: %s (%s)\n' % meals[5][weekday] return reply From aba29f23e65e61be194477df1e25fd355ca4dd65 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 21 Mar 2011 17:13:29 +0100 Subject: [PATCH 04/10] Number thinko, duh... --- modules/mensa.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/mensa.py b/modules/mensa.py index d8ee447..b6ba3fa 100644 --- a/modules/mensa.py +++ b/modules/mensa.py @@ -75,7 +75,7 @@ class Module(ModuleBase): meals = [] pos = 0 - for i in range(0,5): + for i in range(0,6): row = handle_data_row(data, pos) if not row: From a52e07d9047b0f41c16e51e083cc8639eaa88328 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 5 Sep 2011 22:40:46 +0200 Subject: [PATCH 05/10] Changed log backend to PostgreSQL --- modules/log.py | 22 +++++++++++++--------- modules/pgsql.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 modules/pgsql.py diff --git a/modules/log.py b/modules/log.py index ff8093e..74e813a 100644 --- a/modules/log.py +++ b/modules/log.py @@ -3,27 +3,31 @@ from . import ModuleBase class Module(ModuleBase): def __init__(self, manager): ModuleBase.__init__(self, manager) - self.mysql = manager.get('mysql') + self.pgsql = manager.get('pgsql') def helptexts(self): return ['Chatlogs werden auch erstellt.'] def groupchat(self, room, nick, text, handler): - cursor = self.mysql.cursor() - cursor.execute('INSERT INTO log (`type`, `time`, `room`, `nick`, `text`) VALUES ("message", NOW(), %s, %s, %s)', (room, nick, text)) + cursor = self.pgsql.cursor() + cursor.execute('INSERT INTO log ("type", "time", "room", "nick", "text") VALUES (\'message\', now(), %s, %s, %s)', (room, nick, text)) cursor.close() + self.pgsql.commit() def join(self, room, nick, show, status, handler): - cursor = self.mysql.cursor() - cursor.execute('INSERT INTO log (`type`, `time`, `room`, `nick`, `show`, `text`) VALUES ("join", NOW(), %s, %s, %s, %s)', (room, nick, show, status)) + cursor = self.pgsql.cursor() + cursor.execute('INSERT INTO log ("type", "time", "room", "nick", "show", "text") VALUES (\'join\', now(), %s, %s, %s, %s)', (room, nick, show, status)) cursor.close() + self.pgsql.commit() def leave(self, room, nick, show, status, handler): - cursor = self.mysql.cursor() - cursor.execute('INSERT INTO log (`type`, `time`, `room`, `nick`, `show`, `text`) VALUES ("leave", NOW(), %s, %s, %s, %s)', (room, nick, show, status)) + cursor = self.pgsql.cursor() + cursor.execute('INSERT INTO log ("type", "time", "room", "nick", "show", "text") VALUES (\'leave\', now(), %s, %s, %s, %s)', (room, nick, show, status)) cursor.close() + self.pgsql.commit() def topic(self, room, nick, text, handler): - cursor = self.mysql.cursor() - cursor.execute('INSERT INTO log (`type`, `time`, `room`, `nick`, `text`) VALUES ("topic", NOW(), %s, %s, %s)', (room, nick, text)) + cursor = self.pgsql.cursor() + cursor.execute('INSERT INTO log ("type", "time", "room", "nick", "text") VALUES (\'topic\', now(), %s, %s, %s)', (room, nick, text)) cursor.close() + self.pgsql.commit() diff --git a/modules/pgsql.py b/modules/pgsql.py new file mode 100644 index 0000000..24cec76 --- /dev/null +++ b/modules/pgsql.py @@ -0,0 +1,30 @@ +from . import ModuleBase +from pyPgSQL import PgSQL + +class Module(ModuleBase): + def __init__(self, manager): + ModuleBase.__init__(self, manager) + + self.conf = manager.config['pgsql'] + + self.db = False + self._connect() + + def _connect(self): + if self.db: + try: + self.db.close() + except: + pass + + self.db = PgSQL.connect(host = self.conf['host'], user = self.conf['user'], password = self.conf['passwd'], database = self.conf['db'], client_encoding = 'utf8', unicode_results = 1) + + def cursor(self): + try: + return self.db.cursor() + except PgSQL.OperationalError: + self._connect() + return self.db.cursor() + + def commit(self): + self.db.commit() From 33bbc21b0f056475eed27977e623dc5bd0e6ce85 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 27 Oct 2011 13:28:49 +0200 Subject: [PATCH 06/10] mensa: Add egrave entity --- modules/mensa.py | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/mensa.py b/modules/mensa.py index b6ba3fa..96f338a 100644 --- a/modules/mensa.py +++ b/modules/mensa.py @@ -95,6 +95,7 @@ class Module(ModuleBase): s = s.replace('Ü', 'Ü') s = s.replace('ß', 'ß') s = s.replace('é', 'é') + s = s.replace('è', 'è') s = s.replace('“', '“') s = s.replace('„', '„') s = s.replace('–', '–') From bb0168b6b8c1cad235c4fcd49a8b4232d4d07ee6 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 6 Mar 2012 05:40:29 +0100 Subject: [PATCH 07/10] Fix mensa module --- modules/mensa.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/mensa.py b/modules/mensa.py index 96f338a..b14ac02 100644 --- a/modules/mensa.py +++ b/modules/mensa.py @@ -59,7 +59,7 @@ class Module(ModuleBase): return (ret, match.end()) - match = re.compile(r'^.*?]*>.*?]*>.*?(\d+)\.(\d+)\. - \d+\.\d+\.(\d+).*?.*?]*>Freitag\s*(.*?).*$', re.DOTALL|re.IGNORECASE).match(data) + match = re.compile(r'^.*?]*>.*?]*>.*?(\d+)\.(\d+)\. ?- ?\d+\.\d+\.(\d+).*?.*?]*>Freitag\s*(.*?).*$', re.DOTALL|re.IGNORECASE).match(data) if not match: return False From dbc091688f1edbbffb8c70e29778a9437b2d0e47 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 22 Apr 2012 17:43:15 +0200 Subject: [PATCH 08/10] Improved topic module --- connection/xmpp.py | 1 + modules/topic.py | 60 +++++++++++++++++++++++++++++++++------------- 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/connection/xmpp.py b/connection/xmpp.py index dd1c061..d6e3a3f 100644 --- a/connection/xmpp.py +++ b/connection/xmpp.py @@ -33,6 +33,7 @@ class MucHandler(MucRoomHandler): def set_topic(self, topic): self.room_state.set_subject(topic) + self.room_state.subject = topic def message_received(self, user, stanza): if(user == None or user.same_as(self.room_state.me) or stanza.get_body() == None): diff --git a/modules/topic.py b/modules/topic.py index d878a91..7f4ca10 100644 --- a/modules/topic.py +++ b/modules/topic.py @@ -6,24 +6,52 @@ import re class Module(ModuleBase): def __init__(self, manager): ModuleBase.__init__(self, manager) - + def commands(self): - return [('!topic []', 'Fügt einen Text zum Thema des Chatraums hinzu oder zeigt das aktuelle Topic an')] - + return [ + ('!topic [s[how]]', 'Zeigt das aktuelle Topic mit IDs an'), + ('!topic a[dd] ', 'Fügt einen Text zum Thema des Chatraums hinzu'), + ('!topic d[el[ete]] ', 'Entfernt das Topic mit der ID') + ] + def groupchat(self, room, nick, text, handler): - if not re.match(r'!topic(?:\W|\Z)', text): + if not re.match(r'!topic(?:\s|\Z)', text): return - - if not re.match(r'!topic\W', text): - handler.reply(handler.get_topic()) + + if re.match(r'!topic(?:\s+(?:s(?:how)?)?\s*)?\Z', text): + topic = handler.get_topic() + if topic is None or topic == '': + handler.reply('Es ist kein Topic gesetzt.') + return + topics = [s.strip() for s in topic.split('|')] + idtopics = zip(range(len(topics)), topics) + idtopicstrings = ["%i: %s" % t for t in idtopics] + handler.reply('Aktuelles Topic:\n\n' + '\n'.join(idtopicstrings)) return - - topic = re.sub(r'!topic\W+', '', text) - if topic == '': - return - + oldtopic = handler.get_topic() - if oldtopic != '' and oldtopic != None: - topic += ' | ' + oldtopic - - handler.set_topic(topic) + + if re.match(r'!topic\s+a(?:dd)?\s', text): + topic = re.sub(r'!topic\s+a(?:dd)?\s+', '', text) + if topic == '': + return + + if oldtopic != '' and oldtopic is not None: + topic += ' | ' + oldtopic + + handler.set_topic(topic) + return + + if re.match(r'!topic\s+d(?:el(?:ete)?)?\s', text): + try: + topicid = int(re.sub(r'!topic\s+d(?:el(?:ete)?)?\s+', '', text)) + except: + return + + topics = [s.strip() for s in oldtopic.split('|')] + if topicid < 0 or topicid >= len(topics): + return + + del topics[topicid] + + handler.set_topic(' | '.join(topics)) From 64efcb0fd8afe3bd208e509b9eca0f227be6edb2 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 22 Apr 2012 17:50:52 +0200 Subject: [PATCH 09/10] Print new topic on change --- modules/topic.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/modules/topic.py b/modules/topic.py index 7f4ca10..bdc5143 100644 --- a/modules/topic.py +++ b/modules/topic.py @@ -14,19 +14,22 @@ class Module(ModuleBase): ('!topic d[el[ete]] ', 'Entfernt das Topic mit der ID') ] + def _reply_topic(self, handler, prefix): + topic = handler.get_topic() + if topic is None or topic == '': + handler.reply('Es ist kein Topic gesetzt.') + return + topics = [s.strip() for s in topic.split('|')] + idtopics = zip(range(len(topics)), topics) + idtopicstrings = ["%i: %s" % t for t in idtopics] + handler.reply(prefix + '\n\n' + '\n'.join(idtopicstrings)) + def groupchat(self, room, nick, text, handler): if not re.match(r'!topic(?:\s|\Z)', text): return if re.match(r'!topic(?:\s+(?:s(?:how)?)?\s*)?\Z', text): - topic = handler.get_topic() - if topic is None or topic == '': - handler.reply('Es ist kein Topic gesetzt.') - return - topics = [s.strip() for s in topic.split('|')] - idtopics = zip(range(len(topics)), topics) - idtopicstrings = ["%i: %s" % t for t in idtopics] - handler.reply('Aktuelles Topic:\n\n' + '\n'.join(idtopicstrings)) + self._reply_topic(handler, 'Aktuelles Topic:') return oldtopic = handler.get_topic() @@ -40,6 +43,7 @@ class Module(ModuleBase): topic += ' | ' + oldtopic handler.set_topic(topic) + self._reply_topic(handler, 'Neues Topic:') return if re.match(r'!topic\s+d(?:el(?:ete)?)?\s', text): @@ -55,3 +59,4 @@ class Module(ModuleBase): del topics[topicid] handler.set_topic(' | '.join(topics)) + self._reply_topic(handler, 'Neues Topic:') From 7825748a268683a3afeef06b57a7f9b70e41c410 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 29 Dec 2012 02:21:47 +0100 Subject: [PATCH 10/10] Use psycopg2 PgSQL module --- modules/pgsql.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/pgsql.py b/modules/pgsql.py index 24cec76..a09a6de 100644 --- a/modules/pgsql.py +++ b/modules/pgsql.py @@ -1,5 +1,5 @@ from . import ModuleBase -from pyPgSQL import PgSQL +import psycopg2 class Module(ModuleBase): def __init__(self, manager): @@ -17,12 +17,12 @@ class Module(ModuleBase): except: pass - self.db = PgSQL.connect(host = self.conf['host'], user = self.conf['user'], password = self.conf['passwd'], database = self.conf['db'], client_encoding = 'utf8', unicode_results = 1) + self.db = psycopg2.connect(host = self.conf['host'], user = self.conf['user'], password = self.conf['passwd'], database = self.conf['db']) def cursor(self): try: return self.db.cursor() - except PgSQL.OperationalError: + except psycopg2.OperationalError: self._connect() return self.db.cursor()