Advertisement
BoredOOMM

weather.sh

Oct 17th, 2011
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  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.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement