Twitter Support on all my sites plus LastFM2Twitter

In a strange kind of coding frenzy I installed on all my sites Twitter support. New articles can now automagically be announced on Twitter – with the users own account.

The idea came when I could not immediately sleep yesterday night. I just came back from Bremen where we painted my new flat. Yes, the move is imminent. A few days ago, I was asked to include a tweet-feed on the Julis web page I administer. I never cared much about Twitter so far. Though it seems it can drive a lot of traffic to your site as I was about to witness.

So, what the heck. I opened an account with Twitter and installed the above mentioned module. This was not the end, however. As I already said, I was in a strange kind of coding frenzy. Recently I installed songbird, before that I used Amarok and Audacious. And I am still using Squeezecenter for my Squeezeboxes… I did not like the new version of Amarok, Audacious is a bit to simplistic and had problems with submitting tracks to last.fm. Songbird seems to be fine, though. There are a lot of (useful ?) plugins. Of course it can submit tracks to last.fm and it even has a twitter plugin. Yet, this plugin submits every single track that is started, even when I skip it after a few seconds for whatever reasons. I don’t like the skipped songs to appear anywhere. I did not listen to them. The end of the story is I wrote a quick’n’dirty shell script that pulls my last.fm-recently-listened-to feed from the web, parses it and posts the tracks not already posted to Twitter to Twitter. All the necessary ingredients were rsstool to pull the feed from last.fm and bti a cli for posting tweets to twitter. There is still a lot of room for improvements but for now the script works as designed.

#! /bin/bash  
read last < /var/tmp/date.lastfm  
new=$(rsstool --since="$last" --sdesc --shtml2 http://ws.audioscrobbler.com/1.0/user/luweewu/recenttracks.rss |recode u8 |grep pubDate|head -n 1 |sed -e s/""// |sed -e s/"<\/pubDate>"//)  

for tracks in $(rsstool --since="$last" --sdesc --shtml2 --csv http://ws.audioscrobbler.com/1.0/user/luweewu/recenttracks.rss |recode u8 |grep luweewu | cut -d ',' -f 4|sed -e y/" "/_/)
do
 echo "listened to ${tracks//_/ } (http://last.fm/user/luweewu)" | bti --account luweewu --password XXXXXXXXX  
done;  
echo $new > /var/tmp/date.lastfm ;  
comments powered by Disqus