@wearebasefm is a twitter bot which crawls @wearebase's Last.fm feed every minute and compares the latest track with what we have on record. If it's new, it's tweeted.
Base Creative Agency listens to a lot of music during the day, and I thought it would be fun to share our musical tastes.
- @wearebase uses iTunes to scrobble music with Last.fm.
- Every minute, the crontab kicks in and parses Last.fm's 'recent tracks' feed.
- The script then compares when the last track was played (if at all, it may well be the first time), and if this track has been played since, it's tweeted.
- The message is then inserted into the database, so in just under a minute's time, we can determine whether any new tracks have been played.
- tweepy - an python library for the Twitter API.
- MySQLdb - a python MySQL db API.
- feedparser - a python based RSS & Atom feed parser.
First of all, ensure your apt-get
list is up-to-date by performing a sudo apt-get update
.
Next, change the username in the Twadio arg to your Last.fm username, seen here:
twadio = Twadio(username='wearebase')
cd
into yoursrc
directory, such as~/src
.git clone git://github.com/joshthecoder/tweepy.git && cd tweepy
python setup.py install && sudo python setup.py install
sudo apt-get install python-mysqldb
mysql -uroot -p
and create our database.mysql -uroot -p DATABASE_NAME < sql/schema_20110318.sql
- Return to your
src
directory. svn checkout http://feedparser.googlecode.com/svn/trunk/ feedparser && cd feedparser
python setup.py build && sudo python setup.py install
crontab -e
- Paste the crontab line, you may need to change the path to the python file.
- Write and exit, if you are in Vim, use
:wq
. You can verify it's saved viacrontab -l
.