From 01d53befb1bcf99eb230d3ae7df4229af2cf4ef7 Mon Sep 17 00:00:00 2001 From: Lee Sunde Date: Thu, 4 Sep 2025 09:01:10 +0200 Subject: [PATCH] Initial Release --- .gitignore | 1 + composer.json | 19 +++++++++++++++++++ composer.lock | 18 ++++++++++++++++++ src/getWeather.php | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 .gitignore create mode 100644 composer.json create mode 100644 composer.lock create mode 100644 src/getWeather.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..57872d0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/vendor/ diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..c7c8a84 --- /dev/null +++ b/composer.json @@ -0,0 +1,19 @@ +{ + "name": "liberty/weatherman", + "description": "Package to get Windhoeks weather", + "type": "library", + "license": "MIT", + "autoload": { + "psr-4": { + "Liberty\\Weatherman\\": "src/" + } + }, + "authors": [ + { + "name": "Lee Sunde", + "email": "liberty@nampharm.com.na" + } + ], + "minimum-stability": "stable", + "require": {} +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..a2b2f9b --- /dev/null +++ b/composer.lock @@ -0,0 +1,18 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "85b5ce5bd60a2174957bfd3e24a64f38", + "packages": [], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": {}, + "prefer-stable": false, + "prefer-lowest": false, + "platform": {}, + "platform-dev": {}, + "plugin-api-version": "2.6.0" +} diff --git a/src/getWeather.php b/src/getWeather.php new file mode 100644 index 0000000..c4529b7 --- /dev/null +++ b/src/getWeather.php @@ -0,0 +1,34 @@ +apiUrl); + if ($response === false) { + return null; + } + $data = json_decode($response, true); + if (!$data || !isset($data['current_condition'][0])) { + return null; + } + return [ + 'temperature_C' => $data['current_condition'][0]['temp_C'], + 'weather_desc' => $data['current_condition'][0]['weatherDesc'][0]['value'], + 'humidity' => $data['current_condition'][0]['humidity'], + ]; + } +} + +// Example usage: +$weather = new getWeather(); +$current = $weather->getWeather(); +if ($current) { + echo "Temperature: {$current['temperature_C']}°C\n"; + echo "Condition: {$current['weather_desc']}\n"; + echo "Humidity: {$current['humidity']}%\n"; +} else { + echo "Could not fetch weather data.\n"; +} \ No newline at end of file