<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: redirecting code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 25 Jul 2008 02:20:52 GMT</pubDate>
    <description>DZone Snippets: redirecting code</description>
    <item>
      <title>Twitter bot weatherlisbon</title>
      <link>http://snippets.dzone.com/posts/show/4159</link>
      <description>This little bash script shows how to use curl, grep, tail, sed and perl one-liners in order to compose a bleeding-edge twitter bot.&lt;br /&gt;This one returns daily weather forecasts for Lisbon city based on the BBC weather forecast rss feed.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#! /bin/sh&lt;br /&gt;&lt;br /&gt;#Goto here&lt;br /&gt;here=/home/guillaume/Personal&lt;br /&gt;cd $here&lt;br /&gt;&lt;br /&gt;#BBC Lisbon weather id&lt;br /&gt;id=0048&lt;br /&gt;&lt;br /&gt;#BBC weather RSS feed address&lt;br /&gt;feed="http://feeds.bbc.co.uk/weather/feeds/rss/5day/world/${id}.xml"&lt;br /&gt;&lt;br /&gt;#City&lt;br /&gt;city=lisbon&lt;br /&gt;&lt;br /&gt;#temporary file&lt;br /&gt;file="weather${city}"&lt;br /&gt;&lt;br /&gt;#Weather twitter bot&lt;br /&gt;twitbot=weatherlisbon:*******&lt;br /&gt;&lt;br /&gt;#Timestamp the log file&lt;br /&gt;echo .&gt;&gt; $file.log&lt;br /&gt;date &gt;&gt; $file.log&lt;br /&gt;&lt;br /&gt;#Read the RSS feed and filter it&lt;br /&gt;curl $feed | grep 'title' | tail -n 1 | perl -wlne'm/title&gt;(.*)&lt;\/title/i &amp;&amp; print $1' | sed -e "s/&amp;#xB0;//g" &gt; $file.txt&lt;br /&gt;&lt;br /&gt;#Read the forecast into a weather variable&lt;br /&gt;read weather &lt; $file.txt&lt;br /&gt;&lt;br /&gt;#Twit the weather variable away&lt;br /&gt;curl --basic --user $twitbot --data status="$weather" http://twitter.com/statuses/update.xml &gt;&gt; $file.log&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 18 Jun 2007 21:37:40 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4159</guid>
      <author>griflet (guillaume riflet)</author>
    </item>
  </channel>
</rss>
