From 23136f7e7a6b5a7760c0b8a535ce657025e8b52e Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Sun, 3 Oct 2021 02:11:06 +0200 Subject: [PATCH] Small fixes to the 'generateCache' script --- Logic/Osm/Overpass.ts | 2 +- Models/Constants.ts | 5 ++--- scripts/ScriptUtils.ts | 3 +-- scripts/generateCache.ts | 15 +++++++-------- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/Logic/Osm/Overpass.ts b/Logic/Osm/Overpass.ts index 97911a3b6d..257133307f 100644 --- a/Logic/Osm/Overpass.ts +++ b/Logic/Osm/Overpass.ts @@ -42,7 +42,7 @@ export class Overpass { } const self = this; const json = await Utils.downloadJson(query) - console.log("Got json!", json) + if (json.elements.length === 0 && json.remark !== undefined) { console.warn("Timeout or other runtime error while querying overpass", json.remark); throw `Runtime error (timeout or similar)${json.remark}` diff --git a/Models/Constants.ts b/Models/Constants.ts index 50cfcf7505..ab7c007cdb 100644 --- a/Models/Constants.ts +++ b/Models/Constants.ts @@ -12,10 +12,9 @@ export default class Constants { "https://overpass-api.de/api/interpreter", // 'Fair usage' "https://overpass.kumi.systems/api/interpreter", - // "https://overpass.nchc.org.tw/api/interpreter", + // Offline: "https://overpass.nchc.org.tw/api/interpreter", "https://overpass.openstreetmap.ru/cgi/interpreter", - // The french api, only 1000 per day per project allowed, so we put it as last resort - "https://overpass.openstreetmap.fr/api/interpreter" + // Doesn't support nwr "https://overpass.openstreetmap.fr/api/interpreter" ] diff --git a/scripts/ScriptUtils.ts b/scripts/ScriptUtils.ts index 22cdd0d931..5469b56451 100644 --- a/scripts/ScriptUtils.ts +++ b/scripts/ScriptUtils.ts @@ -53,7 +53,7 @@ export default class ScriptUtils { try { headers = headers ?? {} headers.accept = "application/json" - console.log("Fetching", url) + console.log("ScriptUtils.DownloadJson(", url.substring(0,40), url.length > 40 ? "...":"" ,")") const urlObj = new URL(url) https.get({ host: urlObj.host, @@ -72,7 +72,6 @@ export default class ScriptUtils { res.addListener('end', function () { const result = parts.join("") try { - console.log("Fetched", result) resolve(JSON.parse(result)) } catch (e) { console.error("Could not parse the following as JSON:", result) diff --git a/scripts/generateCache.ts b/scripts/generateCache.ts index e207cf67e1..1377b3153e 100644 --- a/scripts/generateCache.ts +++ b/scripts/generateCache.ts @@ -97,17 +97,16 @@ async function downloadRaw(targetdir: string, r: TileRange, theme: LayoutConfig, try { const json = await ScriptUtils.DownloadJSON(url) - if (json.elements.length === 0) { - console.log("Got an empty response!") - if ((json.remark ?? "").startsWith("runtime error")) { - console.error("Got a runtime error: ", json.remark) - failed++; - } + if ((json.remark ?? "").startsWith("runtime error")) { + console.error("Got a runtime error: ", json.remark) + failed++; + }else if (json.elements.length === 0) { + console.log("Got an empty response! Writing anyway") + } + - } else { console.log("Got the response - writing to ", filename) writeFileSync(filename, JSON.stringify(json, null, " ")); - } } catch (err) { console.log(url) console.log("Could not download - probably hit the rate limit; waiting a bit. (" + err + ")")