From d47aebf9edfc9e455e11402c6e93dac29506937a Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 26 Sep 2024 09:26:26 -0700 Subject: locations --- lib/locations.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'lib/locations.ts') 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 = 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); } -- cgit v1.2.3