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.99.1 2024-08-23 14:02 UTC

This package is not auto-updated.

Last update: 2024-12-18 16:52:47 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: