diff options
| author | Adam Soltys <[email protected]> | 2024-08-26 21:17:43 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-08-26 21:17:43 -0700 |
| commit | fe62cadd6fb4a7e49f7d59401fc74ae0411e32a7 (patch) | |
| tree | aa8f34e1692bd2d638a2c996eeadb58671d07aea /lib/locations.ts | |
| parent | 00e43ddc0bf3d6dd719fc9295d156567fa2fecfb (diff) | |
| download | coinos-server-fe62cadd6fb4a7e49f7d59401fc74ae0411e32a7.tar.gz coinos-server-fe62cadd6fb4a7e49f7d59401fc74ae0411e32a7.zip | |
typescript
Diffstat (limited to 'lib/locations.ts')
| -rw-r--r-- | lib/locations.ts | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/locations.ts b/lib/locations.ts new file mode 100644 index 00000000..39212d05 --- /dev/null +++ b/lib/locations.ts @@ -0,0 +1,40 @@ +import fs from "fs"; +import { err } from "$lib/logging"; +import got from "got"; +import { g, s } from "$lib/db"; +import { fields, pick } from "$lib/utils"; + +export let getLocations = async () => { + try { + let locations = 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", + ); + + locations.map((l) => { + let { bounds, lat, lon } = l["osm_json"]; + + l["osm_json"].lat = lat || (bounds.minlat + bounds.maxlat) / 2; + l["osm_json"].lon = lon || (bounds.minlon + bounds.maxlon) / 2; + }); + + for await (let l of locations) { + let username = l.tags["payment:coinos"]; + if (username) { + let uid = await g(`user:${username}`); + let user = await g(`user:${uid}`); + if (user) l["osm_json"].tags.user = pick(user, fields); + } + } + + await s("locations", locations); + } catch (e) { + err("problem fetching locations", e); + } + + setTimeout(getLocations, 60000); +}; |
