Advertisement
ichase

weatherscript

Oct 21st, 2011
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #!/bin/sh
  2. #AccuWeather (r) RSS weather tool for conky
  3. #
  4. #USAGE: weather.sh <locationcode>
  5. #
  6. #(c) Michael Seiler 2007
  7.  
  8. METRIC=0 #Should be 0 or 1; 0 for F, 1 for C
  9.  
  10. if [ -z $1 ]; then
  11. echo "USAGE: weather.sh 23454"
  12. exit 0;
  13. fi
  14.  
  15. wget -q http://rss.accuweather.com/rss/liveweather_rss.asp\?metric\=${METRIC}\&locCode\=$1 -O - | awk \
  16. '/Currently:/ {CurWeather=$0}
  17. /[0-9] Forecast<\/title>/ {nr=NR+5}
  18. NR==nr {postIndx[++x]=$0}
  19. # x>2 {exit}
  20. END{
  21. split(CurWeather,tmp,"Currently: ")
  22. split(tmp [2],tmp1,"<")
  23. CurWeather=sprintf("%s",tmp1 [1])
  24. sub(":",","CurWeather)
  25. for(x in postIndx){
  26. split(postIndx[x],tmp,";|&")
  27. split(tmp[1],tmp,">")
  28. split(tmp[2],statement, " F ") # substitute C for F if metric differs
  29. split(tmp[2],temp)
  30. forecast[++y]=sprintf("%d-%dF %-15s",temp[5],temp[2],statement[3])
  31. }
  32. printf("Now: %s\nToday: %s\nTomorrow: %s",CurWeather,forecast[1],forecast[2])
  33. }'
  34. curl -s http://rss.accuweather.com/rss/liveweather_rss.asp\?metric\=%{METRIC}\&locCode\=$1 | perl -ne 'if (/Currently/) {chomp;/\<title\>Currently: (.*)?\<\/title\>/; print "$1"; }'
  35.  
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement