forked from MapComplete/MapComplete
chore: automated housekeeping...
This commit is contained in:
parent
ebc48f6b53
commit
e7de94576f
232 changed files with 11430 additions and 3365 deletions
|
@ -13,12 +13,12 @@ import { And } from "../../src/Logic/Tags/And"
|
|||
import { Lists } from "../../src/Utils/Lists"
|
||||
|
||||
export class FixWikimediaInImageTag extends Script {
|
||||
|
||||
constructor() {
|
||||
super("For the given bbox, queries all `image=http(s)://commons.wikimedia.org` tags and replaces it with `commons`-tagging")
|
||||
super(
|
||||
"For the given bbox, queries all `image=http(s)://commons.wikimedia.org` tags and replaces it with `commons`-tagging"
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
private handleFeature(f: Feature): ChangeTagAction {
|
||||
const p = f.properties
|
||||
const existingCommons = p["wikimedia_commons"]
|
||||
|
@ -28,19 +28,25 @@ export class FixWikimediaInImageTag extends Script {
|
|||
return undefined
|
||||
}
|
||||
|
||||
const extractedCommons: string = img.match(/^https?:\/\/commons.wikimedia.org\/wiki\/(.*)$/)[1]
|
||||
console.log("Feature " + p.id + ": " + img + ", extr " + extractedCommons + ", old: " + existingCommons)
|
||||
|
||||
const extractedCommons: string = img.match(
|
||||
/^https?:\/\/commons.wikimedia.org\/wiki\/(.*)$/
|
||||
)[1]
|
||||
console.log(
|
||||
"Feature " +
|
||||
p.id +
|
||||
": " +
|
||||
img +
|
||||
", extr " +
|
||||
extractedCommons +
|
||||
", old: " +
|
||||
existingCommons
|
||||
)
|
||||
|
||||
if (existingCommons === extractedCommons) {
|
||||
return new ChangeTagAction(id,
|
||||
new Tag("image", ""),
|
||||
p,
|
||||
{
|
||||
changeType: "cleanup",
|
||||
theme: "/"
|
||||
}
|
||||
)
|
||||
return new ChangeTagAction(id, new Tag("image", ""), p, {
|
||||
changeType: "cleanup",
|
||||
theme: "/",
|
||||
})
|
||||
}
|
||||
if (existingCommons) {
|
||||
return undefined
|
||||
|
@ -48,12 +54,16 @@ export class FixWikimediaInImageTag extends Script {
|
|||
if (!extractedCommons.startsWith("File:")) {
|
||||
return undefined
|
||||
}
|
||||
return new ChangeTagAction(id,
|
||||
new And([new Tag("image", ""), new Tag("wikimedia_commons", decodeURIComponent(extractedCommons))]),
|
||||
return new ChangeTagAction(
|
||||
id,
|
||||
new And([
|
||||
new Tag("image", ""),
|
||||
new Tag("wikimedia_commons", decodeURIComponent(extractedCommons)),
|
||||
]),
|
||||
p,
|
||||
{
|
||||
changeType: "cleanup",
|
||||
theme: "/"
|
||||
theme: "/",
|
||||
}
|
||||
)
|
||||
}
|
||||
|
@ -63,7 +73,8 @@ export class FixWikimediaInImageTag extends Script {
|
|||
if (existsSync(pth)) {
|
||||
return JSON.parse(readFileSync(pth, "utf-8"))
|
||||
}
|
||||
const overpass = new Overpass(Constants.defaultOverpassUrls[0],
|
||||
const overpass = new Overpass(
|
||||
Constants.defaultOverpassUrls[0],
|
||||
new RegexTag("image", /https?:\/\/commons.wikimedia.org/)
|
||||
)
|
||||
const [feats] = await overpass.queryGeoJson(bbox)
|
||||
|
@ -77,18 +88,17 @@ export class FixWikimediaInImageTag extends Script {
|
|||
//return
|
||||
}
|
||||
|
||||
const bbox = new BBox([3.632100582083325,
|
||||
51.11343904784337, 3.8584183481742116,
|
||||
50.99383861993195])
|
||||
const bbox = new BBox([
|
||||
3.632100582083325, 51.11343904784337, 3.8584183481742116, 50.99383861993195,
|
||||
])
|
||||
const feats = await this.fetchData(bbox)
|
||||
|
||||
const actions = Lists.noNull(feats.features.map(f => this.handleFeature(f)))
|
||||
const actions = Lists.noNull(feats.features.map((f) => this.handleFeature(f)))
|
||||
|
||||
const xml = await Changes.createChangesetXMLForJosm(actions)
|
||||
const pth = "move_image_to_wikimedia_commons_" + bbox.toLngLatFlat().join("_") + ".osc"
|
||||
writeFileSync(pth, xml, "utf-8")
|
||||
console.log("Written xml to file://" + pth)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue