-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-links.mjs
More file actions
22 lines (22 loc) · 1.12 KB
/
Copy pathcheck-links.mjs
File metadata and controls
22 lines (22 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
export async function fetchWikidataVenuesNearCity({ city, lat, lon, radiusKm = 30, limit = 120 }) {
const query = `
SELECT ?item ?itemLabel ?coord ?image ?official ?instanceLabel WHERE {
SERVICE wikibase:around {
?item wdt:P625 ?coord.
bd:serviceParam wikibase:center "Point(${lon} ${lat})"^^geo:wktLiteral.
bd:serviceParam wikibase:radius "${radiusKm}".
}
VALUES ?type { wd:Q33506 wd:Q207694 wd:Q570116 wd:Q17431399 wd:Q839954 wd:Q4830453 wd:Q570116 }
?item wdt:P31/wdt:P279* ?type.
OPTIONAL { ?item wdt:P18 ?image. }
OPTIONAL { ?item wdt:P856 ?official. }
OPTIONAL { ?item wdt:P31 ?instance. }
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
LIMIT ${limit}`;
const url = "https://query.wikidata.org/sparql?format=json&query=" + encodeURIComponent(query);
const res = await fetch(url, { headers: { "Accept": "application/sparql-results+json", "User-Agent": "openARTlasAtlas/5.0" } });
if (!res.ok) throw new Error(`Wikidata failed for ${city}: ${res.status}`);
const json = await res.json();
return json.results.bindings.map(binding => ({ source: "wikidata", city, binding }));
}