forked from MapComplete/MapComplete
Small fixes to the 'generateCache' script
This commit is contained in:
parent
5bcb879dfe
commit
23136f7e7a
4 changed files with 11 additions and 14 deletions
|
@ -42,7 +42,7 @@ export class Overpass {
|
||||||
}
|
}
|
||||||
const self = this;
|
const self = this;
|
||||||
const json = await Utils.downloadJson(query)
|
const json = await Utils.downloadJson(query)
|
||||||
console.log("Got json!", json)
|
|
||||||
if (json.elements.length === 0 && json.remark !== undefined) {
|
if (json.elements.length === 0 && json.remark !== undefined) {
|
||||||
console.warn("Timeout or other runtime error while querying overpass", json.remark);
|
console.warn("Timeout or other runtime error while querying overpass", json.remark);
|
||||||
throw `Runtime error (timeout or similar)${json.remark}`
|
throw `Runtime error (timeout or similar)${json.remark}`
|
||||||
|
|
|
@ -12,10 +12,9 @@ export default class Constants {
|
||||||
"https://overpass-api.de/api/interpreter",
|
"https://overpass-api.de/api/interpreter",
|
||||||
// 'Fair usage'
|
// 'Fair usage'
|
||||||
"https://overpass.kumi.systems/api/interpreter",
|
"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",
|
"https://overpass.openstreetmap.ru/cgi/interpreter",
|
||||||
// The french api, only 1000 per day per project allowed, so we put it as last resort
|
// Doesn't support nwr "https://overpass.openstreetmap.fr/api/interpreter"
|
||||||
"https://overpass.openstreetmap.fr/api/interpreter"
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ export default class ScriptUtils {
|
||||||
try {
|
try {
|
||||||
headers = headers ?? {}
|
headers = headers ?? {}
|
||||||
headers.accept = "application/json"
|
headers.accept = "application/json"
|
||||||
console.log("Fetching", url)
|
console.log("ScriptUtils.DownloadJson(", url.substring(0,40), url.length > 40 ? "...":"" ,")")
|
||||||
const urlObj = new URL(url)
|
const urlObj = new URL(url)
|
||||||
https.get({
|
https.get({
|
||||||
host: urlObj.host,
|
host: urlObj.host,
|
||||||
|
@ -72,7 +72,6 @@ export default class ScriptUtils {
|
||||||
res.addListener('end', function () {
|
res.addListener('end', function () {
|
||||||
const result = parts.join("")
|
const result = parts.join("")
|
||||||
try {
|
try {
|
||||||
console.log("Fetched", result)
|
|
||||||
resolve(JSON.parse(result))
|
resolve(JSON.parse(result))
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Could not parse the following as JSON:", result)
|
console.error("Could not parse the following as JSON:", result)
|
||||||
|
|
|
@ -97,17 +97,16 @@ async function downloadRaw(targetdir: string, r: TileRange, theme: LayoutConfig,
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const json = await ScriptUtils.DownloadJSON(url)
|
const json = await ScriptUtils.DownloadJSON(url)
|
||||||
if (json.elements.length === 0) {
|
if ((<string>json.remark ?? "").startsWith("runtime error")) {
|
||||||
console.log("Got an empty response!")
|
console.error("Got a runtime error: ", json.remark)
|
||||||
if ((<string>json.remark ?? "").startsWith("runtime error")) {
|
failed++;
|
||||||
console.error("Got a runtime error: ", json.remark)
|
}else if (json.elements.length === 0) {
|
||||||
failed++;
|
console.log("Got an empty response! Writing anyway")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} else {
|
|
||||||
console.log("Got the response - writing to ", filename)
|
console.log("Got the response - writing to ", filename)
|
||||||
writeFileSync(filename, JSON.stringify(json, null, " "));
|
writeFileSync(filename, JSON.stringify(json, null, " "));
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(url)
|
console.log(url)
|
||||||
console.log("Could not download - probably hit the rate limit; waiting a bit. (" + err + ")")
|
console.log("Could not download - probably hit the rate limit; waiting a bit. (" + err + ")")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue