summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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())