Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

guillaume riflet http://webtopmania.blogspot.com

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Twitter bot weatherlisbon

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.
This one returns daily weather forecasts for Lisbon city based on the BBC weather forecast rss feed.

   1  
   2  #! /bin/sh
   3  
   4  #Goto here
   5  here=/home/guillaume/Personal
   6  cd $here
   7  
   8  #BBC Lisbon weather id
   9  id=0048
  10  
  11  #BBC weather RSS feed address
  12  feed="http://feeds.bbc.co.uk/weather/feeds/rss/5day/world/${id}.xml"
  13  
  14  #City
  15  city=lisbon
  16  
  17  #temporary file
  18  file="weather${city}"
  19  
  20  #Weather twitter bot
  21  twitbot=weatherlisbon:*******
  22  
  23  #Timestamp the log file
  24  echo .>> $file.log
  25  date >> $file.log
  26  
  27  #Read the RSS feed and filter it
  28  curl $feed | grep 'title' | tail -n 1 | perl -wlne'm/title>(.*)<\/title/i && print $1' | sed -e "s/&#xB0;//g" > $file.txt
  29  
  30  #Read the forecast into a weather variable
  31  read weather < $file.txt
  32  
  33  #Twit the weather variable away
  34  curl --basic --user $twitbot --data status="$weather" http://twitter.com/statuses/update.xml >> $file.log
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS