gtfs 3.1.3 → 3.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +14 -19
- package/.husky/pre-commit +4 -0
- package/.prettierrc.js +4 -0
- package/CHANGELOG.md +156 -0
- package/README.md +113 -126
- package/bin/gtfs-export.js +4 -5
- package/bin/gtfs-import.js +6 -7
- package/config-sample-full.json +2 -7
- package/lib/db.js +4 -2
- package/lib/export.js +26 -9
- package/lib/file-utils.js +26 -9
- package/lib/geojson-utils.js +51 -38
- package/lib/gtfs/agencies.js +8 -2
- package/lib/gtfs/attributions.js +8 -2
- package/lib/gtfs/calendar-dates.js +8 -2
- package/lib/gtfs/calendars.js +8 -2
- package/lib/gtfs/fare-attributes.js +8 -2
- package/lib/gtfs/fare-rules.js +8 -2
- package/lib/gtfs/feed-info.js +8 -2
- package/lib/gtfs/frequencies.js +8 -2
- package/lib/gtfs/levels.js +8 -2
- package/lib/gtfs/pathways.js +8 -2
- package/lib/gtfs/routes.js +15 -4
- package/lib/gtfs/shapes.js +49 -18
- package/lib/gtfs/stop-times.js +8 -2
- package/lib/gtfs/stops.js +45 -16
- package/lib/gtfs/transfers.js +8 -2
- package/lib/gtfs/translations.js +8 -2
- package/lib/gtfs/trips.js +8 -2
- package/lib/gtfs-ride/board-alights.js +8 -2
- package/lib/gtfs-ride/ride-feed-infos.js +8 -2
- package/lib/gtfs-ride/rider-trips.js +8 -2
- package/lib/gtfs-ride/riderships.js +8 -2
- package/lib/gtfs-ride/trip-capacities.js +8 -2
- package/lib/import.js +198 -123
- package/lib/log-utils.js +8 -4
- package/lib/non-standard/directions.js +8 -2
- package/lib/non-standard/stop-attributes.js +8 -2
- package/lib/non-standard/timetable-notes-references.js +13 -3
- package/lib/non-standard/timetable-notes.js +8 -2
- package/lib/non-standard/timetable-pages.js +8 -2
- package/lib/non-standard/timetable-stop-order.js +13 -3
- package/lib/non-standard/timetables.js +8 -2
- package/lib/utils.js +22 -11
- package/models/gtfs/agency.js +11 -11
- package/models/gtfs/attributions.js +14 -14
- package/models/gtfs/calendar-dates.js +7 -7
- package/models/gtfs/calendar.js +12 -12
- package/models/gtfs/fare-attributes.js +9 -9
- package/models/gtfs/fare-rules.js +8 -8
- package/models/gtfs/feed-info.js +12 -12
- package/models/gtfs/frequencies.js +10 -10
- package/models/gtfs/levels.js +5 -5
- package/models/gtfs/pathways.js +14 -14
- package/models/gtfs/routes.js +14 -14
- package/models/gtfs/shapes.js +8 -8
- package/models/gtfs/stop-times.js +17 -17
- package/models/gtfs/stops.js +17 -17
- package/models/gtfs/transfers.js +7 -7
- package/models/gtfs/translations.js +10 -10
- package/models/gtfs/trips.js +12 -12
- package/models/gtfs-ride/board-alight.js +24 -24
- package/models/gtfs-ride/ride-feed-info.js +8 -8
- package/models/gtfs-ride/rider-trip.js +21 -21
- package/models/gtfs-ride/ridership.js +23 -23
- package/models/gtfs-ride/trip-capacity.js +10 -10
- package/models/models.js +1 -1
- package/models/non-standard/directions.js +6 -6
- package/models/non-standard/stop-attributes.js +5 -5
- package/models/non-standard/timetable-notes-references.js +9 -9
- package/models/non-standard/timetable-notes.js +5 -5
- package/models/non-standard/timetable-pages.js +5 -5
- package/models/non-standard/timetable-stop-order.js +6 -6
- package/models/non-standard/timetables.js +27 -27
- package/package.json +10 -2
- package/test/mocha/export-gtfs.js +63 -40
- package/test/mocha/get-agencies.js +11 -11
- package/test/mocha/get-attributions.js +1 -1
- package/test/mocha/get-board-alights.js +1 -1
- package/test/mocha/get-calendar-dates.js +22 -21
- package/test/mocha/get-calendars.js +8 -8
- package/test/mocha/get-db.js +9 -2
- package/test/mocha/get-directions.js +1 -1
- package/test/mocha/get-fare-attributes.js +3 -3
- package/test/mocha/get-fare-rules.js +8 -10
- package/test/mocha/get-feed-info.js +1 -1
- package/test/mocha/get-frequencies.js +1 -1
- package/test/mocha/get-levels.js +1 -1
- package/test/mocha/get-pathways.js +1 -1
- package/test/mocha/get-rider-trips.js +1 -1
- package/test/mocha/get-riderships.js +1 -1
- package/test/mocha/get-routes.js +9 -13
- package/test/mocha/get-shapes-as-geojson.js +3 -3
- package/test/mocha/get-shapes.js +28 -36
- package/test/mocha/get-stop-attributes.js +1 -1
- package/test/mocha/get-stops-as-geojson.js +2 -2
- package/test/mocha/get-stops.js +59 -48
- package/test/mocha/get-stoptimes.js +9 -7
- package/test/mocha/get-timetable-pages.js +1 -1
- package/test/mocha/get-timetable-stop-orders.js +1 -1
- package/test/mocha/get-timetables.js +1 -1
- package/test/mocha/get-transfers.js +1 -1
- package/test/mocha/get-translations.js +1 -1
- package/test/mocha/get-trip-capacities.js +1 -1
- package/test/mocha/get-trips.js +3 -3
- package/test/mocha/import-gtfs.js +59 -42
- package/test/test-config.js +9 -4
package/README.md
CHANGED
|
@@ -36,12 +36,12 @@ If you are using this as a node module as part of an application, you can includ
|
|
|
36
36
|
|
|
37
37
|
gtfs-import --gtfsUrl http://www.bart.gov/dev/schedules/google_transit.zip
|
|
38
38
|
|
|
39
|
-
or
|
|
40
|
-
|
|
39
|
+
or
|
|
40
|
+
|
|
41
41
|
gtfs-import --gtfsPath /path/to/your/gtfs.zip
|
|
42
42
|
|
|
43
|
-
or
|
|
44
|
-
|
|
43
|
+
or
|
|
44
|
+
|
|
45
45
|
gtfs-import --gtfsPath /path/to/your/unzipped/gtfs
|
|
46
46
|
|
|
47
47
|
or
|
|
@@ -55,15 +55,17 @@ or
|
|
|
55
55
|
```js
|
|
56
56
|
import { importGtfs } from 'gtfs';
|
|
57
57
|
import { readFile } from 'fs/promises';
|
|
58
|
-
const config = JSON.parse(
|
|
58
|
+
const config = JSON.parse(
|
|
59
|
+
await readFile(new URL('./config.json', import.meta.url))
|
|
60
|
+
);
|
|
59
61
|
|
|
60
62
|
importGtfs(config)
|
|
61
|
-
.then(() => {
|
|
62
|
-
|
|
63
|
-
})
|
|
64
|
-
.catch(err => {
|
|
65
|
-
|
|
66
|
-
});
|
|
63
|
+
.then(() => {
|
|
64
|
+
console.log('Import Successful');
|
|
65
|
+
})
|
|
66
|
+
.catch((err) => {
|
|
67
|
+
console.error(err);
|
|
68
|
+
});
|
|
67
69
|
```
|
|
68
70
|
|
|
69
71
|
## Command Line Usage
|
|
@@ -86,14 +88,14 @@ Specify a local path to GTFS, either zipped or unzipped.
|
|
|
86
88
|
|
|
87
89
|
gtfs-import --gtfsPath /path/to/your/gtfs.zip
|
|
88
90
|
|
|
89
|
-
or
|
|
90
|
-
|
|
91
|
+
or
|
|
92
|
+
|
|
91
93
|
gtfs-import --gtfsPath /path/to/your/unzipped/gtfs
|
|
92
94
|
|
|
93
95
|
`gtfsUrl`
|
|
94
96
|
|
|
95
97
|
Specify a URL to a zipped GTFS file.
|
|
96
|
-
|
|
98
|
+
|
|
97
99
|
gtfs-import --gtfsUrl http://www.bart.gov/dev/schedules/google_transit.zip
|
|
98
100
|
|
|
99
101
|
## Configuration Files
|
|
@@ -102,13 +104,13 @@ Copy `config-sample.json` to `config.json` and then add your projects configurat
|
|
|
102
104
|
|
|
103
105
|
cp config-sample.json config.json
|
|
104
106
|
|
|
105
|
-
| option
|
|
106
|
-
|
|
|
107
|
-
| [`agencies`](#agencies)
|
|
108
|
-
| [`csvOptions`](#csvOptions) | object
|
|
109
|
-
| [`exportPath`](#exportPath) | string
|
|
110
|
-
| [`sqlitePath`](#sqlitePath) | string
|
|
111
|
-
| [`verbose`](#verbose)
|
|
107
|
+
| option | type | description |
|
|
108
|
+
| --------------------------- | ------- | ---------------------------------------------------------------------------------------------------- |
|
|
109
|
+
| [`agencies`](#agencies) | array | An array of GTFS files to be imported. |
|
|
110
|
+
| [`csvOptions`](#csvOptions) | object | Options passed to `csv-parse` for parsing GTFS CSV files. Optional. |
|
|
111
|
+
| [`exportPath`](#exportPath) | string | A path to a directory to put exported GTFS files. Optional, defaults to `gtfs-export/<agency_name>`. |
|
|
112
|
+
| [`sqlitePath`](#sqlitePath) | string | A path to an SQLite database. Optional, defaults to using an in-memory database. |
|
|
113
|
+
| [`verbose`](#verbose) | boolean | Whether or not to print output to the console. Optional, defaults to true. |
|
|
112
114
|
|
|
113
115
|
### agencies
|
|
114
116
|
|
|
@@ -120,7 +122,8 @@ To find an agency's GTFS file, visit [transitfeeds.com](http://transitfeeds.com)
|
|
|
120
122
|
URL from the agency's website or you can use a URL generated from the transitfeeds.com
|
|
121
123
|
API along with your API token.
|
|
122
124
|
|
|
123
|
-
|
|
125
|
+
- Specify a download URL:
|
|
126
|
+
|
|
124
127
|
```json
|
|
125
128
|
{
|
|
126
129
|
"agencies": [
|
|
@@ -131,7 +134,8 @@ API along with your API token.
|
|
|
131
134
|
}
|
|
132
135
|
```
|
|
133
136
|
|
|
134
|
-
|
|
137
|
+
- Specify a download URL with custom headers:
|
|
138
|
+
|
|
135
139
|
```json
|
|
136
140
|
{
|
|
137
141
|
"agencies": [
|
|
@@ -140,13 +144,14 @@ API along with your API token.
|
|
|
140
144
|
"headers": {
|
|
141
145
|
"Content-Type": "application/json",
|
|
142
146
|
"Authorization": "bearer 1234567890"
|
|
143
|
-
}
|
|
147
|
+
}
|
|
144
148
|
}
|
|
145
149
|
]
|
|
146
150
|
}
|
|
147
151
|
```
|
|
148
152
|
|
|
149
|
-
|
|
153
|
+
- Specify a path to a zipped GTFS file:
|
|
154
|
+
|
|
150
155
|
```json
|
|
151
156
|
{
|
|
152
157
|
"agencies": [
|
|
@@ -156,7 +161,9 @@ API along with your API token.
|
|
|
156
161
|
]
|
|
157
162
|
}
|
|
158
163
|
```
|
|
159
|
-
|
|
164
|
+
|
|
165
|
+
- Specify a path to an unzipped GTFS file:
|
|
166
|
+
|
|
160
167
|
```json
|
|
161
168
|
{
|
|
162
169
|
"agencies": [
|
|
@@ -167,23 +174,20 @@ API along with your API token.
|
|
|
167
174
|
}
|
|
168
175
|
```
|
|
169
176
|
|
|
170
|
-
|
|
177
|
+
- Exclude files - if you don't want all GTFS files to be imported, you can specify an array of files to exclude.
|
|
171
178
|
|
|
172
179
|
```json
|
|
173
180
|
{
|
|
174
181
|
"agencies": [
|
|
175
182
|
{
|
|
176
183
|
"path": "/path/to/the/unzipped/gtfs/",
|
|
177
|
-
"exclude": [
|
|
178
|
-
"shapes",
|
|
179
|
-
"stops"
|
|
180
|
-
]
|
|
184
|
+
"exclude": ["shapes", "stops"]
|
|
181
185
|
}
|
|
182
186
|
]
|
|
183
187
|
}
|
|
184
188
|
```
|
|
185
189
|
|
|
186
|
-
|
|
190
|
+
- Specify multiple agencies to be imported into the same database
|
|
187
191
|
|
|
188
192
|
```json
|
|
189
193
|
{
|
|
@@ -239,7 +243,7 @@ See [full list of options](https://csv.js.org/parse/options/).
|
|
|
239
243
|
}
|
|
240
244
|
```
|
|
241
245
|
|
|
242
|
-
If you want to route logs to a custom function, you can pass a function that takes a single `text` argument as `logFunction`. This can't be defined in `config.json` but instead passed in a config object to `importGtfs()`.
|
|
246
|
+
If you want to route logs to a custom function, you can pass a function that takes a single `text` argument as `logFunction`. This can't be defined in `config.json` but instead passed in a config object to `importGtfs()`. For example:
|
|
243
247
|
|
|
244
248
|
```js
|
|
245
249
|
import { importGtfs } from 'gtfs';
|
|
@@ -248,15 +252,13 @@ const config = {
|
|
|
248
252
|
agencies: [
|
|
249
253
|
{
|
|
250
254
|
url: 'http://countyconnection.com/GTFS/google_transit.zip',
|
|
251
|
-
exclude: [
|
|
252
|
-
|
|
253
|
-
]
|
|
254
|
-
}
|
|
255
|
+
exclude: ['shapes'],
|
|
256
|
+
},
|
|
255
257
|
],
|
|
256
|
-
logFunction: function(text) {
|
|
258
|
+
logFunction: function (text) {
|
|
257
259
|
// Do something with the logs here, like save it or send it somewhere
|
|
258
260
|
console.log(text);
|
|
259
|
-
}
|
|
261
|
+
},
|
|
260
262
|
};
|
|
261
263
|
|
|
262
264
|
importGtfs(config);
|
|
@@ -282,15 +284,17 @@ Use `importGtfs()` in your code to run an import of a GTFS file specified in a c
|
|
|
282
284
|
import { importGtfs } from 'gtfs';
|
|
283
285
|
import { readFile } from 'fs/promises';
|
|
284
286
|
|
|
285
|
-
const config = JSON.parse(
|
|
287
|
+
const config = JSON.parse(
|
|
288
|
+
await readFile(new URL('./config.json', import.meta.url))
|
|
289
|
+
);
|
|
286
290
|
|
|
287
291
|
importGtfs(config)
|
|
288
|
-
.then(() => {
|
|
289
|
-
|
|
290
|
-
})
|
|
291
|
-
.catch(err => {
|
|
292
|
-
|
|
293
|
-
});
|
|
292
|
+
.then(() => {
|
|
293
|
+
console.log('Import Successful');
|
|
294
|
+
})
|
|
295
|
+
.catch((err) => {
|
|
296
|
+
console.error(err);
|
|
297
|
+
});
|
|
294
298
|
```
|
|
295
299
|
|
|
296
300
|
Configuration can be a JSON object in your code
|
|
@@ -303,20 +307,18 @@ const config = {
|
|
|
303
307
|
agencies: [
|
|
304
308
|
{
|
|
305
309
|
url: 'http://countyconnection.com/GTFS/google_transit.zip',
|
|
306
|
-
exclude: [
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
}
|
|
310
|
-
]
|
|
310
|
+
exclude: ['shapes'],
|
|
311
|
+
},
|
|
312
|
+
],
|
|
311
313
|
};
|
|
312
314
|
|
|
313
315
|
importGtfs(config)
|
|
314
|
-
.then(() => {
|
|
315
|
-
|
|
316
|
-
})
|
|
317
|
-
.catch(err => {
|
|
318
|
-
|
|
319
|
-
});
|
|
316
|
+
.then(() => {
|
|
317
|
+
console.log('Import Successful');
|
|
318
|
+
})
|
|
319
|
+
.catch((err) => {
|
|
320
|
+
console.error(err);
|
|
321
|
+
});
|
|
320
322
|
```
|
|
321
323
|
|
|
322
324
|
## `gtfs-export` Script
|
|
@@ -340,11 +342,13 @@ By default, it will look for a `config.json` file in the project root. To specif
|
|
|
340
342
|
### Command Line options
|
|
341
343
|
|
|
342
344
|
#### Specify path to config JSON file
|
|
345
|
+
|
|
343
346
|
You can specify the path to a config file to be used by the export script.
|
|
344
347
|
|
|
345
348
|
gtfs-export --configPath /path/to/your/custom-config.json
|
|
346
349
|
|
|
347
350
|
#### Show help
|
|
351
|
+
|
|
348
352
|
Show all command line options
|
|
349
353
|
|
|
350
354
|
gtfs-export --help
|
|
@@ -361,20 +365,18 @@ const config = {
|
|
|
361
365
|
agencies: [
|
|
362
366
|
{
|
|
363
367
|
url: 'http://countyconnection.com/GTFS/google_transit.zip',
|
|
364
|
-
exclude: [
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
}
|
|
368
|
-
]
|
|
368
|
+
exclude: ['shapes'],
|
|
369
|
+
},
|
|
370
|
+
],
|
|
369
371
|
};
|
|
370
372
|
|
|
371
373
|
exportGtfs(config)
|
|
372
|
-
.then(() => {
|
|
373
|
-
|
|
374
|
-
})
|
|
375
|
-
.catch(err => {
|
|
376
|
-
|
|
377
|
-
});
|
|
374
|
+
.then(() => {
|
|
375
|
+
console.log('Export Successful');
|
|
376
|
+
})
|
|
377
|
+
.catch((err) => {
|
|
378
|
+
console.error(err);
|
|
379
|
+
});
|
|
378
380
|
```
|
|
379
381
|
|
|
380
382
|
## Query Methods
|
|
@@ -390,19 +392,15 @@ For example, to get a list of all routes with just `route_id`, `route_short_name
|
|
|
390
392
|
```js
|
|
391
393
|
import { openDb, getRoutes } from 'gtfs';
|
|
392
394
|
import { readFile } from 'fs/promises';
|
|
393
|
-
const config = JSON.parse(
|
|
395
|
+
const config = JSON.parse(
|
|
396
|
+
await readFile(new URL('./config.json', import.meta.url))
|
|
397
|
+
);
|
|
394
398
|
|
|
395
399
|
const db = await openDb(config);
|
|
396
400
|
const routes = await getRoutes(
|
|
397
401
|
{},
|
|
398
|
-
[
|
|
399
|
-
|
|
400
|
-
'route_short_name',
|
|
401
|
-
'route_color'
|
|
402
|
-
],
|
|
403
|
-
[
|
|
404
|
-
['route_short_name', 'ASC']
|
|
405
|
-
]
|
|
402
|
+
['route_id', 'route_short_name', 'route_color'],
|
|
403
|
+
[['route_short_name', 'ASC']]
|
|
406
404
|
);
|
|
407
405
|
```
|
|
408
406
|
|
|
@@ -411,16 +409,16 @@ To get a list of all trip_ids for a specific route:
|
|
|
411
409
|
```js
|
|
412
410
|
import { openDb, getTrips } from 'gtfs';
|
|
413
411
|
import { readFile } from 'fs/promises';
|
|
414
|
-
const config = JSON.parse(
|
|
412
|
+
const config = JSON.parse(
|
|
413
|
+
await readFile(new URL('./config.json', import.meta.url))
|
|
414
|
+
);
|
|
415
415
|
|
|
416
416
|
const db = await openDb(config);
|
|
417
417
|
const trips = await getTrips(
|
|
418
418
|
{
|
|
419
|
-
route_id: '123'
|
|
419
|
+
route_id: '123',
|
|
420
420
|
},
|
|
421
|
-
[
|
|
422
|
-
'trip_id'
|
|
423
|
-
]
|
|
421
|
+
['trip_id']
|
|
424
422
|
);
|
|
425
423
|
```
|
|
426
424
|
|
|
@@ -469,7 +467,7 @@ getAgencies();
|
|
|
469
467
|
|
|
470
468
|
// Get a specific agency
|
|
471
469
|
getAgencies({
|
|
472
|
-
agency_id: 'caltrain'
|
|
470
|
+
agency_id: 'caltrain',
|
|
473
471
|
});
|
|
474
472
|
```
|
|
475
473
|
|
|
@@ -485,7 +483,7 @@ getAttributions();
|
|
|
485
483
|
|
|
486
484
|
// Get a specific attribution
|
|
487
485
|
getAttributions({
|
|
488
|
-
attribution_id: '123'
|
|
486
|
+
attribution_id: '123',
|
|
489
487
|
});
|
|
490
488
|
```
|
|
491
489
|
|
|
@@ -497,17 +495,11 @@ Queries routes and returns a promise. The result of the promise is an array of r
|
|
|
497
495
|
import { getRoutes } from 'gtfs';
|
|
498
496
|
|
|
499
497
|
// Get all routes, sorted by route_short_name
|
|
500
|
-
getRoutes(
|
|
501
|
-
{},
|
|
502
|
-
[],
|
|
503
|
-
[
|
|
504
|
-
['route_short_name', 'ASC']
|
|
505
|
-
]
|
|
506
|
-
);
|
|
498
|
+
getRoutes({}, [], [['route_short_name', 'ASC']]);
|
|
507
499
|
|
|
508
500
|
// Get a specific route
|
|
509
501
|
getRoutes({
|
|
510
|
-
route_id: 'Lo-16APR'
|
|
502
|
+
route_id: 'Lo-16APR',
|
|
511
503
|
});
|
|
512
504
|
```
|
|
513
505
|
|
|
@@ -519,12 +511,10 @@ import { getRoutes } from 'gtfs';
|
|
|
519
511
|
// Get routes that serve a specific stop, sorted by `stop_name`.
|
|
520
512
|
getRoutes(
|
|
521
513
|
{
|
|
522
|
-
stop_id: '70011'
|
|
514
|
+
stop_id: '70011',
|
|
523
515
|
},
|
|
524
516
|
[],
|
|
525
|
-
[
|
|
526
|
-
['stop_name', 'ASC']
|
|
527
|
-
]
|
|
517
|
+
[['stop_name', 'ASC']]
|
|
528
518
|
);
|
|
529
519
|
```
|
|
530
520
|
|
|
@@ -540,7 +530,7 @@ getStops();
|
|
|
540
530
|
|
|
541
531
|
// Get a specific stop by stop_id
|
|
542
532
|
getStops({
|
|
543
|
-
stop_id: '70011'
|
|
533
|
+
stop_id: '70011',
|
|
544
534
|
});
|
|
545
535
|
```
|
|
546
536
|
|
|
@@ -551,7 +541,7 @@ import { getRoutes } from 'gtfs';
|
|
|
551
541
|
|
|
552
542
|
// Get all stops for a specific route
|
|
553
543
|
getStops({
|
|
554
|
-
route_id: 'Lo-16APR'
|
|
544
|
+
route_id: 'Lo-16APR',
|
|
555
545
|
});
|
|
556
546
|
```
|
|
557
547
|
|
|
@@ -562,7 +552,7 @@ import { getRoutes } from 'gtfs';
|
|
|
562
552
|
|
|
563
553
|
// Get all stops for a specific trip
|
|
564
554
|
getStops({
|
|
565
|
-
trip_id: '37a'
|
|
555
|
+
trip_id: '37a',
|
|
566
556
|
});
|
|
567
557
|
```
|
|
568
558
|
|
|
@@ -578,7 +568,7 @@ getStopsAsGeoJSON();
|
|
|
578
568
|
|
|
579
569
|
// Get all stops for a specific route as geoJSON
|
|
580
570
|
getStopsAsGeoJSON({
|
|
581
|
-
route_id: 'Lo-16APR'
|
|
571
|
+
route_id: 'Lo-16APR',
|
|
582
572
|
});
|
|
583
573
|
```
|
|
584
574
|
|
|
@@ -594,24 +584,22 @@ getStoptimes();
|
|
|
594
584
|
|
|
595
585
|
// Get all stoptimes for a specific stop
|
|
596
586
|
getStoptimes({
|
|
597
|
-
stop_id: '70011'
|
|
587
|
+
stop_id: '70011',
|
|
598
588
|
});
|
|
599
589
|
|
|
600
590
|
// Get all stoptimes for a specific trip, sorted by stop_sequence
|
|
601
591
|
getStoptimes(
|
|
602
592
|
{
|
|
603
|
-
trip_id: '37a'
|
|
593
|
+
trip_id: '37a',
|
|
604
594
|
},
|
|
605
595
|
[],
|
|
606
|
-
[
|
|
607
|
-
['stop_sequence', 'ASC']
|
|
608
|
-
]
|
|
596
|
+
[['stop_sequence', 'ASC']]
|
|
609
597
|
);
|
|
610
598
|
|
|
611
599
|
// Get all stoptimes for a specific stop and service_id
|
|
612
600
|
getStoptimes({
|
|
613
601
|
stop_id: '70011',
|
|
614
|
-
service_id: 'CT-16APR-Caltrain-Weekday-01'
|
|
602
|
+
service_id: 'CT-16APR-Caltrain-Weekday-01',
|
|
615
603
|
});
|
|
616
604
|
```
|
|
617
605
|
|
|
@@ -657,7 +645,7 @@ getShapes();
|
|
|
657
645
|
```
|
|
658
646
|
|
|
659
647
|
`getShapes` allows passing a `route_id` in the query and it will query trips to find all shapes served by that `route_id`.
|
|
660
|
-
|
|
648
|
+
|
|
661
649
|
```js
|
|
662
650
|
import { getShapes } from 'gtfs';
|
|
663
651
|
|
|
@@ -674,7 +662,7 @@ import { getShapes } from 'gtfs';
|
|
|
674
662
|
|
|
675
663
|
// Get all shapes for a specific trip_id
|
|
676
664
|
getShapes({
|
|
677
|
-
trip_id: '37a'
|
|
665
|
+
trip_id: '37a',
|
|
678
666
|
});
|
|
679
667
|
```
|
|
680
668
|
|
|
@@ -703,17 +691,17 @@ getShapesAsGeoJSON();
|
|
|
703
691
|
|
|
704
692
|
// Get geoJSON of stops along a specific route
|
|
705
693
|
getShapesAsGeoJSON({
|
|
706
|
-
route_id: 'Lo-16APR'
|
|
694
|
+
route_id: 'Lo-16APR',
|
|
707
695
|
});
|
|
708
696
|
|
|
709
697
|
// Get geoJSON of stops for a specific trip
|
|
710
698
|
getShapesAsGeoJSON({
|
|
711
|
-
trip_id: '37a'
|
|
699
|
+
trip_id: '37a',
|
|
712
700
|
});
|
|
713
701
|
|
|
714
702
|
// Get geoJSON of stops for a specific `service_id`
|
|
715
703
|
getShapesAsGeoJSON({
|
|
716
|
-
service_id: 'CT-16APR-Caltrain-Sunday-02'
|
|
704
|
+
service_id: 'CT-16APR-Caltrain-Sunday-02',
|
|
717
705
|
});
|
|
718
706
|
```
|
|
719
707
|
|
|
@@ -729,7 +717,7 @@ getCalendars();
|
|
|
729
717
|
|
|
730
718
|
// Get calendars for a specific `service_id`
|
|
731
719
|
getCalendars({
|
|
732
|
-
service_id: 'CT-16APR-Caltrain-Sunday-02'
|
|
720
|
+
service_id: 'CT-16APR-Caltrain-Sunday-02',
|
|
733
721
|
});
|
|
734
722
|
```
|
|
735
723
|
|
|
@@ -745,7 +733,7 @@ getCalendarDates();
|
|
|
745
733
|
|
|
746
734
|
// Get calendar_dates for a specific `service_id`
|
|
747
735
|
getCalendarDates({
|
|
748
|
-
service_id: 'CT-16APR-Caltrain-Sunday-02'
|
|
736
|
+
service_id: 'CT-16APR-Caltrain-Sunday-02',
|
|
749
737
|
});
|
|
750
738
|
```
|
|
751
739
|
|
|
@@ -761,7 +749,7 @@ getFareAttributes();
|
|
|
761
749
|
|
|
762
750
|
// Get `fare_attributes` for a specific `fare_id`
|
|
763
751
|
getFareAttributes({
|
|
764
|
-
fare_id: '123'
|
|
752
|
+
fare_id: '123',
|
|
765
753
|
});
|
|
766
754
|
```
|
|
767
755
|
|
|
@@ -777,7 +765,7 @@ getFareRules();
|
|
|
777
765
|
|
|
778
766
|
// Get fare_rules for a specific route
|
|
779
767
|
getFareRules({
|
|
780
|
-
route_id: 'Lo-16APR'
|
|
768
|
+
route_id: 'Lo-16APR',
|
|
781
769
|
});
|
|
782
770
|
```
|
|
783
771
|
|
|
@@ -804,7 +792,7 @@ getFrequencies();
|
|
|
804
792
|
|
|
805
793
|
// Get frequencies for a specific trip
|
|
806
794
|
getFrequencies({
|
|
807
|
-
trip_id: '1234'
|
|
795
|
+
trip_id: '1234',
|
|
808
796
|
});
|
|
809
797
|
```
|
|
810
798
|
|
|
@@ -842,7 +830,7 @@ getTransfers();
|
|
|
842
830
|
|
|
843
831
|
// Get transfers for a specific stop
|
|
844
832
|
getTransfers({
|
|
845
|
-
from_stop_id: '1234'
|
|
833
|
+
from_stop_id: '1234',
|
|
846
834
|
});
|
|
847
835
|
```
|
|
848
836
|
|
|
@@ -869,13 +857,13 @@ getDirections();
|
|
|
869
857
|
|
|
870
858
|
// Get directions for a specific route
|
|
871
859
|
getDirections({
|
|
872
|
-
route_id: '1234'
|
|
860
|
+
route_id: '1234',
|
|
873
861
|
});
|
|
874
862
|
|
|
875
863
|
// Get directions for a specific route and direction
|
|
876
864
|
getDirections({
|
|
877
865
|
route_id: '1234',
|
|
878
|
-
direction_id: 1
|
|
866
|
+
direction_id: 1,
|
|
879
867
|
});
|
|
880
868
|
```
|
|
881
869
|
|
|
@@ -891,7 +879,7 @@ getStopAttributes();
|
|
|
891
879
|
|
|
892
880
|
// Get stop attributes for specific stop
|
|
893
881
|
getStopAttributes({
|
|
894
|
-
stop_id: '1234'
|
|
882
|
+
stop_id: '1234',
|
|
895
883
|
});
|
|
896
884
|
```
|
|
897
885
|
|
|
@@ -907,7 +895,7 @@ getTimetables();
|
|
|
907
895
|
|
|
908
896
|
// Get a specific timetable
|
|
909
897
|
getTimetables({
|
|
910
|
-
timetable_id: '1'
|
|
898
|
+
timetable_id: '1',
|
|
911
899
|
});
|
|
912
900
|
```
|
|
913
901
|
|
|
@@ -923,7 +911,7 @@ getTimetableStopOrders();
|
|
|
923
911
|
|
|
924
912
|
// Get timetable_stop_orders for a specific timetable
|
|
925
913
|
getTimetableStopOrders({
|
|
926
|
-
timetable_id: '1'
|
|
914
|
+
timetable_id: '1',
|
|
927
915
|
});
|
|
928
916
|
```
|
|
929
917
|
|
|
@@ -939,7 +927,7 @@ getTimetablePages();
|
|
|
939
927
|
|
|
940
928
|
// Get a specific timetable_page
|
|
941
929
|
getTimetablePages({
|
|
942
|
-
timetable_page_id: '2'
|
|
930
|
+
timetable_page_id: '2',
|
|
943
931
|
});
|
|
944
932
|
```
|
|
945
933
|
|
|
@@ -955,7 +943,7 @@ getTimetableNotes();
|
|
|
955
943
|
|
|
956
944
|
// Get a specific timetable_note
|
|
957
945
|
getTimetableNotes({
|
|
958
|
-
note_id: '1'
|
|
946
|
+
note_id: '1',
|
|
959
947
|
});
|
|
960
948
|
```
|
|
961
949
|
|
|
@@ -971,7 +959,7 @@ getTimetableNotesReferences();
|
|
|
971
959
|
|
|
972
960
|
// Get all timetable_notes_references for a specific timetable
|
|
973
961
|
getTimetableNotesReferences({
|
|
974
|
-
timetable_id: '4'
|
|
962
|
+
timetable_id: '4',
|
|
975
963
|
});
|
|
976
964
|
```
|
|
977
965
|
|
|
@@ -989,7 +977,6 @@ To run a specific test:
|
|
|
989
977
|
|
|
990
978
|
NODE_ENV=test mocha ./test/mocha/gtfs.get-stoptimes.js
|
|
991
979
|
|
|
992
|
-
|
|
993
980
|
### Linting
|
|
994
981
|
|
|
995
982
|
npm run lint
|
package/bin/gtfs-export.js
CHANGED
|
@@ -13,15 +13,15 @@ const { argv } = yargs(hideBin(process.argv))
|
|
|
13
13
|
.option('c', {
|
|
14
14
|
alias: 'configPath',
|
|
15
15
|
describe: 'Path to config file',
|
|
16
|
-
type: 'string'
|
|
16
|
+
type: 'string',
|
|
17
17
|
})
|
|
18
18
|
.option('sqlitePath', {
|
|
19
19
|
describe: 'Path to SQLite database',
|
|
20
|
-
type: 'string'
|
|
20
|
+
type: 'string',
|
|
21
21
|
})
|
|
22
22
|
.option('exportPath', {
|
|
23
23
|
describe: 'Path where GTFS export should go',
|
|
24
|
-
type: 'string'
|
|
24
|
+
type: 'string',
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
const handleError = (error = 'Unknown Error') => {
|
|
@@ -35,5 +35,4 @@ const setupExport = async () => {
|
|
|
35
35
|
process.exit();
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
setupExport()
|
|
39
|
-
.catch(handleError);
|
|
38
|
+
setupExport().catch(handleError);
|
package/bin/gtfs-import.js
CHANGED
|
@@ -13,22 +13,22 @@ const { argv } = yargs(hideBin(process.argv))
|
|
|
13
13
|
.option('c', {
|
|
14
14
|
alias: 'configPath',
|
|
15
15
|
describe: 'Path to config file',
|
|
16
|
-
type: 'string'
|
|
16
|
+
type: 'string',
|
|
17
17
|
})
|
|
18
18
|
.option('gtfsPath', {
|
|
19
19
|
describe: 'Path to gtfs (zipped or unzipped)',
|
|
20
|
-
type: 'string'
|
|
20
|
+
type: 'string',
|
|
21
21
|
})
|
|
22
22
|
.option('gtfsUrl', {
|
|
23
23
|
describe: 'URL of gtfs file',
|
|
24
|
-
type: 'string'
|
|
24
|
+
type: 'string',
|
|
25
25
|
})
|
|
26
26
|
.option('sqlitePath', {
|
|
27
27
|
describe: 'Path to SQLite database',
|
|
28
|
-
type: 'string'
|
|
28
|
+
type: 'string',
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
-
const handleError = error => {
|
|
31
|
+
const handleError = (error) => {
|
|
32
32
|
const text = error || 'Unknown Error';
|
|
33
33
|
process.stdout.write(`\n${formatError(text)}\n`);
|
|
34
34
|
console.error(error);
|
|
@@ -41,5 +41,4 @@ const setupImport = async () => {
|
|
|
41
41
|
process.exit();
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
-
setupImport()
|
|
45
|
-
.catch(handleError);
|
|
44
|
+
setupImport().catch(handleError);
|
package/config-sample-full.json
CHANGED
|
@@ -2,16 +2,11 @@
|
|
|
2
2
|
"agencies": [
|
|
3
3
|
{
|
|
4
4
|
"url": "http://www.bart.gov/dev/schedules/google_transit.zip",
|
|
5
|
-
"exclude": [
|
|
6
|
-
"shapes"
|
|
7
|
-
]
|
|
5
|
+
"exclude": ["shapes"]
|
|
8
6
|
},
|
|
9
7
|
{
|
|
10
8
|
"path": "/path/to/gtfs.zip",
|
|
11
|
-
"exclude": [
|
|
12
|
-
"stop_times",
|
|
13
|
-
"shapes"
|
|
14
|
-
]
|
|
9
|
+
"exclude": ["stop_times", "shapes"]
|
|
15
10
|
}
|
|
16
11
|
],
|
|
17
12
|
"csvOptions": {
|
package/lib/db.js
CHANGED
|
@@ -8,7 +8,7 @@ export async function openDb(initialConfig) {
|
|
|
8
8
|
if (!db) {
|
|
9
9
|
db = await open({
|
|
10
10
|
filename: config.sqlitePath,
|
|
11
|
-
driver: sqlite3.Database
|
|
11
|
+
driver: sqlite3.Database,
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
14
|
|
|
@@ -33,5 +33,7 @@ export function getDb() {
|
|
|
33
33
|
return db;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
throw new Error(
|
|
36
|
+
throw new Error(
|
|
37
|
+
'No database connection. Call `openDb(config)` before using any methods.'
|
|
38
|
+
);
|
|
37
39
|
}
|