WeatherVisual is a PHP package for fetching weather data from VisualCrossing Weather API and handling the data.
-
Install Composer Dependencies:
- Run Composer to install the required dependencies.
composer install
-
Start XAMPP:
- Open the XAMPP Control Panel and start Apache and MySQL.
-
Run the Demo:
- Place the
WeatherVisualProjectdirectory in thehtdocsdirectory of XAMPP. - Open your web browser and navigate to
http://localhost/WeatherVisualProject/demo/demos.php.
- Place the
-
Run the Tests:
- Open Command Prompt or Terminal.
- Navigate to your project directory (
C:\xampp\htdocs\WeatherVisualProject). - Run the PHPUnit tests.
vendor/bin/phpunit tests/WeatherVisualTest.php
-
Register at Packagist:
- Create an account at Packagist.
- Submit your package by providing the GitHub repository URL.
-
Publish Your Package:
- Follow the instructions on Packagist to publish your package.
- Once published, others can install your module using Composer:
composer require yourname/weathervisual
To install WeatherVisual, use Composer:
composer require visualcrossing/weathervisualuse WeatherVisual\WeatherData;
$data = [
'days' => [
[
'datetime' => '2024-01-02',
'hours' => [
['datetime' => '00:00:00', 'temp' => 70.0, 'humidity' => 50],
['datetime' => '01:00:00', 'temp' => 68.0, 'humidity' => 55],
]
]
]
];
$weather = new WeatherVisual($data);or
<?php
require 'vendor/autoload.php';
use WeatherVisual\WeatherData;
$apiKey = 'YOUR_API_KEY';
$weather = new WeatherData($apiKey);
try {
$data = $weather->fetchWeatherData('Los Angeles, CA', '2024-01-01', '2024-01-07');
print_r($data);
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}
?>// Get temperature at a specific datetime
echo "Temperature at datetime: " . $weather->getTempAtDatetime('2024-01-02', '00:00:00') . "\n";
// Set temperature at a specific datetime
$weather->setTempAtDatetime('2024-01-02', '00:00:00', 72.0);
echo "Updated Temperature at datetime: " . $weather->getTempAtDatetime('2024-01-02', '00:00:00') . "\n";// Get humidity at a specific datetime
echo "Humidity at datetime: " . $weather->getHumidityAtDatetime('2024-01-02', '00:00:00') . "\n";
// Set humidity at a specific datetime
$weather->setHumidityAtDatetime('2024-01-02', '00:00:00', 60);
echo "Updated Humidity at datetime: " . $weather->getHumidityAtDatetime('2024-01-02', '00:00:00') . "\n";To run the tests, use PHPUnit:
vendor/bin/phpunitor
php test_weather_data.php