-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopulate.js
More file actions
29 lines (27 loc) · 819 Bytes
/
populate.js
File metadata and controls
29 lines (27 loc) · 819 Bytes
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
const db = require('level')('./db')
const fs = require('fs')
const path = require('path')
const urlencode = require('urlencode')
const {gray, yellow} = require('chalk')
const {sum} = require('lodash')
db.createKeyStream()
.on('data', async (name) => {
const dataFile = path.join(__dirname, '../sourceranks/data', urlencode(name) + '.json')
let data = {}
if (fs.existsSync(dataFile)) {
const scores = require(dataFile)
data = Object.assign({}, data, {
scores: scores,
total: sum(Object.values(scores))
})
process.stdout.write(gray('x'))
} else {
data.notFound = true
process.stdout.write(yellow('x'))
}
data.updatedAt = new Date()
await db.put(name, JSON.stringify(data, null, 2))
})
.on('end', () => {
console.log('done')
})