gtfs 3.6.1 → 3.7.0
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/CHANGELOG.md +10 -0
- package/README.md +34 -7
- package/config-sample-full.json +1 -0
- package/lib/import.js +5 -4
- package/lib/utils.js +3 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [3.7.0] - 2022-11-17
|
|
9
|
+
|
|
10
|
+
### Updated
|
|
11
|
+
|
|
12
|
+
- Dependency updates
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
|
|
16
|
+
- Add ignoreDuplicates config option
|
|
17
|
+
|
|
8
18
|
## [3.6.1] - 2022-11-08
|
|
9
19
|
|
|
10
20
|
### Updated
|
package/README.md
CHANGED
|
@@ -139,13 +139,14 @@ Copy `config-sample.json` to `config.json` and then add your projects configurat
|
|
|
139
139
|
|
|
140
140
|
cp config-sample.json config.json
|
|
141
141
|
|
|
142
|
-
| option
|
|
143
|
-
|
|
|
144
|
-
| [`agencies`](#agencies)
|
|
145
|
-
| [`csvOptions`](#csvOptions)
|
|
146
|
-
| [`exportPath`](#exportPath)
|
|
147
|
-
| [`
|
|
148
|
-
| [`
|
|
142
|
+
| option | type | description |
|
|
143
|
+
| --------------------------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------- |
|
|
144
|
+
| [`agencies`](#agencies) | array | An array of GTFS files to be imported. |
|
|
145
|
+
| [`csvOptions`](#csvOptions) | object | Options passed to `csv-parse` for parsing GTFS CSV files. Optional. |
|
|
146
|
+
| [`exportPath`](#exportPath) | string | A path to a directory to put exported GTFS files. Optional, defaults to `gtfs-export/<agency_name>`. |
|
|
147
|
+
| [`ignoreDuplicates`](#ignoreduplicates) | boolean | Whether or not to ignore unique constraints on ids when importing GTFS, such as `trip_id`, `calendar_id`. Optional, defaults to false. |
|
|
148
|
+
| [`sqlitePath`](#sqlitePath) | string | A path to an SQLite database. Optional, defaults to using an in-memory database. |
|
|
149
|
+
| [`verbose`](#verbose) | boolean | Whether or not to print output to the console. Optional, defaults to true. |
|
|
149
150
|
|
|
150
151
|
### agencies
|
|
151
152
|
|
|
@@ -274,6 +275,32 @@ See [full list of options](https://csv.js.org/parse/options/).
|
|
|
274
275
|
|
|
275
276
|
{String} A path to a directory to put exported GTFS files. If the directory does not exist, it will be created. Used when running `gtfs-export` script or `exportGtfs()`. Optional, defaults to `gtfs-export/<agency_name>` where `<agency_name>` is a sanitized, [snake-cased](https://en.wikipedia.org/wiki/Snake_case) version of the first `agency_name` in `agency.txt`.
|
|
276
277
|
|
|
278
|
+
```json
|
|
279
|
+
{
|
|
280
|
+
"agencies": [
|
|
281
|
+
{
|
|
282
|
+
"path": "/path/to/the/unzipped/gtfs/"
|
|
283
|
+
}
|
|
284
|
+
],
|
|
285
|
+
"exportPath": "~/path/to/export/gtfs"
|
|
286
|
+
}
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### ignoreDuplicates
|
|
290
|
+
|
|
291
|
+
{Boolean} If you don't want node-GTFS to throw an error when it encounters a duplicate id on GTFS import. If `true`, it will skip importing duplicate records where unique constraints are violated, such as`trip_id`, `stop_id`, `calendar_id`. Useful if importing GTFS from multiple sources into one SQlite database that share routes or stops. Defaults to `false`.
|
|
292
|
+
|
|
293
|
+
```json
|
|
294
|
+
{
|
|
295
|
+
"agencies": [
|
|
296
|
+
{
|
|
297
|
+
"path": "/path/to/the/unzipped/gtfs/"
|
|
298
|
+
}
|
|
299
|
+
],
|
|
300
|
+
"ignoreDuplicates": false
|
|
301
|
+
}
|
|
302
|
+
```
|
|
303
|
+
|
|
277
304
|
### sqlitePath
|
|
278
305
|
|
|
279
306
|
{String} A path to an SQLite database. Optional, defaults to using an in-memory database with a value of `:memory:`.
|
package/config-sample-full.json
CHANGED
package/lib/import.js
CHANGED
|
@@ -128,7 +128,7 @@ const cleanStaleRealtimeData = async (db, log) => {
|
|
|
128
128
|
(x) => x.filenameBase === 'service_alert_targets'
|
|
129
129
|
);
|
|
130
130
|
|
|
131
|
-
log(`Cleaning stale
|
|
131
|
+
log(`Cleaning stale GTFS-RT data..`);
|
|
132
132
|
await db.run(
|
|
133
133
|
`DELETE FROM ${vehiclePositionModel.filenameBase} WHERE isUpdated=0`
|
|
134
134
|
);
|
|
@@ -503,9 +503,9 @@ const importLines = async (task, lines, model, totalLineCount) => {
|
|
|
503
503
|
|
|
504
504
|
try {
|
|
505
505
|
await task.db.run(
|
|
506
|
-
`INSERT
|
|
507
|
-
|
|
508
|
-
)}) VALUES${placeholders.join(',')}`,
|
|
506
|
+
`INSERT ${task.ignoreDuplicates ? 'OR IGNORE' : ''} INTO ${
|
|
507
|
+
model.filenameBase
|
|
508
|
+
}(${fieldNames.join(', ')}) VALUES${placeholders.join(',')}`,
|
|
509
509
|
values
|
|
510
510
|
);
|
|
511
511
|
} catch (error) {
|
|
@@ -642,6 +642,7 @@ export async function importGtfs(initialConfig) {
|
|
|
642
642
|
downloadDir: path,
|
|
643
643
|
path: agency.path,
|
|
644
644
|
csvOptions: config.csvOptions || {},
|
|
645
|
+
ignoreDuplicates: config.ignoreDuplicates,
|
|
645
646
|
db,
|
|
646
647
|
log(message, overwrite) {
|
|
647
648
|
log(message, overwrite);
|
package/lib/utils.js
CHANGED
|
@@ -26,6 +26,7 @@ export function validateConfigForImport(config) {
|
|
|
26
26
|
export function setDefaultConfig(initialConfig) {
|
|
27
27
|
const defaults = {
|
|
28
28
|
sqlitePath: ':memory:',
|
|
29
|
+
ignoreDuplicates: false,
|
|
29
30
|
};
|
|
30
31
|
|
|
31
32
|
return {
|
|
@@ -85,11 +86,11 @@ export function formatWhereClause(key, value) {
|
|
|
85
86
|
.filter((v) => v !== null)
|
|
86
87
|
.map((v) => sqlString.escape(v))
|
|
87
88
|
.join(', ')})`;
|
|
88
|
-
|
|
89
|
+
|
|
89
90
|
if (value.includes(null)) {
|
|
90
91
|
whereClause = `(${whereClause} OR ${sqlString.escapeId(key)} IS NULL)`;
|
|
91
92
|
}
|
|
92
|
-
|
|
93
|
+
|
|
93
94
|
return whereClause;
|
|
94
95
|
}
|
|
95
96
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gtfs",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.0",
|
|
4
4
|
"description": "Import GTFS transit data into SQLite and query routes, stops, times, fares and more",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"transit",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"gtfs-realtime-bindings": "^0.0.6",
|
|
79
79
|
"lodash-es": "^4.17.21",
|
|
80
80
|
"long": "^5.2.1",
|
|
81
|
-
"node-fetch": "^3.
|
|
81
|
+
"node-fetch": "^3.3.0",
|
|
82
82
|
"pluralize": "^8.0.0",
|
|
83
83
|
"pretty-error": "^4.0.0",
|
|
84
84
|
"promise-map-series": "^0.3.0",
|