From 78086bf15a335a9c40b5a58c2e563c0159870ed3 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 26 Sep 2022 00:37:39 +0200 Subject: Made a proper package out of the module --- pyproject.toml | 20 +++++++++++++++ windy.py | 68 ------------------------------------------------- windy/__init__.py | 1 + windy/point_forecast.py | 68 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+), 68 deletions(-) create mode 100644 pyproject.toml delete mode 100644 windy.py create mode 100644 windy/__init__.py create mode 100644 windy/point_forecast.py diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..a5df547 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,20 @@ +[project] +name="windy" +dependencies=[ + "requests==2.*", + "pint" +] +dynamic=["version"] + + +[tool.setuptools_scm] +fallback_version="0" +version_scheme="post-release" + + +[build-system] +build-backend="setuptools.build_meta" +requires=[ + "setuptools>=45", + "setuptools_scm[toml]>=6.2", +] diff --git a/windy.py b/windy.py deleted file mode 100644 index 2d5cab6..0000000 --- a/windy.py +++ /dev/null @@ -1,68 +0,0 @@ -from dataclasses import dataclass -from enum import Enum - -import requests - - -class _StrEnum(Enum): - def __str__(self): - return self.value - - -class Model(_StrEnum): - AROME = "arome" - GEOS5 = "geos5" - GFS = "gfs" - GFSWAVE = "gfsWave" - ICONEU = "iconEu" - NAMALASKA = "namAlaska" - NAMCONUS = "namConus" - NAMHAWAII = "namHawaii" - - -class Level(_StrEnum): - SURFACE = "surface" - H1000 = "1000h" - H950 = "950h" - H925 = "925h" - H900 = "900h" - H850 = "850h" - H800 = "800h" - H700 = "700h" - H600 = "600h" - H500 = "500h" - H400 = "400h" - H300 = "300h" - H200 = "200h" - H150 = "150h" - - -@dataclass -class Config: - key: str - api: str = "https://api.windy.com/api" - - -@dataclass -class Request: - lat: float - lon: float - model: Model - parameters: list = None - levels: list = None - endpoint: str = "/point-forecast/v2" - - def json(self): - body = { - 'lat': self.lat, - 'lon': self.lon, - 'model': str(self.model), - 'parameters': self.parameters or [], - } - if self.levels: - body['levels'] = [str(x) for x in self.levels] - return body - - -def point_forecast(request: Request, config: Config): - return requests.post(config.api + request.endpoint, json=request.json()) diff --git a/windy/__init__.py b/windy/__init__.py new file mode 100644 index 0000000..ba397a9 --- /dev/null +++ b/windy/__init__.py @@ -0,0 +1 @@ +from . import point_forecast diff --git a/windy/point_forecast.py b/windy/point_forecast.py new file mode 100644 index 0000000..2d5cab6 --- /dev/null +++ b/windy/point_forecast.py @@ -0,0 +1,68 @@ +from dataclasses import dataclass +from enum import Enum + +import requests + + +class _StrEnum(Enum): + def __str__(self): + return self.value + + +class Model(_StrEnum): + AROME = "arome" + GEOS5 = "geos5" + GFS = "gfs" + GFSWAVE = "gfsWave" + ICONEU = "iconEu" + NAMALASKA = "namAlaska" + NAMCONUS = "namConus" + NAMHAWAII = "namHawaii" + + +class Level(_StrEnum): + SURFACE = "surface" + H1000 = "1000h" + H950 = "950h" + H925 = "925h" + H900 = "900h" + H850 = "850h" + H800 = "800h" + H700 = "700h" + H600 = "600h" + H500 = "500h" + H400 = "400h" + H300 = "300h" + H200 = "200h" + H150 = "150h" + + +@dataclass +class Config: + key: str + api: str = "https://api.windy.com/api" + + +@dataclass +class Request: + lat: float + lon: float + model: Model + parameters: list = None + levels: list = None + endpoint: str = "/point-forecast/v2" + + def json(self): + body = { + 'lat': self.lat, + 'lon': self.lon, + 'model': str(self.model), + 'parameters': self.parameters or [], + } + if self.levels: + body['levels'] = [str(x) for x in self.levels] + return body + + +def point_forecast(request: Request, config: Config): + return requests.post(config.api + request.endpoint, json=request.json()) -- cgit v1.1