Changed log backend to PostgreSQL
This commit is contained in:
parent
aba29f23e6
commit
a52e07d904
2 changed files with 43 additions and 9 deletions
|
@ -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()
|
||||
|
|
30
modules/pgsql.py
Normal file
30
modules/pgsql.py
Normal file
|
@ -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()
|
Reference in a new issue