Add error recovery to downloadNSI-script
This commit is contained in:
parent
bf4f5ab256
commit
e64d8884a3
2 changed files with 19 additions and 6 deletions
|
@ -111,7 +111,7 @@
|
||||||
"housekeeping": "git pull && npx update-browserslist-db@latest && npm run weblate-fix-heavy && npm run generate && npm run generate:docs && npm run generate:contributor-list && vite-node scripts/fetchLanguages.ts && vite-node scripts/generateSunnyUnlabeled.ts && npm run format && git add assets/ langs/ Docs/ **/*.ts Docs/* src/* && git commit -m 'chore: automated housekeeping...'",
|
"housekeeping": "git pull && npx update-browserslist-db@latest && npm run weblate-fix-heavy && npm run generate && npm run generate:docs && npm run generate:contributor-list && vite-node scripts/fetchLanguages.ts && vite-node scripts/generateSunnyUnlabeled.ts && npm run format && git add assets/ langs/ Docs/ **/*.ts Docs/* src/* && git commit -m 'chore: automated housekeeping...'",
|
||||||
"reuse-compliance": "reuse lint",
|
"reuse-compliance": "reuse lint",
|
||||||
"backup:images": "vite-node scripts/generateImageAnalysis.ts -- ~/data/imgur-image-backup/",
|
"backup:images": "vite-node scripts/generateImageAnalysis.ts -- ~/data/imgur-image-backup/",
|
||||||
"downloadNsiLogos": "vite-node scripts/downloadNsiLogos.ts",
|
"downloadNsiLogos": "vite-node scripts/downloadNsiLogos.ts || npm run downloadNsiLogos # This script crashes often without the possibility to correct - hence the auto retry with OR",
|
||||||
"dloadVelopark": "vite-node scripts/velopark/veloParkToGeojson.ts ",
|
"dloadVelopark": "vite-node scripts/velopark/veloParkToGeojson.ts ",
|
||||||
"compareVelopark": "vite-node scripts/velopark/compare.ts -- velopark_nonsynced_.geojson ~/Projecten/OSM/Fietsberaad/2024-02-02\\ Fietsenstallingen_OSM_met_velopark_ref.geojson\n",
|
"compareVelopark": "vite-node scripts/velopark/compare.ts -- velopark_nonsynced_.geojson ~/Projecten/OSM/Fietsberaad/2024-02-02\\ Fietsenstallingen_OSM_met_velopark_ref.geojson\n",
|
||||||
"scrapeWebsites": "vite-node scripts/importscripts/compareWebsiteData.ts -- ~/Downloads/ShopsWithWebsiteNodes.csv ~/data/scraped_websites/",
|
"scrapeWebsites": "vite-node scripts/importscripts/compareWebsiteData.ts -- ~/Downloads/ShopsWithWebsiteNodes.csv ~/data/scraped_websites/",
|
||||||
|
|
|
@ -15,7 +15,7 @@ class DownloadNsiLogos extends Script {
|
||||||
return await this.downloadLogoUnsafe(nsiItem, type, basePath)
|
return await this.downloadLogoUnsafe(nsiItem, type, basePath)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Could not download", nsiItem.displayName, "due to", e)
|
console.error("Could not download", nsiItem.displayName, "due to", e)
|
||||||
return false
|
return "error"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ class DownloadNsiLogos extends Script {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if (logos.facebook) {
|
if (logos.facebook) {
|
||||||
// Facebook logo's are generally better and square
|
// Facebook's logos are generally better and square
|
||||||
await ScriptUtils.DownloadFileTo(logos.facebook, path)
|
await ScriptUtils.DownloadFileTo(logos.facebook, path)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -88,19 +88,32 @@ class DownloadNsiLogos extends Script {
|
||||||
const items = NameSuggestionIndex.allPossible(type)
|
const items = NameSuggestionIndex.allPossible(type)
|
||||||
const basePath = "./public/assets/data/nsi/logos/"
|
const basePath = "./public/assets/data/nsi/logos/"
|
||||||
let downloadCount = 0
|
let downloadCount = 0
|
||||||
const stepcount = 100
|
const stepcount = 5
|
||||||
for (let i = 0; i < items.length; i += stepcount) {
|
for (let i = 0; i < items.length; i += stepcount) {
|
||||||
if (i % 100 === 0) {
|
if (downloadCount > 0 || i % 200 === 0) {
|
||||||
console.log(i + "/" + items.length, "downloaded " + downloadCount)
|
console.log(i + "/" + items.length, "downloaded " + downloadCount)
|
||||||
}
|
}
|
||||||
await Promise.all(
|
|
||||||
|
const results = await Promise.all(
|
||||||
Utils.TimesT(stepcount, (j) => j).map(async (j) => {
|
Utils.TimesT(stepcount, (j) => j).map(async (j) => {
|
||||||
const downloaded = await this.downloadLogo(items[i + j], type, basePath)
|
const downloaded = await this.downloadLogo(items[i + j], type, basePath)
|
||||||
if (downloaded) {
|
if (downloaded) {
|
||||||
downloadCount++
|
downloadCount++
|
||||||
}
|
}
|
||||||
|
return downloaded
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
for (let j = 0; j < results.length; j++) {
|
||||||
|
let didDownload = results[j]
|
||||||
|
if(didDownload !== "error"){
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
console.log("Retrying", items[i + j].id, type)
|
||||||
|
didDownload = await this.downloadLogo(items[i + j], type, basePath)
|
||||||
|
if(didDownload === "error"){
|
||||||
|
console.log("Failed again:", items[i + j].id)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue