tellyarz / afri-weather-app
There is no license information available for the latest version (dev-master) of this package.
Fetch current and weather forecast from OpenWeatherMap
dev-master
2017-04-11 14:38 UTC
Requires
- php: ^7.0
This package is not auto-updated.
Last update: 2025-06-13 21:45:53 UTC
README
Fetch current and weather forecast from OpenWeatherMap
How to Install:
Install using composer:
composer require tellyarz/afri-weather-app
How to use:
include 'vendor/autoload.php'; //create open weather object and retrieve weather forecast for 5days $op = new \AfriWeatherApp\OpenWeather('your_api_key'); $weather = $op->getWeatherForecast('Abuja'); //decode json string $decodedString = json_decode($weather, true); if(intVal($decodedString['cod']) === 200) { //we have weather data ready, get the list $listData = $decodedString['list']; //iterate through list foreach($listData as $list) { $timeStamp = $list['dt']; $timeString = $list['dt_txt']; $mainSubArray = $list['main']; $tempMin = $mainSubArray['temp_min']; $tempMax = $mainSubArray['temp_max']; $pressure = $mainSubArray['pressure']; $seaLevel = $mainSubArray['sea_level']; $groundLevel = $mainSubArray['grnd_level']; $humidity = $mainSubArray['humidity']; $weatherSubArray = $list['weather'][0]; $description = $weatherSubArray['main']; $condition = $weatherSubArray['description']; $icon = "http://openweathermap.org/img/w/{$weatherSubArray['icon']}.png"; $windSubArray = $list['wind']; $speed = $windSubArray['speed']; $degree = $windSubArray['deg']; //further process here... } } //to get current weather data $currentWeather = $op->getCurrentWeather('London'); //decode json string $decodedString_ = json_decode($currentWeather, true); if(intVal($decodedString_['cod']) === 200) { //successfully fetched weather data var_dump($decodedString_); }