https://github.com/previousnext/bom-weather
PHP lib for reading Australian Bureau of Meteorology Weather data.
https://github.com/previousnext/bom-weather
Last synced: 10 months ago
JSON representation
PHP lib for reading Australian Bureau of Meteorology Weather data.
- Host: GitHub
- URL: https://github.com/previousnext/bom-weather
- Owner: previousnext
- License: gpl-2.0
- Created: 2018-06-24T23:29:31.000Z (almost 8 years ago)
- Default Branch: main
- Last Pushed: 2024-03-06T06:09:55.000Z (about 2 years ago)
- Last Synced: 2025-08-10T08:49:17.653Z (10 months ago)
- Language: PHP
- Homepage:
- Size: 94.7 KB
- Stars: 5
- Watchers: 8
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# BOM Weather
A PHP library for fetching data from the Australian Bureau of Meteorology API.
## Installation
```
composer require previousnext/bom-weather php-http/discovery
```
The library requires a PSR-18 HTTP client and PSR-17 HTTP factories. We recommend using [Guzzle](https://docs.guzzlephp.org/en/stable/).
## Usage
### Forecasts
```php
$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();
}
}
```
### Observations
```php
$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();
```
## Developing
**PHP CodeSniffer**
```
./bin/phpcs
```
**PHPUnit**
```
./bin/phpunit
```
**PHPStan**
```
./bin/phpstan
```