Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

weather.sh

By: BoredOOMM on Oct 17th, 2011  |  syntax: None  |  size: 0.85 KB  |  views: 307  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # !/usr/bin/bash
  2. METRIC=0 #Should be 0 or 1; 0 for F, 1 for C
  3. if [ -z $1 ]; then
  4.     echo "USAGE: weather.sh <locationcode>"
  5.     exit 0;
  6. fi
  7.  
  8. wget -q http://rss.accuweather.com/rss/liveweather_rss.asp\?metric\=${METRIC}\&locCode\=$1 -O - | awk \
  9. '/Currently:/ {CurWeather=$0}
  10. /[0-9] Forecast<\/title>/ {nr=NR+5}
  11. NR==nr    {postIndx[++x]=$0}
  12. # x>2    {exit}
  13. END{
  14.     split(CurWeather,tmp,"Currently: ")
  15.     split(tmp[2],tmp1,"<")
  16.     CurWeather=sprintf("%s",tmp1[1])
  17.     sub(":",",",CurWeather)
  18.     for(x in postIndx){
  19.     split(postIndx[x],tmp,";|&")
  20.     split(tmp[1],tmp,">")
  21.     split(tmp[2],statement," C ") # substitute C for F if metric differs
  22.     split(tmp[2],temp)
  23.     forecast[++y]=sprintf("%d-%dC %-15s",temp[5],temp[2],statement[3])
  24.     }
  25.     printf("WEATHER:\nNow: %s\nToday: %s\nTomorrow: %s",CurWeather,forecast[1],forecast[2])
  26. }'
  27.  
clone this paste RAW Paste Data