Repository navigation
Expand file tree
/
Copy pathshow.js
More file actions
61 lines (52 loc) · 1.34 KB
/
Copy pathshow.js
File metadata and controls
61 lines (52 loc) · 1.34 KB
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
57
58
59
60
var levelup = require('levelup')
var queue = require('queue-async')
var moment = require('moment')
var db = levelup('./db')
exports.getShows = function(done) {
getShows(function(result) {
done(result)
})
}
exports.addShows = function(shows) {
addShows(shows, function() {
console.log('written')
})
}
// if there is a date on the command line, use that. else use current moment(
// command line argument should be of format YYYY-MM-DD
exports.referenceDate = function()
{
var result = moment()
if( process.argv.length === 3 )
{ result = moment( process.argv[2] ) }
return result;
}
function getShows(done) {
var showsThisWeek = []
var date = exports.referenceDate();
var today = date.toISOString().slice(0,10)
var nextWeek = date.add(7, 'days').toISOString().slice(0,10)
db.createReadStream({gte: today, lt: nextWeek})
.on('data', function(data) {
showsThisWeek.push(data.value)
})
.on('error', function(err) {
console.log('err::::'+err)
})
.on('end', function() {
done(showsThisWeek)
})
}
function addShows(shows, done) {
var q = queue(1)
shows.forEach(function (show) {
q.defer(function (cb) {
db.put(show.date + '!' + show.venue + '!' + show.title, JSON.stringify(show), function (err) {
cb(null, null)
})
})
})
q.awaitAll(function () {
console.log('putting')
})
}