Commit 98c34052 authored by Svetlana Tkachenko's avatar Svetlana Tkachenko
Browse files

Start reusing cursors again (related to issue #19)

parent 10eb3585
# guppy Copyright (C) 2010-2011 guppy team members.
# guppy Copyright (C) 2010-2014 guppy team members.
#
# This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
# This is free software, and you are welcome to redistribute it
......@@ -71,21 +69,26 @@ class Seen(object):
nick = args[0].lower()
cursor = sqlite3.connect(self.db).cursor()
cursor.execute('SELECT * FROM seen WHERE nick = ? and network = ?', (nick, self.network))
info = self.cursor.fetchone()
if info:
# ('gry', '2013-01-31 14:50:02.419198', 'gnu', '#guppy', '-seen gry')
t = time.time() - float(info[1])
info = cursor.fetchone() ###N# db is opened locally, cannot be accessed with 'self'
#### info = self.cursor.fetchone()
minutes = int(t // 60)
seconds = int(t % 60)
hours = int(t // 3600)
days = int(t // 86400)
if info:
t = int(time.time() - float(info[1])) ###N# the code I commented out comes up with
minutes, seconds = divmod(t, 60) ###N# (115 days, 2778 hours, 166693 minutes and 2 seconds ago)
hours, minutes = divmod(minutes, 60) ###N# for example because it shows t in d,h,m but doesn't do modulo.
days, hours = divmod(hours, 24) ###N# divmod is even better than % in this case.
#### t = time.time() - float(info[1])
#### minutes = int(t // 60)
#### seconds = int(t % 60)
#### hours = int(t // 3600)
#### days = int(t // 86400)
time_msg = "{0} days, {1} hours, {2} minutes and {3} seconds ago".format(days, hours, minutes, seconds)
if info[3][0] == '#':
self.server.doMessage(channel, "%s said '%s' in %s (%s)" % (info[0], info[4], info[3], time_msg))
self.server.doMessage(channel, "%s said '%s' in %s (%s)" % (info[0], info[4][:200], info[3], time_msg)) ###N# added [:200] to break long lines.
else:
self.server.doMessage(channel, "%s talked to me %s" % (info[0], time_msg))
# print(info); # give the info
else:
self.server.doMessage(channel, "I haven't seen " + nick + ", sorry.")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment