rubin/openweather 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rubin/openweather

最新稳定版本:1.2.2

Composer 安装命令:

composer require rubin/openweather

包简介

OpenWeather API connector

README 文档

README

Build Status Latest Stable Version Coverage Status PHP Version Require

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2024-07-07