Created
February 14, 2010 23:23
-
-
Save orblivion/304335 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import imaplib | |
import getpass | |
import re | |
import webbrowser | |
import sys | |
mail = imaplib.IMAP4_SSL('imap.gmail.com', 993) | |
pw = getpass.getpass() # get password | |
mail.login('example@gmail.com',pw) | |
# I think this is necessariy to refer to emails in the inbox. Doesn't seem to work without it. | |
status, count = mail.select ('INBOX') | |
dummy, [idsstr] = mail.search(None, "(SUBJECT \"is now following you on Twitter!\")"); | |
idslist = [int(x) for x in idsstr.split()] # turns the "### ### ###" we get into [###, ###, ###] | |
if idslist == []: | |
print "no new followers!" | |
sys.exit() | |
ok, msglist = mail.fetch(",".join(idsstr.split()), '(UID BODY[TEXT])') | |
# it seems that msglist is a list of [useless, msg1, useless, msg2...] | |
def justMsgs(msglist): | |
if msglist == []: return [] | |
return [msglist[0][1]] + justMsgs(msglist[2:]) | |
msgs = justMsgs(msglist) | |
webbrowser.open_new("https://mail.google.com/mail/?shva=1#search/%22is+now+following+you+on+twitter%22+label%3Ainbox") | |
for msg in msgs: | |
webbrowser.open_new_tab(re.findall("http://twitter.com/\w+", msg)[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment