ajur-media/openweathermap-data-parser

A PHP class to parse weather data from OpenWeatherMap.org. This library tries to normalise and abstract the data and remove inconsistencies

0.9 2020-10-24 20:17 UTC

This package is not auto-updated.

Last update: 2024-04-22 10:51:29 UTC


README

A PHP class to retrieve and parse weather data from OpenWeatherMap.org.

This library aims to normalise the provided data and remove some inconsistencies. This library is neither maintained by OpenWeatherMap nor their official PHP API.

Installation

This library can be found on Packagist. The recommended way to install and use it is through Composer.

composer require ajur-media/openweathermap-data-parser

Example call

<?php
use AJUR\OpenWeatherMap;
use AJUR\OpenWeatherMap\Exception as OWMException;

// Must point to composer's autoload file.
require 'vendor/autoload.php';

// Language of data (try your own language here!):
$lang = 'ru';

// Units (can be 'metric' or 'imperial' [default]):
$units = 'metric';

// Create OpenWeatherMap object. 
// Don't use caching (take a look into Examples/Cache.php to see how it works).
$owm = new OpenWeatherMap('YOUR-API-KEY');

try {
    $weather = $owm->getWeather('Berlin', $units, $lang);
} catch(OWMException $e) {
    echo 'OpenWeatherMap exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').';
} catch(\Exception $e) {
    echo 'General exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').';
}

echo $weather->temperature;

License

MIT — Please see the LICENSE file distributed with this source code for further information regarding copyright and licensing.

Please check out the following official links to read about the terms, pricing and license of OpenWeatherMap before using the service: