Search:

eriksmartt.com/blog

 

Topics:

  • arduino (3)
  • art (2)
  • austin (39)
  • automotive (15)
  • blogging (25)
  • books (14)
  • business (5)
  • code (15)
  • design (10)
  • diy (3)
  • django (9)
  • experience (17)
  • family (2)
  • film (4)
  • food (1)
  • for:optaros (2)
  • gadgets (11)
  • games (11)
  • garden (3)
  • green (5)
  • hack (13)
  • hardware (11)
  • hci (9)
  • life (13)
  • lifehack (11)
  • links (71)
  • linux (8)
  • living (3)
  • make (3)
  • media (7)
  • mobile (98)
  • music (2)
  • news (17)
  • osx (29)
  • outdoors (4)
  • privacy (2)
  • product-management (1)
  • python (75)
  • quote (3)
  • security (10)
  • society (21)
  • software (38)
  • spam (2)
  • syndication (5)
  • technical (31)
  • technolust (5)
  • transportation (12)
  • travel (25)
  • ubuntu (7)
  • web (67)
  •  

    A simple shell script for grabbing the current temperature from the command line

    Filed under: code, lifehack — November 16, 2007

    In case someone else needs it, here’s a simple shell script I use for grabbing the current weather conditions by U.S. zipcode using the Yahoo APIs:

    function weather {
      zipcode=$1
      if [ -n "$zipcode" ]; then
        lynx -dump "http://weather.yahooapis.com/forecastrss?p=$zipcode" | grep -i condition | awk -F' ' '{print $4 $5 $6}' | awk -F'< ' '{print $1}' | sed 's/,/ /'
      else
        echo 'USAGE: weather <zipcode>'
      fi
    }
    

    The script uses lynx to grab the Yahoo RSS feed, piping the output to grep, which extracts the line containing the word ‘condition’. awk then pulls out some specific fields (delimited by spaces, then later by ‘<’), and sed converts the commas to spaces for prettier output. Obviously, the whole thing is fairly fragile, and changes to the RSS format (which happened maybe a month back) break the code. Checking the weather in Austin with the command: `weather 78701`, currently outputs: “Fair 67F”.



    Leave a Reply


     

    A few books I'm reading now:

    A few books I'd recommend: