-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
49 lines (45 loc) · 1.45 KB
/
index.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')
let lines = fs.readFileSync('record.txt', 'utf8').split('\n').filter(line => !!line)
const bracketL = '('
const bracketR = ')'
const locationConnector = '-'
const locationKeyword = '地點'
const statusKeyword = '車況'
const noteKeyword = '註'
const colon = ':'
const driver = '司機員'
const coordinator = '調度員'
const inspector = '檢查員'
const system = '系統'
let currentTime
let currentLocation
let entries = lines.map(line => {
let person
let content = line.replace(bracketL, '').replace(bracketR, '')
if(content.match(/[0-9]{2}:[0-9]{2}:[0-9]{2}/)) {
currentTime = content
return
} else if(content.indexOf(locationKeyword) > -1) {
let [trash, locationString] = content.split(colon)
let [from, to] = locationString.split(locationConnector)
currentLocation = to ? { type: 'between', from, to } : { type: 'around', at: from }
return
} else if(content.indexOf(statusKeyword) === 0) {
let [trash, status] = content.split(colon)
person = system
content = status
} else if(content.indexOf(colon) > -1) {
[person, content] = content.split(colon)
if(person === noteKeyword) {
person = system
}
}
return {
time: currentTime,
location: currentLocation,
person,
content
}
}).filter(entry => !!entry)
fs.writeFileSync('record.json', JSON.stringify(entries, null, 2))
fs.writeFileSync('record.js', 'let record = ' + JSON.stringify(entries, null, 2))