Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.2.1 #79

Merged
merged 2 commits into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Gtfsrt2LC.js

This file was deleted.

12 changes: 6 additions & 6 deletions bin/gtfsrt2json.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node

const Gtfsrt2LC = require('../lib/Gtfsrt2LC');
var program = require('commander');
import { Gtfsrt2LC } from '../lib/Gtfsrt2LC.js';
import { program } from 'commander';

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

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

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

// Set HTTP custom headers, e.g., API keys
var headers = {};
if (program.headers) {
if (program.opts().headers) {
try {
headers = JSON.parse(program.headers);
headers = JSON.parse(program.opts().headers);
} catch (err) {
console.error('Please provide a valid JSON string for the extra HTTP headers');
process.exit();
}
}

async function parse() {
let gtfsrt2lc = new Gtfsrt2LC({ path: program.realTime, headers: headers });
let gtfsrt2lc = new Gtfsrt2LC({ path: program.opts().realTime, headers: headers });
console.log(JSON.stringify(await gtfsrt2lc.parse2Json()));
}

Expand Down
38 changes: 19 additions & 19 deletions bin/gtfsrt2lc.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env node

const fs = require('fs');
const GtfsIndex = require('../lib/GtfsIndex');
const Gtfsrt2LC = require('../lib/Gtfsrt2LC');
const { Level } = require('level');
const program = require('commander');
import fs from 'fs';
import { GtfsIndex } from '../lib/GtfsIndex.js';
import { Gtfsrt2LC } from '../lib/Gtfsrt2LC.js';
import { Level } from 'level';
import { program } from 'commander';

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

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

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

if (!program.store) {
program.store = 'MemStore';
if (!program.opts().store) {
program.opts().store = 'MemStore';
}

// Load URIs template
let template = null;
try {
if (program.urisTemplate) {
template = JSON.parse(fs.readFileSync(program.urisTemplate, 'utf8'));
if (program.opts().urisTemplate) {
template = JSON.parse(fs.readFileSync(program.opts().urisTemplate, 'utf8'));
}
} catch (err) {
console.error('Please provide a valid path to a template file');
console.error("GTFS-RT to linked connections converter use --help to discover how to use it");
process.exit();
}
// Get resulting data format
const format = program.format || 'json';
const format = program.opts().format || 'json';
// Set HTTP custom headers, e.g., API keys
let headers = {};
if (program.headers) {
if (program.opts().headers) {
try {
headers = JSON.parse(program.headers);
headers = JSON.parse(program.opts().headers);
} catch (err) {
console.error(err);
console.error('Please provide a valid JSON string for the extra HTTP headers');
Expand All @@ -62,13 +62,13 @@ if (program.headers) {

// Load historic connections store (if any)
let historyDB = null;
if(program.history) {
historyDB = new Level(program.history, { valueEncoding: 'json' });
if(program.opts().history) {
historyDB = new Level(program.opts().history, { valueEncoding: 'json' });
}

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

async function processUpdate(store, grep, deduce) {
console.error("Converting the GTFS-RT feed to Linked Connections");
Expand Down Expand Up @@ -99,4 +99,4 @@ async function processUpdate(store, grep, deduce) {
}
}

processUpdate(program.store, program.grep, program.deduce);
processUpdate(program.opts().store, program.opts().grep, program.opts().deduce);
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { GtfsIndex } from './lib/GtfsIndex.js';
import { Gtfsrt2LC } from './lib/Gtfsrt2LC.js';

export default { GtfsIndex, Gtfsrt2LC };
2 changes: 1 addition & 1 deletion lib/Connections2JSONLD.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Transform } from 'stream';
import utpl from 'uri-templates';
import Utils from './Utils';
import Utils from './Utils.js';

export class Connections2JSONLD extends Transform {
constructor(streamContext, templates) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Connections2Triples.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Transform } from 'stream';
import utpl from 'uri-templates';
import Utils from './Utils';
import Utils from './Utils.js';
import { DataFactory } from "rdf-data-factory";

const df = new DataFactory();
Expand Down
2 changes: 1 addition & 1 deletion lib/GtfsIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { parse as parseCsv } from 'fast-csv';
import { deleteAsync as del } from 'del';
import childProcess from 'child_process';
import { Level } from 'level';
import Utils from './Utils';
import Utils from './Utils.js';

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

Expand Down
6 changes: 3 additions & 3 deletions lib/Gtfsrt2LC.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import gtfsrtBindings from 'gtfs-realtime-bindings';
import JSONStream from 'JSONStream';
import { StreamWriter } from 'n3';
import { format, addHours, addMinutes, addSeconds, addDays } from 'date-fns';
import { Connections2JSONLD } from './Connections2JSONLD';
import { Connections2CSV } from './Connections2CSV';
import { Connections2Triples } from './Connections2Triples';
import { Connections2JSONLD } from './Connections2JSONLD.js';
import { Connections2CSV } from './Connections2CSV.js';
import { Connections2Triples } from './Connections2Triples.js';

const readFile = util.promisify(fs.readFile);
const days = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "gtfsrt2lc",
"version": "2.2.0",
"version": "2.2.1",
"description": "Converts the GTFS-RT to Linked Connections",
"main": "./Gtfsrt2LC.js",
"main": "./index.js",
"type": "module",
"bin": {
"gtfsrt2lc": "bin/gtfsrt2lc.js",
Expand Down
Loading