Twitter autofollow and DM using python-twitter, imaplib and gmail
Apr.01, 2009 in
Python
The script will:
- connect via imap to gmail
- select the imap directory TwitterFollow (you should filter twitter follow notifications and label them with TwitterFollow)
- fetch the headers of all unread mails
- retrieve the twitter user screen_name that is following you from the headers
- attempt to create a friendship aka autofollow. If an error occurs is probably due to the fact you previously followed the user
- Send a direct message to thank for the following
- Flag the message as read so it won’t be fetched next time script runs
You could also check Twitter autofollow and direct message using python mechanize libgmail which is basically achieving the same goal but operate differently using reverse engineering on gmail web site.


April 25th, 2009 at 10:22 pm
Hey,
“if friendship_created is True:” isn’t really pythonic
Better write: “if friendship_created:”
But thanks for that inspiration!
Cheers.
April 25th, 2009 at 10:28 pm
the whole script isn’t quite pythonic and lacks introspection, so I tried to make it readable also for those not knowing python, just for documentation. Many lines could have been condensed into one, etc.
September 12th, 2009 at 6:19 pm
There are some minor fixes that I see are already implemented in the version hosted by Snipt (http://snipt.net/raduboncea/autofollow-and-dm-twitter-using-imap-on-gmail) but not over here. Mainly – there should be a slash before the w in the regular expression, and a slash before the Seen in order to mark a message as read.
Thought that future readers should now about it…