Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Berlin coordinates
wd:${wikidataId} wdt:P625 ?singLoc .
SERVICE wikibase:around {
?place wdt:P625 ?location .
bd:serviceParam wikibase:center ?singLoc .
bd:serviceParam wikibase:radius ${radius} .
}
# Is a human settlement
?place wdt:P31/wdt:P279* wd:Q486972 .
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
}
}
`;
var url = wdk.sparqlQuery(sparql);
request(url, function (err, response) {
if (err) {
console.log(err);
} else {
var body = JSON.parse(response.body);
try {
var bindings = body['results']['bindings'];
var count = 0;
bindings.forEach(function (binding) {
bindings[count]['wikidata_url'] = binding['place']['value'];
bindings[count]['wikidata_qid'] = binding['place']['value'].split('entity/')[1];
bindings[count]['place_label'] = binding['placeLabel']['value'];
bindings[count]['location'] = binding['location']['value'];
count += 1;
});
var uniqueBindings = uniqBy(bindings, 'place');
result.search.forEach((entity) => {
choices.push(entity);
entity.lang = lang;
queue.push(
fetch(wdk.sparqlQuery(instancesSPARQL(entity)))
.then(response => response.json())
.then(result => getInstances(result, entity))
.catch(e => console.error(colors.red(e)))
);
queue.push(
fetch(wdk.sparqlQuery(sitelinkSPARQL(entity)))
.then(response => response.json())
.then(result => getSitelink(result, entity))
.catch(e => console.error(colors.red(e)))
);
});
return Promise.all(queue);
result.search.forEach((entity) => {
choices.push(entity);
entity.lang = lang;
queue.push(
fetch(wdk.sparqlQuery(instancesSPARQL(entity)))
.then(response => response.json())
.then(result => getInstances(result, entity))
.catch(e => console.error(colors.red(e)))
);
queue.push(
fetch(wdk.sparqlQuery(sitelinkSPARQL(entity)))
.then(response => response.json())
.then(result => getSitelink(result, entity))
.catch(e => console.error(colors.red(e)))
);
});
return Promise.all(queue);