A little project that randomly tweets out fragments of lyrics from They Might Be Giants songs.
Minimum Wage! HYAH!
— tmbotg (@tmbotg) January 10, 2014
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
If you'd like to use this as the basis for a twitterbot of your own, please check out the related Nanobot framework that's extracted from this project and should make your work easier.
- Obviously, thanks to They Might Be Giants, both for writing this stuff in the first place, and (as importantly for this project) not being all cease-and-desisty to this kind of fan project. This project is not officially affiliated with the band.
- All the editors/contributors to 'TMBW: The They Might Be Giants Knowledge Base' (http://www.tmbw.net) for maintaining full lyrics in a format that was relatively easy for me to extract.
Python modules
- Requests is the only reasonable way to deal with HTTP in Python.
- Similarly, Beautiful Soup needs to be your first choice when you need to parse HTML, even the most horrible HTML
- Twython for handling the Twitter API. Clean and sensible.
Utility using Requests and BeautifulSoup to scrape the lyrics database that's at http://tmbw.net, storing the lyrics as one file per track.
Twitter bot app (written using Twython) that assumes it will be called once a minute by a cron job. Approximately once an hour (depending on configuration data), it should generate a new tweet.
I've also written a post on my work blog about this code that may be of interest:
http://www.artandlogic.com/blog/2014/01/this-might-be-a-twitterbot/
TODO:
- occasionally also use tweet contents to perform google image searches; include links in the tweet.
- add logging
- Add a mode that generates (daily?) stats (#posts, #followers, #favs, #retweets)
- wrap the update_status call in a try block so we can catch (and log) TwythonError exceptions (e.g. on a duplicate status update)
- add the ability to process mentions that contain a '?' by replying to that user with a chunk of lyrics.
- Favorite any post that mentions us.
- Track the time of the most recent tweet & refuse to twwet again for some period of time after that (rate-limit to not feel spammy. Max once an hour? )