summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-10-04 23:20:23 +0200
committerAki <please@ignore.pl>2022-10-04 23:20:23 +0200
commit732e30975828cf525fe27dc406712eb3d9b4d812 (patch)
tree0d93d7c6d08fe0622509b8f1f33917ce5d9420be
parent21c64c5f6c87fda8fbfbb34d8d625aa506b96046 (diff)
downloadwindy-732e30975828cf525fe27dc406712eb3d9b4d812.zip
windy-732e30975828cf525fe27dc406712eb3d9b4d812.tar.gz
windy-732e30975828cf525fe27dc406712eb3d9b4d812.tar.bz2
Wrapped and shuffled endpoint config around to Windy class
-rw-r--r--windy/__init__.py16
-rw-r--r--windy/point_forecast.py13
2 files changed, 20 insertions, 9 deletions
diff --git a/windy/__init__.py b/windy/__init__.py
index ba397a9..346cece 100644
--- a/windy/__init__.py
+++ b/windy/__init__.py
@@ -1 +1,15 @@
-from . import point_forecast
+from pint import UnitRegistry
+from requests import Session
+
+import point_forecast
+
+
+class Windy:
+ def __init__(self, registry: UnitRegistry, session: Session = None, api: str = "https://api.windy.com/api"):
+ self.registry = registry
+ self.session = session or Session()
+ self.api = api
+ self._point_forecast = point_forecast.Endpoint("/point-forecast/v2")
+
+ def point_forecast(self, request: point_forecast.Request):
+ return self._point_forecast(self, request)
diff --git a/windy/point_forecast.py b/windy/point_forecast.py
index 83c328d..976f785 100644
--- a/windy/point_forecast.py
+++ b/windy/point_forecast.py
@@ -1,8 +1,6 @@
from dataclasses import dataclass
from enum import Enum
-import requests
-
class _StrEnum(Enum):
def __str__(self):
@@ -45,8 +43,6 @@ class Request:
model: Model
parameters: list = None
levels: list = None
- endpoint: str = "/point-forecast/v2"
- api: str = "https://api.windy.com/api"
def body(self):
body = {
@@ -60,9 +56,10 @@ class Request:
body['levels'] = [str(x) for x in self.levels]
return body
- def url(self):
- return self.api + self.endpoint
+@dataclass
+class Endpoint:
+ path: str
-def point_forecast(request: Request):
- return requests.post(request.url(), json=request.body())
+ def __call__(self, windy, request: Request):
+ return windy.session.post(windy.api + self.path, json=request.body())