]> git.mxchange.org Git - friendica-addons.git/blob - curweather/vendor/cmfcmf/openweathermap-php-api/Examples/WeatherHistory.php
c64ee524d0452bee36984ba60cc5ec16ad7bfd75
[friendica-addons.git] / curweather / vendor / cmfcmf / openweathermap-php-api / Examples / WeatherHistory.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 = 'en';
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 hourly weather history between 2014-01-01 and today.
39 $history = $owm->getWeatherHistory('Berlin', new \DateTime('2014-01-01'), new \DateTime('now'), 'hour', $units, $lang);
40
41 foreach ($history as $weather) {
42     echo "Average temperature at " . $weather->time->format('d.m.Y H:i') . ": " . $weather->temperature . "\n\r<br />";
43 }