jbvn0q
Last Updated: February 25, 2016
·
302
· danreynolds

Terminal Weather Updates

I wanted to see the current weather when I opened the terminal so I looked around and found a great API for returning weather data based on the lat/long.

Since it was returned in XML and I already had the Nokogiri gem installed, I fed the XML returned into it running the right command to get the basic things I wanted, namely temperature outside and current weather classification.

It turned out to be a longish one-liner I then stuck in my bash_profile and now I get all my weather updates easily and cleanly.

curl -s "http://api.openweathermap.org/data/2.5/weather?lat=43.4667&lon=-80.5167&units=metric&mode=xml&APPID=7c7eaeee706086a91f91215242f3b44a" | nokogiri -E xml -e 'puts "it is " + $_.xpath("//current //temperature").first.attributes["value"].value + " degrees in Waterloo, and the weather is " + $_.xpath("//weather").first.attributes["value"].value + "."'