forked from MapComplete/MapComplete
Scripts: imgur to panoramax now remembers earlier used images
This commit is contained in:
parent
2ee15b964a
commit
f60c077554
1 changed files with 19 additions and 9 deletions
|
@ -24,9 +24,11 @@ import { UploadableTag } from "../src/Logic/Tags/TagTypes"
|
||||||
export class ImgurToPanoramax extends Script {
|
export class ImgurToPanoramax extends Script {
|
||||||
private readonly panoramax = new PanoramaxUploader(
|
private readonly panoramax = new PanoramaxUploader(
|
||||||
Constants.panoramax.url,
|
Constants.panoramax.url,
|
||||||
Constants.panoramax.token
|
Constants.panoramax.token,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private readonly alreadyUploaded: Record<string, string> = {}
|
||||||
|
|
||||||
private _imageDirectory: string
|
private _imageDirectory: string
|
||||||
private _licenseDirectory: string
|
private _licenseDirectory: string
|
||||||
|
|
||||||
|
@ -39,7 +41,7 @@ export class ImgurToPanoramax extends Script {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super(
|
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: {
|
sequences: {
|
||||||
id: string
|
id: string
|
||||||
"stats:items": { count: number }
|
"stats:items": { count: number }
|
||||||
}[]
|
}[],
|
||||||
): Promise<UploadableTag | undefined> {
|
): Promise<UploadableTag | undefined> {
|
||||||
const v = feat.properties[key]
|
const v = feat.properties[key]
|
||||||
if (!v) {
|
if (!v) {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
const imageHash = v.split("/").at(-1).split(".").at(0)
|
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
|
let path: string = undefined
|
||||||
if (existsSync(this._imageDirectory + "/" + imageHash + ".jpg")) {
|
if (existsSync(this._imageDirectory + "/" + imageHash + ".jpg")) {
|
||||||
path = this._imageDirectory + "/" + imageHash + ".jpg"
|
path = this._imageDirectory + "/" + imageHash + ".jpg"
|
||||||
|
@ -92,7 +101,7 @@ export class ImgurToPanoramax extends Script {
|
||||||
|
|
||||||
const file = new MyFile([], path)
|
const file = new MyFile([], path)
|
||||||
|
|
||||||
file.stream = function () {
|
file.stream = function() {
|
||||||
return handle.readableWebStream()
|
return handle.readableWebStream()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,8 +111,9 @@ export class ImgurToPanoramax extends Script {
|
||||||
GeoOperations.centerpointCoordinates(feat),
|
GeoOperations.centerpointCoordinates(feat),
|
||||||
author,
|
author,
|
||||||
true,
|
true,
|
||||||
sequence
|
sequence,
|
||||||
)
|
)
|
||||||
|
this.alreadyUploaded[imageHash] = result.value
|
||||||
await handle.close()
|
await handle.close()
|
||||||
return new And([new Tag(key.replace("image", result.key), result.value), new Tag(key, "")])
|
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.6984301050112833, 51.06715570450848],
|
||||||
[3.7434328399847914, 51.039379568816145],
|
[3.7434328399847914, 51.039379568816145],
|
||||||
])
|
])
|
||||||
const maxcount = 100
|
const maxcount = 500
|
||||||
const filter = new RegexTag("image", /^https:\/\/i.imgur.com\/.*/)
|
const filter = new RegexTag("image", /^https:\/\/i.imgur.com\/.*/)
|
||||||
const overpass = new Overpass(filter, [], Constants.defaultOverpassUrls[0])
|
const overpass = new Overpass(filter, [], Constants.defaultOverpassUrls[0])
|
||||||
const features = (await overpass.queryGeoJson(bounds))[0].features
|
const features = (await overpass.queryGeoJson(bounds))[0].features
|
||||||
|
@ -146,7 +156,7 @@ export class ImgurToPanoramax extends Script {
|
||||||
{
|
{
|
||||||
theme: "image-mover",
|
theme: "image-mover",
|
||||||
changeType: "link-image",
|
changeType: "link-image",
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
changes.push(...(await action.CreateChangeDescriptions()))
|
changes.push(...(await action.CreateChangeDescriptions()))
|
||||||
converted++
|
converted++
|
||||||
|
@ -156,7 +166,7 @@ export class ImgurToPanoramax extends Script {
|
||||||
const modifiedObjectsFresh = <OsmObject[]>(
|
const modifiedObjectsFresh = <OsmObject[]>(
|
||||||
(
|
(
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
modif.map((id) => new OsmObjectDownloader().DownloadObjectAsync(id))
|
modif.map((id) => new OsmObjectDownloader().DownloadObjectAsync(id)),
|
||||||
)
|
)
|
||||||
).filter((m) => m !== "deleted")
|
).filter((m) => m !== "deleted")
|
||||||
)
|
)
|
||||||
|
@ -164,7 +174,7 @@ export class ImgurToPanoramax extends Script {
|
||||||
changes,
|
changes,
|
||||||
modifiedObjectsFresh,
|
modifiedObjectsFresh,
|
||||||
false,
|
false,
|
||||||
[]
|
[],
|
||||||
)
|
)
|
||||||
const cs = Changes.buildChangesetXML("0", modifiedObjects)
|
const cs = Changes.buildChangesetXML("0", modifiedObjects)
|
||||||
writeFileSync("imgur_to_panoramax.osc", cs, "utf8")
|
writeFileSync("imgur_to_panoramax.osc", cs, "utf8")
|
||||||
|
|
Loading…
Reference in a new issue