Skip to content

Commit

Permalink
Remove unnecessary code and format
Browse files Browse the repository at this point in the history
Move f.open() with the rest of the file operations- it was driving me nuts.
Also, remove 'server' and 'channel' information. I likely already know what
server/channel they are in, and if not, can find the message easily enough
when getting back to my client.
  • Loading branch information
atoponce committed Sep 3, 2012
1 parent b7a8a24 commit 2dab3d3
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions email-0mq.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,27 @@
socket.connect('tcp://127.0.0.1:2428')

while True:
f = open('/var/log/0mq.log','a')
msg = socket.recv()
msg = re.sub('\n:', '\n', msg)
msg = re.sub('^---| !binary \|-\n','',msg)
y = yaml.load(msg)

f = open('/var/log/0mq.log','a')
f.write(msg)
f.close()

# Ignore client events that aren't PUBLIC
if not y['tags'][3]:
continue

server = base64.b64decode(y['server'])
channel = base64.b64decode(y['channel'])
nick = base64.b64decode(y['tags'][3])
nick = re.sub('^nick_','',nick)
message = base64.b64decode(y['message'])

# If sending messages to the channel while away, it shows up as
# "prefix_nick_white". This can change it to your nick.
if nick == 'prefix_nick_white':
nick = 'eightyeight'

# Change your email-to-sms address as provided by your mobile provider
fromaddr = 'weechat@irc.example.com'
toaddr = '1234567890@messaging.sprintpcs.com'
msg = MIMEText("{0}/{1}: <{2}> {3}".format(server, channel, nick, message))
msg = MIMEText("<{0}> {1}".format(nick, message))
msg['To'] = email.utils.formataddr(('eightyeight', toaddr))
msg['From'] = email.utils.formataddr(('WeeChat', fromaddr))

Expand Down

0 comments on commit 2dab3d3

Please sign in to comment.