From f60c077554bde83350b7616a529ae5c98c6a0eb4 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Sun, 27 Oct 2024 14:09:58 +0100 Subject: [PATCH] Scripts: imgur to panoramax now remembers earlier used images --- scripts/ImgurToPanoramax.ts | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/scripts/ImgurToPanoramax.ts b/scripts/ImgurToPanoramax.ts index 253cc1500..551b202ba 100644 --- a/scripts/ImgurToPanoramax.ts +++ b/scripts/ImgurToPanoramax.ts @@ -24,9 +24,11 @@ import { UploadableTag } from "../src/Logic/Tags/TagTypes" export class ImgurToPanoramax extends Script { private readonly panoramax = new PanoramaxUploader( Constants.panoramax.url, - Constants.panoramax.token + Constants.panoramax.token, ) + private readonly alreadyUploaded: Record = {} + private _imageDirectory: string private _licenseDirectory: string @@ -39,7 +41,7 @@ export class ImgurToPanoramax extends Script { constructor() { super( - "Queries OSM for 'imgur'-images, uploads them to Panoramax and creates a changeset to update OSM" + "Queries OSM for 'imgur'-images, uploads them to Panoramax and creates a changeset to update OSM", ) } @@ -49,13 +51,20 @@ export class ImgurToPanoramax extends Script { sequences: { id: string "stats:items": { count: number } - }[] + }[], ): Promise { const v = feat.properties[key] if (!v) { return undefined } const imageHash = v.split("/").at(-1).split(".").at(0) + + if (this.alreadyUploaded[imageHash]) { + const panohash = this.alreadyUploaded[imageHash] + return new And([new Tag(key.replace("image", panohash), panohash), new Tag(key, "")]) + } + + let path: string = undefined if (existsSync(this._imageDirectory + "/" + imageHash + ".jpg")) { path = this._imageDirectory + "/" + imageHash + ".jpg" @@ -92,7 +101,7 @@ export class ImgurToPanoramax extends Script { const file = new MyFile([], path) - file.stream = function () { + file.stream = function() { return handle.readableWebStream() } @@ -102,8 +111,9 @@ export class ImgurToPanoramax extends Script { GeoOperations.centerpointCoordinates(feat), author, true, - sequence + sequence, ) + this.alreadyUploaded[imageHash] = result.value await handle.close() return new And([new Tag(key.replace("image", result.key), result.value), new Tag(key, "")]) } @@ -116,7 +126,7 @@ export class ImgurToPanoramax extends Script { [3.6984301050112833, 51.06715570450848], [3.7434328399847914, 51.039379568816145], ]) - const maxcount = 100 + const maxcount = 500 const filter = new RegexTag("image", /^https:\/\/i.imgur.com\/.*/) const overpass = new Overpass(filter, [], Constants.defaultOverpassUrls[0]) const features = (await overpass.queryGeoJson(bounds))[0].features @@ -146,7 +156,7 @@ export class ImgurToPanoramax extends Script { { theme: "image-mover", changeType: "link-image", - } + }, ) changes.push(...(await action.CreateChangeDescriptions())) converted++ @@ -156,7 +166,7 @@ export class ImgurToPanoramax extends Script { const modifiedObjectsFresh = ( ( await Promise.all( - modif.map((id) => new OsmObjectDownloader().DownloadObjectAsync(id)) + modif.map((id) => new OsmObjectDownloader().DownloadObjectAsync(id)), ) ).filter((m) => m !== "deleted") ) @@ -164,7 +174,7 @@ export class ImgurToPanoramax extends Script { changes, modifiedObjectsFresh, false, - [] + [], ) const cs = Changes.buildChangesetXML("0", modifiedObjects) writeFileSync("imgur_to_panoramax.osc", cs, "utf8")