An unofficial Python wrapper for public API of Hong Kong Observatory
Project description
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
Built Distribution
File details
Details for the file hko-0.3.1.tar.gz
.
File metadata
- Download URL: hko-0.3.1.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.1 CPython/3.9.13 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e34fa834f9b29b5fd16693ed9f1f209659691759e075d9d8579d6586fd5bc248 |
|
MD5 | 9f6b9825ba0a3e80d9bb3ef18bd2615c |
|
BLAKE2b-256 | f153c12faf3058cedff1aa94edac02e774ef81c011f4253e64e9933962fdb726 |
File details
Details for the file hko-0.3.1-py3-none-any.whl
.
File metadata
- Download URL: hko-0.3.1-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.1 CPython/3.9.13 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4543bf24fedfb9cd2fa4e7c51cfd352b8045bf2592523fe9d9a280d8bab91e4 |
|
MD5 | 3107947de2a2e6fd59b3ce7f1842aa5c |
|
BLAKE2b-256 | 1e695f7e51f94e0b70d110b7ffc397e974625808ff710f9632a6951947e30330 |