Scripts: imgur to panoramax now remembers earlier used images

This commit is contained in:
Pieter Vander Vennet 2024-10-27 14:09:58 +01:00
parent 2ee15b964a
commit f60c077554

View file

@ -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<string, string> = {}
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<UploadableTag | undefined> {
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 = <OsmObject[]>(
(
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")