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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { toDatesWithTz } from "https://esm.town/v/wilt/toDatesWithTz";
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
// See https://open-meteo.com/en/docs for usage
type OMHourlyMeasures =
| "temperature_2m"
| "relativehumidity_2m"
| "dewpoint_2m"
| "apparent_temperature"
| "pressure_msl"
| "surface_pressure"
| "cloudcover"
| "cloudcover_low"
| "cloudcover_mid"
| "cloudcover_high"
| "windspeed_10m"
| "windspeed_80m"
| "windspeed_120m"
| "windspeed_180m"
| "winddirection_10m"
| "winddirection_80m"
| "winddirection_120m"
| "winddirection_180m"
| "windgusts_10m"
| "shortwave_radiation"
| "direct_radiation"
| "direct_normal_irradiance"
| "diffuse_radiation"
| "vapor_pressure_deficit"
| "cape"
| "evapotranspiration"
| "et0_fao_evapotranspiration"
| "precipitation"
| "snowfall"
| "precipitation_probability"
| "rain"
| "showers"
| "weathercode"
| "snow_depth"
| "freezinglevel_height"
| "visibility"
| "soil_temperature_0cm"
| "soil_temperature_6cm"
| "soil_temperature_18cm"
| "soil_temperature_54cm"
| "soil_moisture_0_1cm"
| "soil_moisture_1_3cm"
| "soil_moisture_3_9cm"
| "soil_moisture_9_27cm"
| "soil_moisture_27_81cm"
| "is_day";
type OMDailyMeasures =
| "temperature_2m_max"
| "temperature_2m_min"
| "apparent_temperature_max"
| "apparent_temperature_min"
| "precipitation_sum"
| "rain_sum"
| "showers_sum"
| "snowfall_sum"
| "precipitation_hours"
| "precipitation_probability_max"
| "precipitation_probability_min"
| "precipitation_probability_mean"
| "weathercode"
| "sunrise"
| "sunset"
| "windspeed_10m_max"
| "windgusts_10m_max"
| "winddirection_10m_dominant"
| "shortwave_radiation_sum"
| "et0_fao_evapotranspiration"
| "uv_index_max"
| "uv_index_clear_sky_max";
interface OMParams {
latitude: number;
longitude: number;
hourly?: OMHourlyMeasures[];
daily?: OMDailyMeasures[];
current_weather?: boolean;
temperature_unit?: "celcius" | "fahrenheit";
windspeed_unit?: "kmh" | "ms" | "mph" | "kn";
precipitation_unit?: "mm" | "inch";
timeformat?: string;
timezone?: string;
past_days?: number;
forecast_days?: number;
start_date?: string;
end_date?: string;
models?: string[];
cell_selection?: "land" | "sea" | "nearest";
}
export async function getOpenMeteoForecast(params: OMParams) {
const data = await fetchJSON(
`https://api.open-meteo.com/v1/forecast?${new URLSearchParams(
params as {} // Typescript is stricter than Deno here
).toString()}`
);
if (Array.isArray(data.hourly?.time)) {
data.hourly.time = await toDatesWithTz(
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.