-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathscrape.js
29 lines (27 loc) · 857 Bytes
/
scrape.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
var conf = require('rc')('marvel-characters')
var api = require('marvel-comics-api-stream')
var fs = require('fs')
var path = require('path')
var clean = require('./clean')
var date = require('dateformat')
var list = []
var comma = require('comma-number')
api('characters', {
privateKey: conf.privateKey,
publicKey: conf.publicKey,
query: {
limit: 100
}
}).on('data', function (character) {
console.log(character.name)
list.push(character.name)
}).on('end', function () {
var file = path.resolve(__dirname, '..', 'characters.json')
list = clean(list)
console.log("Writing to file: %s", file)
console.log("**Total Characters:** %d", comma(list.length))
console.log("**Last Updated:** %s.", date(new Date(), 'dddd, mmmm dS, yyyy'))
fs.writeFile(file, JSON.stringify(list, null, 2), function (err) {
if (err) throw err
})
})