diff --git a/scripts/generateCache.ts b/scripts/generateCache.ts index f81d124..7e626e4 100644 --- a/scripts/generateCache.ts +++ b/scripts/generateCache.ts @@ -16,6 +16,8 @@ import * as OsmToGeoJson from "osmtogeojson"; import {Script} from "vm"; import MetaTagging from "../Logic/MetaTagging"; import State from "../State"; +import {createEvalAwarePartialHost} from "ts-node/dist/repl"; +import {fail} from "assert"; function createOverpassObject(theme: LayoutConfig) { let filters: TagsFilter[] = []; @@ -48,14 +50,15 @@ function createOverpassObject(theme: LayoutConfig) { return new Overpass(new Or(filters), extraScripts); } -function saveResponse(chunks: string[], targetDir: string) { +function saveResponse(chunks: string[], targetDir: string): boolean { const contents = chunks.join("") if (contents.startsWith(" { gotResponse = true; - saveResponse(chunks, filename) + success = saveResponse(chunks, filename) }) while (!gotResponse) { @@ -105,10 +112,21 @@ async function downloadRaw(targetdir: string, r: TileRange, overpass: Overpass) console.log("Didn't get an answer yet - waiting more") } } + + if(!success){ + failed++; + console.log("Hit the rate limit - waiting 90s") + for (let i = 0; i < 90; i++) { + console.log(90 - i) + await ScriptUtils.sleep(1000) + } + } } } + + return {failed: failed, skipped: skipped} } async function postProcess(targetdir: string, r: TileRange, theme: LayoutConfig) { @@ -189,8 +207,15 @@ async function main(args: string[]) { const overpass = createOverpassObject(theme) + let failed = 0; + do { + const cachingResult = await downloadRaw(targetdir, tileRange, overpass) + failed = cachingResult.failed + if (failed > 0) { + ScriptUtils.sleep(30000) + } + } while (failed > 0) - await downloadRaw(targetdir, tileRange, overpass) await postProcess(targetdir, tileRange, theme) }