-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathreprocessAll.js
59 lines (50 loc) · 1.53 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
50
51
52
53
54
55
56
57
58
59
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
let toDay = list[lastRelevantIndex] || list[list.length-1]
console.log(
`monday: ${monday}
toDay: ${toDay}`)
if (prevLastDate == list[lastRelevantIndex]) {
index(
utils.jsonForDate(toDay),
utils.jsonForDate(toDay),
utils.toISODateString(monday)
)
console.log(`\n\n${monday.toDateString()} => nothing new to report`)
} else {
console.log(`\n\n${monday.toDateString()} =>
from: ${start}
lastDate: ${toDay}`)
index(
utils.jsonForDate(start),
utils.jsonForDate(toDay),
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)
}))
*/