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 getting 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(websession) Manage and perform requests Return: hko.HKO class

Parameter Optional Type Description
websession no ClientSession see aiphttp

hko.HKO.weather(type, lang="en") Retrieve weather data from Weather Information API Return: dictionary

Parameter Optional Type Description Accepted values
dataType no string type of data requested see Official API Documentation
lang yes string language used in response see Official API Documentation

Usage Example

Get and print local weather forcast general situation in English

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

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

loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.close()

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.2.0.tar.gz (3.4 kB view hashes)

Uploaded Source

Built Distribution

hko-0.2.0-py3-none-any.whl (3.2 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