summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesusaves <cpntb1@ymail.com>2020-11-07 22:53:07 -0300
committerJesusaves <cpntb1@ymail.com>2020-11-07 22:53:07 -0300
commitfb0f48bac0a17d5349dac63687eed724c440cbe9 (patch)
treea47fa7f76e802fcdc7f53ab8897133356c7b9a1f
parent8a8751a17e8b6b85f7c899388573124b0ee529b5 (diff)
downloadmanamarket-fb0f48bac0a17d5349dac63687eed724c440cbe9.tar.gz
manamarket-fb0f48bac0a17d5349dac63687eed724c440cbe9.tar.bz2
manamarket-fb0f48bac0a17d5349dac63687eed724c440cbe9.tar.xz
manamarket-fb0f48bac0a17d5349dac63687eed724c440cbe9.zip
Do not trust databases; SQL errors can happen and I prefer to not have the bot
crashing down when they happen
-rw-r--r--onlineusers.py46
1 files changed, 29 insertions, 17 deletions
diff --git a/onlineusers.py b/onlineusers.py
index 55da670..2bfdc25 100644
--- a/onlineusers.py
+++ b/onlineusers.py
@@ -140,9 +140,14 @@ class SqliteDbManager:
db.commit()
def get_lastseen_info(self, nick):
- self.cur.execute('select DATE_ from LastSeen where NICK=?',(nick,))
- self.db.commit() # NOTE: do I need it?
- row = self.cur.fetchone()
+ try:
+ self.cur.execute('select DATE_ from LastSeen where NICK=?',(nick,))
+ self.db.commit() # NOTE: do I need it?
+ row = self.cur.fetchone()
+ except sqlite3.Error, e:
+ print ("sqlite3 error: %s" % e.message)
+ row = ["although I do not remember when."]
+
if row:
return ('%s was seen %s' % (nick, row[0])).encode('utf-8')
else:
@@ -161,22 +166,29 @@ class SqliteDbManager:
db.close()
def send_mail(self, from_, to_, message):
- self.cur.execute('replace into MailBox(FROM_,TO_,MESSAGE) values(?,?,?)',
- (from_,to_,message))
- self.db.commit()
+ try:
+ self.cur.execute('replace into MailBox(FROM_,TO_,MESSAGE) values(?,?,?)',
+ (from_,to_,message))
+ self.db.commit()
+ except sqlite3.Error, e:
+ print ("sqlite3 error: %s" % e.message)
def get_unread_mails(self, nick, db=None, cur=None):
- if db is None:
- db = self.db
- if cur is None:
- cur = self.cur
- cur.execute('select FROM_,MESSAGE from MailBox where TO_=?',
- (nick,))
- db.commit()
- mails = cur.fetchall()
- cur.execute('delete from MailBox where TO_=?',
- (nick,))
- db.commit()
+ try:
+ if db is None:
+ db = self.db
+ if cur is None:
+ cur = self.cur
+ cur.execute('select FROM_,MESSAGE from MailBox where TO_=?',
+ (nick,))
+ db.commit()
+ mails = cur.fetchall()
+ cur.execute('delete from MailBox where TO_=?',
+ (nick,))
+ db.commit()
+ except sqlite3.Error, e:
+ print ("sqlite3 error: %s" % e.message)
+ mails = []
return mails
def __mailbox_threadfunc(self):