2017 © Pedro Peláez
 

library weather-api

Weather API and air quality for Poland

image

mrcnpdlk/weather-api

Weather API and air quality for Poland

  • Monday, June 11, 2018
  • by mrcnpdlk
  • Repository
  • 0 Watchers
  • 0 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

WEATHER API - (not only) Polish weather + air quality

Contents

  1. Installation
  2. Basic usage
    1. Cache
    2. Logger
  3. External sources
    1. Chief Inspectorate of Environmental Protection
    2. Airly
    3. Open Weather Map
  4. API Usage
    1. Create instance
    2. Available methods
    3. Examples

Installation

Install the latest version with composer, (*1)

composer require mrcnpdlk/weather-api

Basic usage

Cache

Library supports Cache bundles based on PSR-16 standard., (*2)

For below example was used phpfastcache/phpfastcache V7. phpfastcache/phpfastcache supports a lot of endpoints, i.e. Files, Sqlite, Redis and many other. More information about using cache and configuration it you can find in this Wiki., (*3)


/** * Cache in system files */ $oFilesConfig = new \Phpfastcache\Drivers\Files\Config(); $oFilesConfig->setPath(sys_get_temp_dir())->setDefaultTtl(60); $oInstanceCacheFiles = new \Phpfastcache\Helper\Psr16Adapter('files', $oFilesConfig); /** * Cache in Redis */ $oRedisConfig = new \Phpfastcache\Drivers\Redis\Config(); $oRedisConfig ->setHost('localhost') ->setPort(6379) ->setDefaultTtl(60) ; $oInstanceCacheRedis = new \Phpfastcache\Helper\Psr16Adapter('redis', $oRedisConfig);

Log

Library also supports logging packages based on PSR-3 standard, i.e. very popular monolog/monolog., (*4)

$oInstanceLogger = new \Monolog\Logger('name_of_my_logger');
$oInstanceLogger->pushHandler(new \Monolog\Handler\ErrorLogHandler(
        \Monolog\Handler\ErrorLogHandler::OPERATING_SYSTEM,
        \Psr\Log\LogLevel::DEBUG
    )
)->pushProcessor(new \Monolog\Processor\PsrLogMessageProcessor());

External sources

GIOS

GIOS (Chief Inspectorate of Environmental Protection - Główny Inspektorat Ochrony Środowiska) provide API without any authentication., (*5)

Airly

Airly builds networks of air quality sensors that can be deployed across entire cities or counties. If you want to use external data using this API you have to get the free Token key from here ., (*6)

OWM

Open Weather Map is well know project for weather and forecast. To use it, get the free Token Key from here ., (*7)

API usage

Create instance

$oClient = new \mrcnpdlk\Weather\Client();
$oClient
    ->setCacheInstance($oInstanceCacheFiles)
    ->setLoggerInstance($oInstanceLogger)
    ->setAirlyConfig('AIRLY_TOKEN')  // not required but recommended
    ->setOWMConfig('OWM_TOKEN')  // not required but recommended
;
$oApi = new \mrcnpdlk\Weather\Api($oClient);

By default API uses: - current geo location found using public IP of machine where script is run - current date of machine where script is run, (*8)

We are able to change location calling setLocation() method., (*9)

use mrcnpdlk\Weather\NativeModel\GeoPoint;

$oApi->setLocation(new GeoPoint(51.758158,19.544377));

Methods

Name Description Uses external sources?
getAddress() Getting address using revers geocode no
getSunSchedule() Getting surise, sunset, twilight timing etc no
getNearestGiosStation() Getting nearest GIOS station no
getUVIndex() UV Index yes, OWM
getWeather() weather yes, OWM

Examples

getAddress()

mrcnpdlk\Weather\Model\Address Object
(
    [countryCode] => pl
    [province] => łódzkie
    [commune] => Łódź
    [place] => Łódź
    [neighbourhood] => Katedralna
    [street] => Wincentego Tymienieckiego
    [homeNr] => 16
    [postalCode] => 90-365
)

getSunSchedule()

Method can give inappropriate results for location near pole., (*10)

mrcnpdlk\Weather\Model\SunSchedule Object
(
    [sunrise] => 07:46:57
    [sunset] => 15:50:12
    [dayDuration] => 8:03
    [transit] => 11:48:34
    [civilTwilightBegin] => 07:07:27
    [civilTwilightEnd] => 16:29:42
    [nauticalTwilightBegin] => 06:24:41
    [nauticalTwilightEnd] => 17:12:27
    [astronomicalTwilightBegin] => 05:44:05
    [astronomicalTwilightEnd] => 17:53:03
)

getUVIndex()

0.43

getNearestGiosStation()

mrcnpdlk\Weather\NativeModel\Gios\Station Object
(
    [id] => 10058
    [stationName] => Łódź-Jana Pawła II 15
    [dateStart] => 2015-10-27 00:00:00
    [dateEnd] =>
    [gegrLat] => 51.754613
    [gegrLon] => 19.434925
    [addressStreet] => al. Jana Pawła II 15
    [city] => mrcnpdlk\Weather\NativeModel\Gios\City Object
        (
            [id] => 516
            [name] => Łódź
            [commune] => mrcnpdlk\Weather\NativeModel\Gios\Commune Object
                (
                    [communeName] => Łódź
                    [districtName] => Łódź
                    [provinceName] => ŁÓDZKIE
                )

        )

    [distance] => 2253.495
)

mrcnpdlk\Weather\NativeModel\Gios\Station has implemented two methods:, (*11)

| Name | Description | | -------- | -------- | | getAirQualityIndex() | Return air quality index | | getSensors() | Return list of available sensors for station | For each sensor getData() method return list of historical measurement data., (*12)

Native API

The Versions

11/06 2018
11/06 2018

dev-devel

dev-devel

Weather API and air quality for Poland

  Sources   Download

MIT

The Requires

 

The Development Requires

weather air quality pogoda airly gios

11/06 2018
07/01 2018

v0.1.0

0.1.0.0

Weather API and air quality for Poland

  Sources   Download

MIT

The Requires

 

The Development Requires

weather air quality pogoda airly gios