-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathto-brick.js
executable file
·56 lines (49 loc) · 1.22 KB
/
to-brick.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env node
const fs = require('fs')
const path = require('path')
const H = require('highland')
const brickDb = require('to-brick')
const DATA_DIR = path.join(__dirname, 'data')
const ORGANIZATION_ID = 'nypl'
const TASKS = [
{
id: 'geotag-photo',
submissionsNeeded: 5
},
{
id: 'select-toponym',
submissionsNeeded: 1
}
]
const collections = require(path.join(DATA_DIR, 'collections.json'))
.filter((collection) => collection.include)
.map((collection) => ({
organization_id: ORGANIZATION_ID,
tasks: TASKS,
id: collection.uuid,
title: collection.title,
url: collection.url
}))
const collectionsMap = {}
collections.forEach((collection) => {
collectionsMap[collection.id] = true
})
H(fs.createReadStream(path.join(DATA_DIR, 'items.ndjson')))
.split()
.compact()
.map(JSON.parse)
.map((item) => Object.assign({
organization_id: ORGANIZATION_ID
}, item))
.filter((item) => collectionsMap[item.collection_id])
.toArray((items) => {
const tasks = TASKS
.map((task) => ({
id: task.id
}))
brickDb.addAll(tasks, collections, items, true)
.then(() => console.log('\nDone!'))
.catch((err) => {
console.error(err)
})
})