Commits

Miki Tebeka committed 0d50a60

--timezone

Comments (0)

Files changed (7)

 dist
 build
 logbot.egg-info
+venv
-2013-03-27 version 0.1.0
+2013-11-27 version 0.2.0
+    * --timezone
+
+2013-09-27 version 0.1.0
     * Initial release
 
 
 clean:
 	rm -rf build dist logbot.egg-info/
-	find . -name '*.py[co]' -exec rm -v {} \;
+	find tests -name '*.py[co]' -exec rm -v {} \;
+	find logbot -name '*.py[co]' -exec rm -v {} \;
 
 github:
 	hg bookmark -r default master

logbot/__init__.py

-__version__ = '0.1.0'
+__version__ = '0.2.0'

logbot/__main__.py

 from logbot.common import create_cfg_dirs, run_thread, register_listener
 from logbot import log, httpd, bot, search, __version__
 
+from pytz import timezone, UnknownTimeZoneError
+
 from getpass import getuser, getpass
 
 
     parser.add_argument('room', help='room to log')  # FIXME: Rooms
     parser.add_argument('--version', action='version',
                         version='logbot {}'.format(__version__))
+    parser.add_argument('--timezone', help='time zone', default=None)
+
     args = parser.parse_args(argv[1:])
 
+    if args.timezone:
+        try:
+            tz = timezone(args.timezone)
+        except UnknownTimeZoneError:
+            raise SystemExit(
+                'error: unknown timezone - {}'.format(args.timezone))
+    else:
+        tz = None
+
     create_cfg_dirs()
 
     user = args.user or getuser()
     register_listener(search.index)
 
     run_thread(httpd.run)
-    bot.run(args.host, args.port, user, passwd, args.room, args.use_tls)
+    bot.run(args.host, args.port, user, passwd, args.room, args.use_tls, tz)
 
 
 if __name__ == '__main__':
 
 
 class LogBot(ClientXMPP):
-    def __init__(self, jid, password, room, nick):
+    def __init__(self, jid, password, room, nick, tz=None):
         super(LogBot, self).__init__(jid, password)
         self.room = room
         self.nick = nick
+        self.tz = tz
 
         self.add_event_handler("session_start", self.session_start)
         self.add_event_handler("groupchat_message", self.publish)
         msg = Message(
             user=self.xmpp_user(xmpp_msg),
             content=xmpp_msg['body'],
-            time=datetime.now(),
+            time=datetime.now(tz=self.tz),
         )
         publish(msg)
 
 
-def run(host, port, user, passwd, rooms, use_tls=True, nick='logbot'):
-    xmpp = LogBot(user, passwd, rooms, nick)
+def run(host, port, user, passwd, rooms, use_tls=True, nick='logbot', tz=None):
+    xmpp = LogBot(user, passwd, rooms, nick, tz)
 
     signal(SIGINT, lambda signum, frame: xmpp.disconnect())
 
+flask
+pytz
+sleekxmpp 
 whoosh
-sleekxmpp 
-flask