diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/locations.ts | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/locations.ts b/lib/locations.ts index 39212d05..0faad2fc 100644 --- a/lib/locations.ts +++ b/lib/locations.ts @@ -1,4 +1,3 @@ -import fs from "fs"; import { err } from "$lib/logging"; import got from "got"; import { g, s } from "$lib/db"; @@ -6,13 +5,20 @@ import { fields, pick } from "$lib/utils"; export let getLocations = async () => { try { - let locations = await got( + let last = await g("locations:last"); + let now = Date.now(); + + if (now - last < 60000) return g("locations"); + let locations: Array<any> = await got( "https://api.btcmap.org/v2/elements?updated_since=2022-09-19T00:00:00Z", ).json(); locations = locations.filter( (l) => - l["osm_json"].tags && l["osm_json"].tags["payment:coinos"] === "yes", + l["osm_json"].tags && + l["osm_json"].tags["payment:coinos"] === "yes" && + l["osm_json"].tags.name && + !l["deleted_at"], ); locations.map((l) => { @@ -32,6 +38,7 @@ export let getLocations = async () => { } await s("locations", locations); + await s("locations:last", now); } catch (e) { err("problem fetching locations", e); } |
