flibidi67/open-meteo
Composer 安装命令:
composer require flibidi67/open-meteo
包简介
Symfony SDK for Open-Meteo API
README 文档
README
Open-Meteo collaborates with National Weather Services providing Open Data with 11 to 2 km resolution. Our high performance APIs select the best weather model for your location and provide data as a simple JSON API.
APIs are free without any API key for open-source developers and non-commercial use. You can embed them directly into your app.
Installation
You can install the package via composer:
composer require flibidi67/open-meteo
Then you can add this yaml file inside your config/packages directory (or you can copy it from the config directory of the package) :
flibidi67_open_meteo:
default:
temperature_unit: "celcius" # or fahrenheit
wind_speed_unit: "kmh" # or ms, mph, kn
precipitation_unit: "mm" # or inch
timeformat: "iso8601" #or unixtime
timezone: "GMT" # auto, GMT or another existing timezone (eg: Europe/Paris).
past_days: 0 # between 0 and 92
forecast_days: 7 # between 0 and 16
current_weather: false # true or false
forecast:
temperature_unit: ~
wind_speed_unit: ~
precipitation_unit: ~
timeformat: ~
timezone: ~
past_days: ~
forecast_days: ~
current_weather: ~
historical:
temperature_unit: ~
wind_speed_unit: ~
precipitation_unit: ~
timeformat: ~
timezone: ~
ecmwf:
temperature_unit: ~
wind_speed_unit: ~
precipitation_unit: ~
timeformat: ~
past_days: ~
gfs:
temperature_unit: ~
wind_speed_unit: ~
precipitation_unit: ~
timeformat: ~
timezone: ~
past_days: ~
forecast_days: ~
current_weather: ~
meteofrance:
temperature_unit: ~
wind_speed_unit: ~
precipitation_unit: ~
timeformat: ~
timezone: ~
past_days: ~
current_weather: ~
dwd:
temperature_unit: ~
wind_speed_unit: ~
precipitation_unit: ~
timeformat: ~
timezone: ~
past_days: ~
current_weather: ~
jma:
temperature_unit: ~
wind_speed_unit: ~
precipitation_unit: ~
timeformat: ~
timezone: ~
past_days: ~
current_weather: ~
metno:
temperature_unit: ~
wind_speed_unit: ~
precipitation_unit: ~
timeformat: ~
timezone: ~
past_days: ~
current_weather: ~
gem:
temperature_unit: ~
wind_speed_unit: ~
precipitation_unit: ~
timeformat: ~
timezone: ~
past_days: ~
current_weather: ~
You can either modify the values for a specific API's endpoint or just the default values.
If a value is set to null for API's parameters, then the default value is taken.
Usage
/!\ To see all available parameters don't hesitate to take a look at the Open-Meteo Documentation and feel free to explore the code.
List of available services
- ForecastService, to call the Weather Forecast API
- HistoricalService, to call the Historical Weather API
- ECMWFService, to call the ECMWF Weather Forecast API
- GFSService, to call the GFS & HRRR Forecast API
- MeteoFranceService, to call the MeteoFrance API
- DWDService, to call the DWD ICON API
- JMAService, to call the JMA API
- METNoService, to call the MET Norway API
- GEMService, to call the GEM API
Main service's methods
- getDaily() : Return the daily object.
- getHourly() : Return the hourly object.
- getSettings() : Return the settings object
- get() : Return the results
- setUrl(string $url): you can force the URL (need to be a full URL eg: https://api.open-meteo.com/v1/forecast?latitude=48.58&longitude=7.75&hourly=temperature_2m)
You can easily chain the different values you want to retrieve (except after retrieving the Settings). Autosuggest from your IDE will be you best friend :)
Daily, Hourly and Minutely15
with(string|array $parameter): $parameter can contain coma.get(): call the service'sget()method.$service->setCoordinates(48.58, 7.75) ->getHourly() ->with("temperature_2m,relativehumidity_2m,dewpoint_2m,cloudcover,cloudcover_low,cloudcover_mid");
Use a formatter
In order to directly render the data returned by the OpenMeteo API in a desired format, you can set a formatter to use.
This package come with a DefaultFormatter. To use it :
$myService->useDefaultFormatter()
The default formatter return the hourly, daily and minutely_15 in a formatted associative array.
[
'hourly' => [
'2023-03-22 00:00' => [
'time' => DateTime // the datetime object corresponding to the key
'temperature_2m' => 25.9 // for example
// and all the other values you retrieve with the with function
]
]
]
If you want to use your own formatter you should do like this
namespace Your\Namespace;
use Flibidi67\OpenMeteo\Contract\FormatterInterface;
class MyAwesomeFormatter implements FormatterInterface {
public function format(array $data): array {
// do what you want with $data.
return [];
}
}
// And then to use it
$myService->useFormatter(new MyAwesomeFormatter());
Quick examples
public function myFunction(ForecastService $forecastService) {
$forecastService->setCoordinates(48.58, 7.75)
->getHourly()
->withApparentTemperature()
->withTemperature2m()
->getSettings()
->setCurrentWeather(true)
->getDaily()
->withApparentTemperatureMax();
$results = $forecastService->get();
}
public function myFunction(ForecastService $forecastService) {
$forecastService->setCoordinates(48.58, 7.75)
->getHourly()
->withAll(true) // true parameters is for precise that we want ALL the pressure level.
->getDaily()
->withAll();
$results = $forecastService->get();
}
public function myFunction(ForecastService $forecastService) {
$results = $forecastService->setCoordinates(48.58, 7.75)
->getHourly()
->withAll(true) // true parameters is for precise that we want ALL the pressure level.
->getDaily()
->withAll()
->get();
}
public function myFunction(HttpClientInterface $httpClient, ParameterBagInterface $parameterBag) {
$forecastService = new ForecastService($httpClient, $parameterBag);
$forecastService->setCoordinates(48.58, 7.75)->withHourlyTemperature2m();
}
flibidi67/open-meteo 适用场景与选型建议
flibidi67/open-meteo 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 198 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 03 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「sdk」 「weather」 「forecasts」 「meteo」 「open-meteo」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 flibidi67/open-meteo 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 flibidi67/open-meteo 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 flibidi67/open-meteo 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The bundle for easy using json-rpc api on your project
Laravel-forecast provides a service provider and a facade around the Forecast-php wrapper
Bundle Symfony DaplosBundle
Add a weather widget to Flarum
Simple weather forecaster for Laravel
Unofficial PHP client for aWhere weather API
统计信息
- 总下载量: 198
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-03-17
