gbajfa
Last Updated: February 25, 2016
·
2.485K
· donutdan4114
Drupal logo 1

Getting weather via the command line

After reading this Pro Tip: http://coderwall.com/p/uhj-2a I decided to make my own version in a way that I know how... PHP.

For this to work, you need to have PHP, and it needs to be part of your system PATH. If it isn't, just modify the php part of the script to be the path to your PHP executable.

Put this function into your .bashrc file:

weather(){

 local zip=$1
 php -r '$xml = simplexml_load_file("http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query='${zip}'"); foreach($xml->txt_forecast->forecastday as $weather){ echo "{$weather->title}: "; echo $weather->fcttext; echo PHP_EOL . PHP_EOL;}' 

}

Now in console, just type:

$> weather ZIP_CODE

You'll get the forcast for the next few days.

Say Thanks
Respond
Filed Under