Skip to main content

An unofficial Python wrapper for public API of Hong Kong Observatory

Project description

GitHub Release PyPI

python-hko

A python warpper for retrieving Hong Kong SAR local weather from Hong Kong Observatory Open Data API. Please refer to the Official Documentation for request parameters and response details. Official API Documentation

Reference

HKO Module

hko.HKO(session) Manage and perform requests Return: hko.HKO class

Parameter Optional (default value) Type Description
session no ClientSession see aiohttp

hko.HKO.weather(dataType, lang) Retrieve weather data from Weather Information API Return: dictionary

Parameter Optional (default value) Type Description
dataType no string type of data requested
lang yes (en) string language used in response

hko.HKO.earthquake(dataType, lang) Retrieve weather data from Earthquake Information API Return: dictionary

Parameter Optional (default value) Type Description
dataType no string type of data requested
lang yes (en) string language used in response

hko.HKO.openData(dataType, lang) Retrieve weather data from Earthquake Information API Return: dictionary

Parameter Optional (default value) Type Description
dataType no string type of data requested
lang yes (en) string language used in response
station - string refer to Official API Documentation
year - string refer to Official API Documentation
month - string refer to Official API Documentation
day - string refer to Official API Documentation
hour - string refer to Official API Documentation

Usage Example

Get and print local weather forcast general situation in English

from hko import HKO, HKOError
import asyncio
from aiohttp import ClientSession
from aiohttp import ClientConnectorError

async def main():
    async with ClientSession() as session:
        try:
            hko = HKO(session)
            fnd = await hko.weather(dataType="fnd")
            print(fnd["generalSituation"])
        except HKOError as error:
            print(error)

asyncio.run(main())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hko-0.3.2.tar.gz (3.6 kB view hashes)

Uploaded Source

Built Distribution

hko-0.3.2-py3-none-any.whl (3.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page