Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilip H.F. "FiXato" Slagter <fixato@gmail.com>2012-06-11 23:02:28 +0200
committerFilip H.F. "FiXato" Slagter <fixato@gmail.com>2012-06-11 23:05:00 +0200
commitd1051e5304dd13767bb1b00bb6725d383ac17da8 (patch)
tree2700f8d822bd3fd6b79e1e352925d6f9eab850f0
parent82814fa304d4130005ff61563370bd15ce06b791 (diff)
Add support for timezone offsets on a per channel basis.
You can now create a file at CHANNEL_LOCATIONS_FILE that contains a list of channels and (pytz) timezone location names. All log files for specified channels from that point on will have their timestamps adjusted to the given timezone. If a channel is not specified in the config file, it will default to the timezone specified by DEFAULT_TIMEZONE (which defaults to UTC). I've started storing this info in a separate config file as I plan to move all the other settings into a config file as well so people don't need to edit the script (allowing the script to be re-used more easily).
-rwxr-xr-xlogbot.py27
1 files changed, 25 insertions, 2 deletions
diff --git a/logbot.py b/logbot.py
index 3e54ec8..4450926 100755
--- a/logbot.py
+++ b/logbot.py
@@ -38,6 +38,10 @@ import os
import ftplib
import sys
from time import strftime
+try:
+ from datetime import datetime
+ from pytz import timezone
+except: pass
try:
from hashlib import md5
@@ -83,6 +87,8 @@ FTP_FOLDER = ""
# The amount of messages to wait before uploading to the FTP server
FTP_WAIT = 25
+CHANNEL_LOCATIONS_FILE = os.path.expanduser("~/.logbot-channel_locations.conf")
+DEFAULT_TIMEZONE = 'UTC'
default_format = {
"help" : HELP_MESSAGE,
@@ -167,6 +173,7 @@ class Logbot(SingleServerIRCBot):
self.count = 0
self.nick_pass = nick_pass
+ self.load_channel_locations()
print "Logbot %s" % __version__
print "Connecting to %s:%i..." % (server, port)
print "Press Ctrl-C to quit"
@@ -265,8 +272,14 @@ class Logbot(SingleServerIRCBot):
append_line("%s/index.html" % LOG_FOLDER, '<a href="%s/index.html">%s</a>' % (channel.replace("#", "%23"), channel_title))
# Current log
- time = strftime("%H:%M:%S")
- date = strftime("%Y-%m-%d")
+ try:
+ localtime = datetime.now(timezone(self.channel_locations.get(channel,DEFAULT_TIMEZONE)))
+ time = localtime.strftime("%H:%M:%S")
+ date = localtime.strftime("%Y-%m-%d")
+ except:
+ time = strftime("%H:%M:%S")
+ date = strftime("%Y-%m-%d")
+
log_path = "%s/%s/%s.html" % (LOG_FOLDER, channel, date)
# Create the log date index if it doesnt exist
@@ -364,6 +377,16 @@ class Logbot(SingleServerIRCBot):
def on_topic(self, c, e):
self.write_event("topic", e)
+ # Loads the channel - timezone-location pairs from the CHANNEL_LOCATIONS_FILE
+ # Each line is expected to have the channelname and (pytz) TimeZone location separated by a space
+ # Example:
+ # #excid3 UTC
+ # #Netherlands Europe/Amsterdam
+ def load_channel_locations(self):
+ self.channel_locations = {}
+ if os.path.exists(CHANNEL_LOCATIONS_FILE):
+ f = open(CHANNEL_LOCATIONS_FILE, 'r')
+ self.channel_locations = dict([line.split() for line in f.readlines()])
def connect_ftp():
print "Using FTP %s..." % (FTP_SERVER)