Permalink
Browse files

Fix day change bug

When the day changes, WeeChat prints the following message:
    Day changed to Thu, 30 Aug 2012
This causes the 'tags' list in the dictionary to be empty. Because we're
not interested in getting notified of day changes, the loop should pass.

Further, rather than using yaml.items() to get at the values, yaml.values()
is uesed to get to the data. Also make stylistic changes to the code, and
add comments.
  • Loading branch information...
1 parent ca5534c commit 0ec0ec80bed96e54ca355e11a101d0305f11bf11 @atoponce committed Aug 30, 2012
Showing with 12 additions and 10 deletions.
  1. +12 −10 email-0mq.py
View
22 email-0mq.py
@@ -4,7 +4,6 @@
import email.utils
import re
import smtplib
-import time
import yaml
import zmq
from email.mime.text import MIMEText
@@ -24,21 +23,24 @@
f.write(msg)
f.close()
- nick = base64.b64decode(y.items()[0][1][3])
- server = base64.b64decode(y.items()[2][1])
- epoch = base64.b64decode(y.items()[3][1])
- message = base64.b64decode(y.items()[5][1])
- channel = base64.b64decode(y.items()[7][1])
+ # When day changes, the 'tags' value list will be empty. Ignore.
+ if y.values()[0] == []:
+ pass
+
+ # Format is:
+ # ['tags', 'away', 'server', 'date', 'highlight', 'message', 'type', 'channel']
+ # where 'tags' is another list of items.
+ server = base64.b64decode(y.values()[2])
+ channel = base64.b64decode(y.values()[7])
+ nick = base64.b64decode(y.values()[0][3])
+ nick = re.sub('^nick_','',nick)
+ message = base64.b64decode(y.values()[5])
# If sending messages to the channel while away, it shows up as
# "prefix_nick_white". This can change it to your nick.
- nick = re.sub('^nick_','',nick)
if nick == 'prefix_nick_white':
nick = 'eightyeight'
- mt = time.localtime(int(epoch))
- d = time.strftime('%H:%M:%S', mt)
-
# Change your email-to-sms address as provided by your mobile provider
fromaddr = 'weechat@irc.example.com'
toaddr = '1234567890@messaging.sprintpcs.com'

0 comments on commit 0ec0ec8

Please sign in to comment.