aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-09-26 09:26:26 -0700
committerAdam Soltys <[email protected]>2024-09-26 09:26:26 -0700
commitd47aebf9edfc9e455e11402c6e93dac29506937a (patch)
tree9e7df56a7dd1983eea72d2751310d373d653b363
parent8c07db5c9f944c82fab31c2af1eeb132aa2245c9 (diff)
downloadcoinos-server-d47aebf9edfc9e455e11402c6e93dac29506937a.tar.gz
coinos-server-d47aebf9edfc9e455e11402c6e93dac29506937a.zip
locations
-rw-r--r--lib/locations.ts13
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);
}