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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hko-0.3.2.tar.gz.
File metadata
- Download URL: hko-0.3.2.tar.gz
- Upload date:
- Size: 3.6 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 |
e85cdd6926b0eec5f9db033c1db1c51ad29d47624183707670c6673fb45f433b
|
|
| MD5 |
441f731d66f59f406f2d82618d1ac7fc
|
|
| BLAKE2b-256 |
705a09d5b1b0c8817964064f50274611566b757a4ab03bffa8b91de8337d5886
|
File details
Details for the file hko-0.3.2-py3-none-any.whl.
File metadata
- Download URL: hko-0.3.2-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 |
86c97d13d7456cb6d54b2390bc659d0f7f9a912fd2f46ca59851f3a2d379b543
|
|
| MD5 |
69f5b57bf97bb3b416107d65e6ab2d35
|
|
| BLAKE2b-256 |
5a8b435abcfa3888863951b614639aa96d883bb8d31c5ddda14a4c8bba4f5ac9
|