Public
Script
Forked from stevekrouse/easyAQI
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
import { blob } from "https://esm.town/v/std/blob?v=12";
import { nominatimSearch } from "https://esm.town/v/stevekrouse/nominatimSearch";
import { nowcastPMAQISeverity } from "https://esm.town/v/stevekrouse/nowcastPMAQISeverity";
import { openAQLocation as findOpenAQLocation } from "https://esm.town/v/stevekrouse/openAQLocation";
import { openAqNowcastAQI } from "https://esm.town/v/stevekrouse/openAqNowcastAQI";
const cacheKey = location => "easyAQI_locationID_cache_" + encodeURIComponent(location);
export async function easyAQI({ location }: {
location: string;
}) {
let openAQLocation = await blob.getJSON(cacheKey(location));
if (!openAQLocation) {
const [geo] = await nominatimSearch({
q: location,
});
console.log("Searching for openAQ stations near: " + geo.display_name);
openAQLocation = await findOpenAQLocation({
lat: parseFloat(geo.lat),
lon: parseFloat(geo.lon),
});
await blob.setJSON(cacheKey(location), { name: openAQLocation.name, id: openAQLocation.id });
}
console.log("Pulling pm2.5 from station: " + openAQLocation.name);
const aqi = await openAqNowcastAQI({
location_id: openAQLocation.id,
});
return { aqi, severity: nowcastPMAQISeverity(aqi) };
}
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!
May 30, 2024