From 5289f6bc7573ec9f646db1fd7cfda9241aaebd1c Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Tue, 26 Aug 2003 11:15:15 +0000 Subject: [PATCH] Renamed conf.timestampFormat to conf.logTimestampFormat and added conf.humanTimestampFormat. --- plugins/ChannelLogger.py | 2 +- plugins/Factoids.py | 2 +- plugins/Quotes.py | 6 ++++-- plugins/Relay.py | 3 ++- plugins/URLSnarfer.py | 14 ++++++++++---- src/asyncoreDrivers.py | 2 +- src/conf.py | 16 ++++++++++++---- src/irclib.py | 4 ++-- src/world.py | 2 +- 9 files changed, 34 insertions(+), 17 deletions(-) diff --git a/plugins/ChannelLogger.py b/plugins/ChannelLogger.py index 056d75ad5..e864701a5 100644 --- a/plugins/ChannelLogger.py +++ b/plugins/ChannelLogger.py @@ -81,7 +81,7 @@ class ChannelLogger(irclib.IrcCallback): return StringIO() def timestamp(self, log): - log.write(time.strftime(conf.timestampFormat)) + log.write(time.strftime(conf.logTimestampFormat)) log.write(' ') def doPrivmsg(self, irc, msg): diff --git a/plugins/Factoids.py b/plugins/Factoids.py index 9f11f5f17..c0c0a890c 100644 --- a/plugins/Factoids.py +++ b/plugins/Factoids.py @@ -218,7 +218,7 @@ class Factoids(ChannelDBHandler, callbacks.Privmsg): L = [] counter = 0 for (added_by, added_at) in factoids: - added_at = time.strftime(conf.timestampFormat, + added_at = time.strftime(conf.humanTimestampFormat, time.localtime(int(added_at))) L.append('#%s was added by %s at %s' % (counter,added_by,added_at)) counter += 1 diff --git a/plugins/Quotes.py b/plugins/Quotes.py index a6c550797..ceea49c2a 100644 --- a/plugins/Quotes.py +++ b/plugins/Quotes.py @@ -158,10 +158,12 @@ class Quotes(ChannelDBHandler, callbacks.Privmsg): db = self.getDb(channel) cursor = db.cursor() cursor.execute("""SELECT * FROM quotes WHERE id=%s""", id) - row = cursor.fetchone() + (id, added_by, added_at, quote) = cursor.fetchone() if row: + timestamp = time.strftime(conf.humanTimestampFormat, + time.localtime(int(added_at))) irc.reply(msg, 'Quote %r added by %s at %s.' % \ - (row.quote, row.added_by, time.strftime(conf.timestampFormat))) + (quote, added_by, timestamp) return else: irc.reply(msg, 'There isn\'t a quote with that id.') diff --git a/plugins/Relay.py b/plugins/Relay.py index 6ad2c3537..af9a67458 100644 --- a/plugins/Relay.py +++ b/plugins/Relay.py @@ -337,7 +337,8 @@ class Relay(callbacks.Privmsg): channels = utils.commaAndify(channels) if '317' in d: idle = utils.timeElapsed(d['317'].args[2]) - signon = time.ctime(float(d['317'].args[3])) + signon = time.strftime(conf.humanTimestampFormat, + time.localtime(float(d['317'].args[3]))) else: idle = '' signon = '' diff --git a/plugins/URLSnarfer.py b/plugins/URLSnarfer.py index 253177459..aee25477f 100644 --- a/plugins/URLSnarfer.py +++ b/plugins/URLSnarfer.py @@ -122,7 +122,8 @@ class URLSnarfer(callbacks.Privmsg, ChannelDBHandler): cursor = db.cursor() cursor.execute("""SELECT * FROM urls ORDER BY random() LIMIT 1""") (id, url, added, addedBy, _, _, _, _, _, _) = cursor.fetchone() - when = time.ctime(int(added)) + when = time.strftime(conf.humanTimestampFormat, + time.localtime(int(added))) s = '%s: <%s> (added by %s on %s)' % (id, url, addedBy, when) irc.reply(msg, s) @@ -180,13 +181,18 @@ class URLSnarfer(callbacks.Privmsg, ChannelDBHandler): db = self.getDb(channel) cursor = db.cursor() criterion = ' AND '.join(criteria) - sql = 'SELECT url FROM urls WHERE %s ORDER BY id DESC' % criterion + sql = """SELECT url, added, added_by + FROM urls + WHERE %s ORDER BY id DESC""" % criterion cursor.execute(sql, *formats) if cursor.rowcount == 0: irc.reply(msg, 'No URLs matched that criteria.') else: - (url,) = cursor.fetchone() - irc.reply(msg, url) + (url, added, added_by) = cursor.fetchone() + timestamp = time.strftime('%I:%M %p, %B %d, %Y', + time.localtime(int(added))) + s = '<%s>, added by %s at %s.' % (url, added_by, timestamp) + irc.reply(msg, s) Class = URLSnarfer diff --git a/src/asyncoreDrivers.py b/src/asyncoreDrivers.py index 420a19087..ce82e84c8 100644 --- a/src/asyncoreDrivers.py +++ b/src/asyncoreDrivers.py @@ -75,7 +75,7 @@ class AsyncoreDriver(asynchat.async_chat, object): def scheduleReconnect(self): when = time.time() + 60 - whenS = time.strftime(conf.timestampFormat, time.localtime(when)) + whenS = time.strftime(conf.logTimestampFormat, time.localtime(when)) debug.msg('Scheduling reconnect at %s' % whenS, 'normal') def makeNewDriver(): self.irc.reset() diff --git a/src/conf.py b/src/conf.py index 7e634d5aa..b91ccddc8 100644 --- a/src/conf.py +++ b/src/conf.py @@ -57,11 +57,19 @@ ignoresfile = os.path.join(confDir, 'ignores.conf') rawlogfile = os.path.join(logDir, 'raw.log') ### -# timestampFormat: A format string defining how timestamps should be. Check -# the Python library reference for the "time" module to see -# what the various format specifiers mean. +# logTimestampFormat: A format string defining how timestamps should be. Check +# the Python library reference for the "time" module to see +# what the various format specifiers mean. ### -timestampFormat = '[%d-%b-%Y %H:%M:%S]' +logTimestampFormat = '[%d-%b-%Y %H:%M:%S]' + +### +# humanTimestampFormat: A format string defining how timestamps should be +# formatted for human consumption. Check the Python +# library reference for the "time" module to see what the +# various format specifiers mean. +### +humanTimestampFormat = '%I:%M %p, %B %d, %Y' ### # throttleTime: A floating point number of seconds to throttle queued messages. diff --git a/src/irclib.py b/src/irclib.py index ea5acf259..b6a40535b 100644 --- a/src/irclib.py +++ b/src/irclib.py @@ -423,7 +423,7 @@ class Irc(object): debug.msg(s) return None self.state.addMsg(self,ircmsgs.IrcMsg(msg=msg, prefix=self.prefix)) - s = '%s %s' % (time.strftime(conf.timestampFormat), msg) + s = '%s %s' % (time.strftime(conf.logTimestampFormat), msg) debug.msg(s, 'low') if msg.command == 'NICK': # We don't want a race condition where the server's NICK @@ -438,7 +438,7 @@ class Irc(object): return None def feedMsg(self, msg): - debug.msg('%s %s' % (time.strftime(conf.timestampFormat), msg), 'low') + debug.msg('%s %s'%(time.strftime(conf.logTimestampFormat), msg),'low') # Yeah, so this is odd. Some networks (oftc) seem to give us certain # messages with our nick instead of our prefix. We'll fix that here. if msg.prefix == self.nick: diff --git a/src/world.py b/src/world.py index 4cfba0d87..247b10f69 100644 --- a/src/world.py +++ b/src/world.py @@ -88,7 +88,7 @@ def upkeep(): # Function to be run on occasion to do upkeep stuff. debug.msg('Uncollectable garbage: %s' % gc.garbage, 'normal') if 'noflush' not in tempvars: flush() - msg = '%s upkeep ran.' % time.strftime(conf.timestampFormat) + msg = '%s upkeep ran.' % time.strftime(conf.logTimestampFormat) debug.msg(msg, 'verbose') '''