Twitter / weatherlisbon

By 11 de enero de 2008 Linux No Comments

twitter.jpgDocumentándome sobre esta red pública, me ha gustadoespecialmente este script que adjunto:

Twitter is a fairly recent social short messaging system. It allows to send short messages to a network of friends via instant messaging (IM) services, sms-es, and the twitter web-site itself.
Twitter begs for folks to do inventive mashups like twittervision.

 

Thus I wrote a small script in bash that checks for the weather in Lisbon from a BBC weather forecast feed and sends it to twitter. I called this script a twitter-bot-agent. The agent's name is weatherlisbon. If you're registered in Twitter then you can add "him" to your friends and every morning at 6am Lisbon time you'll be twitted with the lisbon weather for the day.
Comment: In fact I was scooped, and other folks already had this idea. But as far as I can see this is the only bot tweeting the daily weather for lisbon. Go check out more bots at http://www.retweet.com/.

You can check out the script explained in this wiki or here below:


#! /bin/sh
#BBC Lisbon weather id
id=0048


#BBC weather RSS feed address
feed="http://feeds.bbc.co.uk/weather/feeds/rss/5day/world/${id}.xml"

#City
city=lisbon

#temporary file
tmpfile="weather${city}.txt"

#Weather twitter bot
twitbot=username:******


#Read the RSS feed and filter it
#Careful with this long one-liner. Blogger may have corrupted it. Thanks to LordRich for pointing that out.
curl $feed 2>&1 | grep 'title' | tail -n 1 | perl -wlne'm/title>(.*)<\/title/i && print $1' | sed -e "s/°//g" > $tmpfile

#Read the forecast into a weather variable
read weather < $tmpfile

#Twit the weather variable away
curl --basic --user $twitbot --data status="$weather" http://twitter.com/statuses/update.xml

Vía: http://webtopmania.blogspot.com/2007/06/twitter-weatherlisbon.html

Leave a Reply

Your email address will not be published.