rubin/openweather
最新稳定版本:1.2.2
Composer 安装命令:
composer require rubin/openweather
包简介
OpenWeather API connector
关键字:
README 文档
README
PHP implementation for the OpenWeather REST API. This library is based on the REST API docs.
Installation
With composer:
composer require rubin/openweather
Usage
Create API connector:
$openWeatherApi = new \OpenWeather\OpenWeatherApi('{key}');
Set language (optional):
$openWeatherApi->setLanguage('ru');
Examples
Example script to get current weather:
$openWeatherApi = new \OpenWeather\OpenWeatherApi('{key}'); $output = new \Symfony\Component\Console\Output\StreamOutput(fopen('php://stdout', 'w')); $table = new \Symfony\Component\Console\Helper\Table($output); $table ->setHeaders(['Latitude', 'Longitude', 'Temperature', 'Weather']) ->setRows(array_map(function (\OpenWeather\GeoCoordinates $coordinates) use ($openWeatherApi) { $current = $openWeatherApi->getCurrentWeather($coordinates); return [ $coordinates->lat, $coordinates->lon, $current->main->temp, $current->weather[0]->description ]; }, [ new \OpenWeather\GeoCoordinates(lon: 37.36, lat: 55.45), new \OpenWeather\GeoCoordinates(lon: -66.159, lat: -68.2008), new \OpenWeather\GeoCoordinates(lon: 147.794, lat: -31.358) ])); $table->render();
Example script to get 5 days forecast:
$openWeatherApi = new \OpenWeather\OpenWeatherApi('{key}'); $output = new \Symfony\Component\Console\Output\StreamOutput(fopen('php://stdout', 'w')); $table = new \Symfony\Component\Console\Helper\Table($output); $table ->setHeaders(['DateTime', 'Temperature', 'PoP', 'Weather']) ->setRows(array_map(fn(\OpenWeather\ForecastItem $item) => [ $item->dt->format('Y-m-d H:i:s'), $item->main->temp, $item->pop, $item->weather[0]->description, ], $openWeatherApi->getForecast(new \OpenWeather\GeoCoordinates(lon: -66.159, lat: -68.2008))->list)); $table->render();
统计信息
- 总下载量: 160
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2024-07-07