-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbatches.js
executable file
·41 lines (33 loc) · 1.16 KB
/
batches.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env node
import fs from 'fs'
import url from 'url'
import path from 'path'
import JSONStream from 'JSONStream'
import H from 'highland'
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
const features = fs
.createReadStream('./data/dighimapper.geojson')
.pipe(JSONStream.parse('features.*'))
async function downloadImageInfo(feature) {
const batch = feature.properties.batch
const id = feature.properties.identifier
const imageUri = `https://images.dighimapper.eu/iiif/2/${id}.tif`
const imageInfoUrl = `${imageUri}/info.json`
let imageInfo
try {
console.error(`Downloading for batch ${batch}:`, imageInfoUrl)
imageInfo = await fetch(imageInfoUrl).then((response) => response.json())
} catch (err) {
console.error(`Error fetching for batch ${batch}:`, imageInfoUrl)
return
}
const dir = path.join(__dirname, 'batches', String(batch))
const filename = path.join(dir, `${id}.info.json`)
fs.mkdirSync(dir, { recursive: true })
fs.writeFileSync(filename, JSON.stringify(imageInfo, null, 2))
}
H(features)
.flatMap((feature) => H(downloadImageInfo(feature)))
.done(() => {
console.log('Done...')
})