diff options
-rw-r--r-- | .gitignore | 6 | ||||
-rw-r--r-- | windy.py | 37 |
2 files changed, 43 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bdc591b --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +__pycache__/ +.venv/ +*.egg-info/ +build*/ +.eggs/ +.env diff --git a/windy.py b/windy.py new file mode 100644 index 0000000..3938ed6 --- /dev/null +++ b/windy.py @@ -0,0 +1,37 @@ +from enum import Enum + +import requests + +API = "https://api.windy.com/api" + + +class Model(Enum): + ICONEU = "iconEu" + + def __str__(self): + return self.value + + +class PointForecast: + ENDPOINT = "/point-forecast/v2" + + def __init__(self, lat: float, lon: float, model: Model, parameters=None, levels=None, key=None): + self.lat = lat + self.lon = lon + self.model = model + self.parameters = parameters or [] + self.levels = levels or ["surface"] + self.key = key + + def request(self, /, key=None): + return requests.post(API + self.ENDPOINT, json=self.body(key=key)) + + def body(self, /, lat=None, lon=None, model=None, parameters=None, levels=None, key=None): + return { + 'lat': lat or self.lat, + 'lon': lon or self.lon, + 'model': str(model or self.model), + 'parameters': parameters or self.parameters, + 'levels': levels or self.levels, + 'key': key or self.key, + } |