Public
Script
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
import { API } from "https://esm.town/v/nws/api";
export class Warnings {
endpoint: string
constructor(api: API) {
this.endpoint = api.url + `/alerts/active?status=actual&event=`;
}
async latest(warning_type: WarningType): Promise<Warning> {
const features = await fetch(this.endpoint + warning_type + " Warning&limit=1").then(res => res.json())
.then(res => res.features);
if (features.length === 0) return {
type: warning_type,
headline: `No current ${warning_type} warnings`
}
const latest = features[0].properties;
return {
type: warning_type,
area: latest.areaDesc,
sent: new Date(latest.sent),
expires: new Date(latest.expires),
sender: latest.senderName,
headline: latest.headline,
description: latest.description
};
}
}
interface Warning {
type: WarningType
area?: String
sent?: Date
expires?: Date
// TODO: change to Office type
sender?: String
headline: String
description?: String
}
/* Starting with just a few so please email
* nws@jordanreger.com if you want more
*/
export type WarningType =
| "Blizzard"
| "Flash Flood"
| "Flood"
| "Freeze"
| "Severe Thunderstorm"
| "Tornado"
| "Tropical Storm"
| "Tsunami"
| "Winter Storm";
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
June 4, 2024