forked from bkardell/bcd-watch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreprocessAll.js
49 lines (41 loc) · 1.34 KB
/
reprocessAll.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
const fs = require('fs')
const index = require('./index.js').run
const entriesStore = require('./entriesStore.js')
const utils = require('./utils.js')
let result = {}
let list = entriesStore.getSortedListOfJSONEntries("./store", true).map(item => utils.dateFromISODateString(item))
let start = list[0],
end = list[1],
firstMonday = utils.findNextMonday(end),
today = new Date(),
mondays = [],
prevLastDate
for (let currentMonday = firstMonday; currentMonday <= today; currentMonday = utils.findNextMonday(currentMonday, true)) {
mondays.push(currentMonday)
}
let used = [start]
mondays.forEach(monday => {
lastRelevantIndex = list.findIndex(date => date > monday) - 1
if (prevLastDate == list[lastRelevantIndex]) {
console.log(`\n\n${monday.toDateString()} => nothing new to report`)
} else {
console.log(`\n\n${monday.toDateString()} =>
from: ${start}
lastDate: ${list[lastRelevantIndex]}`)
index(
utils.jsonForDate(start),
utils.jsonForDate(list[lastRelevantIndex]),
utils.toISODateString(monday)
)
used.push(list[lastRelevantIndex])
}
prevLastDate = list[lastRelevantIndex]
start = list[lastRelevantIndex]
})
/*
This can be used to log the ones we aren't using,
if we want to trim a bunch of them
console.log('unused: ', list.filter(item => {
return !used.includes(item)
}))
*/