]> git.mxchange.org Git - friendica-addons.git/blob - curweather/vendor/cmfcmf/openweathermap-php-api/Examples/WeatherForecast.php
added composer.json and needed libs
[friendica-addons.git] / curweather / vendor / cmfcmf / openweathermap-php-api / Examples / WeatherForecast.php
1 <?php
2 /**
3  * OpenWeatherMap-PHP-API — A php api to parse weather data from http://www.OpenWeatherMap.org .
4  *
5  * @license MIT
6  *
7  * Please see the LICENSE file distributed with this source code for further
8  * information regarding copyright and licensing.
9  *
10  * Please visit the following links to read about the usage policies and the license of
11  * OpenWeatherMap before using this class:
12  *
13  * @see http://www.OpenWeatherMap.org
14  * @see http://www.OpenWeatherMap.org/terms
15  * @see http://openweathermap.org/appid
16  */
17
18 use Cmfcmf\OpenWeatherMap;
19
20 if (file_exists('../vendor/autoload.php')) {
21     // Library is not part of a project. "composer install" was executed directly on this library's composer file.
22     require('../vendor/autoload.php');
23 } else {
24     // Library is part of a project.
25     /** @noinspection PhpIncludeInspection */
26     require('../../../autoload.php');
27 }
28
29 // Language of data (try your own language here!):
30 $lang = 'de';
31
32 // Units (can be 'metric' or 'imperial' [default]):
33 $units = 'metric';
34
35 // Get OpenWeatherMap object. Don't use caching (take a look into Example_Cache.php to see how it works).
36 $owm = new OpenWeatherMap();
37
38 // Example 1: Get forecast for the next 10 days for Berlin.
39 $forecast = $owm->getWeatherForecast('Berlin', $units, $lang, '', 10);
40 echo "EXAMPLE 1<hr />\n\n\n";
41
42 echo "City: " . $forecast->city->name;
43 echo "<br />\n";
44 echo "LastUpdate: " . $forecast->lastUpdate->format('d.m.Y H:i');
45 echo "<br />\n";
46 echo "Sunrise : " . $forecast->sun->rise->format("H:i:s") . " Sunset : " . $forecast->sun->set->format("H:i:s");
47 echo "<br />\n";
48 echo "<br />\n";
49
50 foreach ($forecast as $weather) {
51     // Each $weather contains a Cmfcmf\ForecastWeather object which is almost the same as the Cmfcmf\Weather object.
52     // Take a look into 'Examples_Current.php' to see the available options.
53     echo "Weather forecast at " . $weather->time->day->format('d.m.Y') . " from " . $weather->time->from->format('H:i') . " to " . $weather->time->to->format('H:i');
54     echo "<br />\n";
55     echo $weather->temperature;
56     echo "<br />\n";
57     echo "---";
58     echo "<br />\n";
59 }
60
61 // Example 2: Get forecast for the next 3 days for Berlin.
62 $forecast = $owm->getWeatherForecast('Berlin', $units, $lang, '', 3);
63 echo "EXAMPLE 2<hr />\n\n\n";
64
65 foreach ($forecast as $weather) {
66     echo "Weather forecast at " . $weather->time->day->format('d.m.Y') . " from " . $weather->time->from->format('H:i') . " to " . $weather->time->to->format('H:i') . "<br />";
67     echo $weather->temperature . "<br />\n";
68     echo "---<br />\n";
69 }