I’m leaving in minutes and going to London, for a couple of meetings and tomorrow’s PHP meetup.
So, I do not have much time, but I would like to take a look to forecasts in London.
I could browse to some websites, sure..but I’m a nerd and if something doesn’t involve coding it’s not fun and, moreover, Mashape has a beatutiful Weather API! :)
So:
- go to that API url http://www.mashape.com/component/Weather
- download PHP client library (or ruby, or python, or java, or objective-c or use it in json.. as you prefer.. I’m going to a PHP meetup, so I will use PHP!)
- unzip it in a directory of your choice
- enter the path where you unzipped it (you will see a Weather.php)
- open your favourite text editor
- this is the code I’ve written:
<?php
include “Weather.php”;
$w = new Weather( your-mashape-api-key );
$result = $w->getForecasts(“london”)->result;
foreach($result as $day) {
print $day->day_of_week.“: ”.$day->condition.“\n”;
}
?>
Obviously, you have to put your Mashape API Key.. you will find it in the “account settings” section.
I’ve saved this file as client.php.. so I’m ready:
michele@erakis:~/Downloads/mashape-Weather-v1$ php client.php
Wed: Chance of Rain
Thu: Chance of Rain
Fri: Clear
Sat: Chance of Rain
Sh*t.. where is my umbrella?