Geo Weather

xmlstarlet fo "http://www.google.com/ig/api?weather=$(curl -s api.hostip.info/get_html.php?ip=$(curl -s icanhazip.com)... SEE SAMPLE OUTPUT
This command will determine an individuals local weather, based on their I.P. address. I had to learn a lot about SED and a little about XMLStarlet in order to achieve this. This command is my original work and there is much room for improvement; I look forward to any constructive feedback.
Sample Output
xmlstarlet fo http://www.google.com/ig/api?weather=$(curl -s api.hostip.info/get_html.php?ip=$(curl -s icanhazip.com) | sed -e'1d;3d' -e's/C.*: \(.*\)/\1/' -e's/ /%20/g' -e"s/'/%27/g" -e"s/-/%2d/g") | sed -e's|<f.*_i.*>|Locale|' -e's|<ci.*=|Origin |' -e's|<c.*_d.*=|Date+Time |' -e's|<c.*_c.*>|Today|' -e's|<co.*=|Conditions |' -e's|<t.*_f.*=|Temperature (?F) |' -e's|<t.*_c.*=|Temperature (?C) |' -e's|"H.*: |Humidity "|' -e's|"W.*: |Wind "|' -e's|<.*=||' -e's|/>||' -e's|<.*>||' -e"s/&#39;/'/g" -e'1,3d;6,9d;11d;18d;20,49d'

 Locale
      Origin "St John's, NL"
      Date+Time "2010-02-11 05:25:15 +0000"
    
    Today
      Description "Cloudy"
      Temperature (F) "30"
      Temperature (C) "-1"
      Humidity "76%"
      Wind "W at 9 mph"

0
By: o0110o
2010-02-11 06:32:44

1 Alternatives + Submit Alt

  • Weather based on your location


    -4
    curl -s http://www.google.com/ig/api?weather=$(curl -s "http://api.hostip.info/get_html.php?ip=$(curl -s icanhazip.com)" | grep City | sed 's/City: \(.*\)/\1/' | sed 's/ /%20/g' | sed "s/'/%27/g") | sed 's|.*<temp_f data="\([^"]*\)"/>.*|\1\n|'
    matthewbauer · 2010-02-13 21:42:48 8

What Others Think

I hope you all have fun with this!
o0110o · 452 weeks and 5 days ago
hmm, am my the only one that cant get either of these to work at all. I am using bash in osx terminal and have installed xmlstarlet via homebrew. There seems to be a mismatched quote in the original command. All I get when running these is a > at the prompt. Any ideas.
anika200 · 452 weeks and 4 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: