Skip to content

Commit 254700c

Browse files
Merge pull request #79 from linkedconnections/development
v2.2.1
2 parents cc411a1 + 5d1b239 commit 254700c

File tree

10 files changed

+39
-39
lines changed

10 files changed

+39
-39
lines changed

Gtfsrt2LC.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

bin/gtfsrt2json.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22

3-
const Gtfsrt2LC = require('../lib/Gtfsrt2LC');
4-
var program = require('commander');
3+
import { Gtfsrt2LC } from '../lib/Gtfsrt2LC.js';
4+
import { program } from 'commander';
55

66
console.error("GTFS-RT to JSON converter use --help to discover how to use it");
77

@@ -10,24 +10,24 @@ program
1010
.option('-H --headers <headers>', 'Extra HTTP headers for requesting the gtfs files. E.g., {\\"some-header\\":\\"some-API-Key\\"}')
1111
.parse(process.argv);
1212

13-
if (!program.realTime) {
13+
if (!program.opts().realTime) {
1414
console.error('Please provide a url or a path to a GTFS-RT feed');
1515
process.exit();
1616
}
1717

1818
// Set HTTP custom headers, e.g., API keys
1919
var headers = {};
20-
if (program.headers) {
20+
if (program.opts().headers) {
2121
try {
22-
headers = JSON.parse(program.headers);
22+
headers = JSON.parse(program.opts().headers);
2323
} catch (err) {
2424
console.error('Please provide a valid JSON string for the extra HTTP headers');
2525
process.exit();
2626
}
2727
}
2828

2929
async function parse() {
30-
let gtfsrt2lc = new Gtfsrt2LC({ path: program.realTime, headers: headers });
30+
let gtfsrt2lc = new Gtfsrt2LC({ path: program.opts().realTime, headers: headers });
3131
console.log(JSON.stringify(await gtfsrt2lc.parse2Json()));
3232
}
3333

bin/gtfsrt2lc.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/env node
22

3-
const fs = require('fs');
4-
const GtfsIndex = require('../lib/GtfsIndex');
5-
const Gtfsrt2LC = require('../lib/Gtfsrt2LC');
6-
const { Level } = require('level');
7-
const program = require('commander');
3+
import fs from 'fs';
4+
import { GtfsIndex } from '../lib/GtfsIndex.js';
5+
import { Gtfsrt2LC } from '../lib/Gtfsrt2LC.js';
6+
import { Level } from 'level';
7+
import { program } from 'commander';
88

99
program
1010
.option('-r --real-time <realTime>', 'URL/path to gtfs-rt feed')
@@ -18,40 +18,40 @@ program
1818
.option('-h --history <history>', 'Path to historic Connection LevelStore for differential updates')
1919
.parse(process.argv);
2020

21-
if (!program.realTime) {
21+
if (!program.opts().realTime) {
2222
console.error('Please provide a url or a path to a GTFS-RT feed');
2323
console.error("GTFS-RT to linked connections converter use --help to discover how to use it");
2424
process.exit();
2525
}
2626

27-
if (!program.static) {
27+
if (!program.opts().static) {
2828
console.error('Please provide a url or a path to a GTFS feed');
2929
console.error("GTFS-RT to linked connections converter use --help to discover how to use it");
3030
process.exit();
3131
}
3232

33-
if (!program.store) {
34-
program.store = 'MemStore';
33+
if (!program.opts().store) {
34+
program.opts().store = 'MemStore';
3535
}
3636

3737
// Load URIs template
3838
let template = null;
3939
try {
40-
if (program.urisTemplate) {
41-
template = JSON.parse(fs.readFileSync(program.urisTemplate, 'utf8'));
40+
if (program.opts().urisTemplate) {
41+
template = JSON.parse(fs.readFileSync(program.opts().urisTemplate, 'utf8'));
4242
}
4343
} catch (err) {
4444
console.error('Please provide a valid path to a template file');
4545
console.error("GTFS-RT to linked connections converter use --help to discover how to use it");
4646
process.exit();
4747
}
4848
// Get resulting data format
49-
const format = program.format || 'json';
49+
const format = program.opts().format || 'json';
5050
// Set HTTP custom headers, e.g., API keys
5151
let headers = {};
52-
if (program.headers) {
52+
if (program.opts().headers) {
5353
try {
54-
headers = JSON.parse(program.headers);
54+
headers = JSON.parse(program.opts().headers);
5555
} catch (err) {
5656
console.error(err);
5757
console.error('Please provide a valid JSON string for the extra HTTP headers');
@@ -62,13 +62,13 @@ if (program.headers) {
6262

6363
// Load historic connections store (if any)
6464
let historyDB = null;
65-
if(program.history) {
66-
historyDB = new Level(program.history, { valueEncoding: 'json' });
65+
if(program.opts().history) {
66+
historyDB = new Level(program.opts().history, { valueEncoding: 'json' });
6767
}
6868

6969
let t0 = new Date();
70-
const gtfsrt2lc = new Gtfsrt2LC({ path: program.realTime, uris: template, headers: headers });
71-
const gtfsIndexer = new GtfsIndex({ path: program.static, headers: headers });
70+
const gtfsrt2lc = new Gtfsrt2LC({ path: program.opts().realTime, uris: template, headers: headers });
71+
const gtfsIndexer = new GtfsIndex({ path: program.opts().static, headers: headers });
7272

7373
async function processUpdate(store, grep, deduce) {
7474
console.error("Converting the GTFS-RT feed to Linked Connections");
@@ -99,4 +99,4 @@ async function processUpdate(store, grep, deduce) {
9999
}
100100
}
101101

102-
processUpdate(program.store, program.grep, program.deduce);
102+
processUpdate(program.opts().store, program.opts().grep, program.opts().deduce);

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { GtfsIndex } from './lib/GtfsIndex.js';
2+
import { Gtfsrt2LC } from './lib/Gtfsrt2LC.js';
3+
4+
export default { GtfsIndex, Gtfsrt2LC };

lib/Connections2JSONLD.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Transform } from 'stream';
22
import utpl from 'uri-templates';
3-
import Utils from './Utils';
3+
import Utils from './Utils.js';
44

55
export class Connections2JSONLD extends Transform {
66
constructor(streamContext, templates) {

lib/Connections2Triples.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Transform } from 'stream';
22
import utpl from 'uri-templates';
3-
import Utils from './Utils';
3+
import Utils from './Utils.js';
44
import { DataFactory } from "rdf-data-factory";
55

66
const df = new DataFactory();

lib/GtfsIndex.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { parse as parseCsv } from 'fast-csv';
66
import { deleteAsync as del } from 'del';
77
import childProcess from 'child_process';
88
import { Level } from 'level';
9-
import Utils from './Utils';
9+
import Utils from './Utils.js';
1010

1111
const exec = util.promisify(childProcess.exec);
1212

lib/Gtfsrt2LC.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import gtfsrtBindings from 'gtfs-realtime-bindings';
88
import JSONStream from 'JSONStream';
99
import { StreamWriter } from 'n3';
1010
import { format, addHours, addMinutes, addSeconds, addDays } from 'date-fns';
11-
import { Connections2JSONLD } from './Connections2JSONLD';
12-
import { Connections2CSV } from './Connections2CSV';
13-
import { Connections2Triples } from './Connections2Triples';
11+
import { Connections2JSONLD } from './Connections2JSONLD.js';
12+
import { Connections2CSV } from './Connections2CSV.js';
13+
import { Connections2Triples } from './Connections2Triples.js';
1414

1515
const readFile = util.promisify(fs.readFile);
1616
const days = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "gtfsrt2lc",
3-
"version": "2.2.0",
3+
"version": "2.2.1",
44
"description": "Converts the GTFS-RT to Linked Connections",
5-
"main": "./Gtfsrt2LC.js",
5+
"main": "./index.js",
66
"type": "module",
77
"bin": {
88
"gtfsrt2lc": "bin/gtfsrt2lc.js",

0 commit comments

Comments
 (0)