previousnext / bom-weather
PHP库,用于访问澳大利亚气象局(BOM)的天气预报和观测数据。
1.0.0-alpha1
2018-06-25 03:52 UTC
Requires
- php: ^7.2
- ext-curl: *
- ext-xml: *
- guzzlehttp/guzzle: ~6.3
- psr/log: ~1.0
- symfony/property-access: ~4.1
- symfony/serializer: ~4.1
Requires (Dev)
- drupal/coder: ~8
- mikey179/vfsstream: ~1.0
- phpunit/phpunit: ~6.0
- symfony/phpunit-bridge: ~4.1
This package is auto-updated.
Last update: 2024-09-24 06:49:42 UTC
README
一个用于从澳大利亚气象局API获取数据的PHP库。
安装
composer require previousnext/bom-weather php-http/discovery
该库需要PSR-18 HTTP客户端和PSR-17 HTTP工厂。我们建议使用Guzzle。
使用
预报
$httpClient = new GuzzleHttp\Client(['base_uri' => 'http://www.bom.gov.au/']); $requestFactory = new Http\Factory\Guzzle\RequestFactory(); $client = new BomClient($httpClient, $requestFactory, new NullLogger()); $forecast = $client->getForecast('IDN10031'); $issueTime = $forecast->getIssueTime(); $regions = $forecast->getRegions(); $metros = $forecast->getMetropolitanAreas(); $locations = $forecast->getLocations(); foreach ($locations as $location) { $aac = $location->getAac(); $desc = $location->getDescription(); /** @var \BomWeather\Forecast\ForecastPeriod[] $periods */ $periods = $location->getForecastPeriods(); // Usually 7 days of forecast data. foreach ($periods as $period) { $date = $period->getStartTime(); $maxTemp = $period->getAirTempMaximum(); $precis = $period->getPrecis(); } }
观测
$httpClient = new GuzzleHttp\Client(['base_uri' => 'http://www.bom.gov.au/']); $requestFactory = new Http\Factory\Guzzle\RequestFactory(); $client = new BomClient($httpClient, $requestFactory, new NullLogger()); $observationList = $client->getObservationList('IDN60901', '95757'); $refreshMessage = $observationList->getRefreshMessage(); // Get the latest observation. $observation = $observationList->getLatest(); $rain = $observation->getRainSince9am(); // Station information. $station = $observation->getStation(); $name = $station->getName(); // Temperature observations. $temperature = $observation->getTemperature(); $airTemp = $temperature->getAirTemp(); $apparentTemp = $temperature->getApparentTemp(); $relativeHumidity = $temperature->getRealtiveHumidity(); // Wind observations. $wind = $observation->getWind(); $direction = $wind->getDirection(); $speedKmh = $wind->getSpeedKmh(); $gustKmh = $wind->getGustKmh(); // Pressure observations. $pressure = $observation->getPressure(); $qnh = $pressure->getQnh(); $meanSeaLevel = $pressure->getMeanSeaLevel();
开发
PHP CodeSniffer
./bin/phpcs
PHPUnit
./bin/phpunit
PHPStan
./bin/phpstan