File: test_api.py

package info (click to toggle)
pyopenuv 2023.12.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 400 kB
  • sloc: python: 586; sh: 46; makefile: 3
file content (45 lines) | stat: -rw-r--r-- 1,076 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""Run an example script to quickly test."""
import asyncio
import logging
import time

from pyopenuv import Client
from pyopenuv.errors import OpenUvError

_LOGGER = logging.getLogger(__name__)

API_KEY = "<OPENUV_API_KEY>"
LATITUDE = 39.7974509
LONGITUDE = -104.8887227
ALTITUDE = 1609.3


async def main() -> None:
    """Create the aiohttp session and run the example."""
    logging.basicConfig(level=logging.DEBUG)

    client = Client(API_KEY, LATITUDE, LONGITUDE, altitude=ALTITUDE)

    start = time.time()

    try:
        # Get current UV info:
        _LOGGER.info("CURRENT UV DATA:")
        _LOGGER.info(await client.uv_index())

        # Get forecasted UV info:
        _LOGGER.info("FORECASTED UV DATA:")
        _LOGGER.info(await client.uv_forecast())

        # Get UV protection window:
        _LOGGER.info("UV PROTECTION WINDOW:")
        _LOGGER.info(await client.uv_protection_window())
    except OpenUvError as err:
        _LOGGER.info(err)

    end = time.time()

    _LOGGER.info("Execution time: %s seconds", end - start)


asyncio.run(main())