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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
from enum import Enum
import requests
API = "https://api.windy.com/api"
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"
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,
}
|