-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrecord.js
executable file
·57 lines (48 loc) · 1.23 KB
/
record.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
#!/usr/bin/env node
'use strict'
const mri = require('mri')
const pkg = require('./package.json')
const argv = mri(process.argv.slice(2), {
boolean: [
'help', 'h',
'version', 'v',
]
})
if (argv.help || argv.h) {
process.stdout.write(`
Usage:
monitor-hafas … | record-hafas-data <path-to-leveldb>
Supported monitor-hafas-cli events:
departure, stopover, trip
Options:
--event-types -e Event types for record. Default: all
Examples:
monitor-hafas vbb-hafas departure stations \\
900000100001,900000100003 | record-hafas-data vbb-deps.ldb
monitor-hafas oebb-hafas stopover bbox \\
52.6 13.3 52.3 13.6 | record-hafas-data oebb-stopovers.ldb
\n`)
process.exit(0)
}
if (argv.version || argv.v) {
process.stdout.write(`record-hafas-data v${pkg.version}\n`)
process.exit(0)
}
const pump = require('pump')
const {parse} = require('ndjson')
const record = require('.')
const showError = (err) => {
if (!err) return;
console.error(err)
process.exit(1)
}
const pathToLeveldb = argv._[0]
if (!pathToLeveldb) showError('Missing path to the LevelDB.')
let eventTypes = argv['event-types'] || argv.e
if (eventTypes) eventTypes = eventTypes.split(/,\s?/)
pump(
process.stdin,
parse(),
record(pathToLeveldb, {eventTypes}),
showError
)