gtfs 4.13.4 → 4.14.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/README.md +36 -20
- package/dist/bin/gtfs-export.js.map +1 -1
- package/dist/bin/gtfs-import.js +90 -59
- package/dist/bin/gtfs-import.js.map +1 -1
- package/dist/bin/gtfsrealtime-update.js +86 -195
- package/dist/bin/gtfsrealtime-update.js.map +1 -1
- package/dist/index.d.ts +20 -9
- package/dist/index.js +94 -65
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/dist/bin/gtfs-import.js
CHANGED
|
@@ -3350,31 +3350,34 @@ function padLeadingZeros(time) {
|
|
|
3350
3350
|
|
|
3351
3351
|
// src/lib/import.ts
|
|
3352
3352
|
var downloadFiles = async (task) => {
|
|
3353
|
-
task.log(`Downloading GTFS from ${task.
|
|
3353
|
+
task.log(`Downloading GTFS from ${task.url}`);
|
|
3354
3354
|
task.path = `${task.downloadDir}/gtfs.zip`;
|
|
3355
|
-
const response = await fetch(task.
|
|
3355
|
+
const response = await fetch(task.url, {
|
|
3356
3356
|
method: "GET",
|
|
3357
3357
|
headers: task.headers || {},
|
|
3358
3358
|
signal: task.downloadTimeout ? AbortSignal.timeout(task.downloadTimeout) : void 0
|
|
3359
3359
|
});
|
|
3360
3360
|
if (response.status !== 200) {
|
|
3361
|
-
throw new Error(`Unable to download GTFS from ${task.
|
|
3361
|
+
throw new Error(`Unable to download GTFS from ${task.url}`);
|
|
3362
3362
|
}
|
|
3363
3363
|
const buffer = await response.arrayBuffer();
|
|
3364
3364
|
await writeFile(task.path, Buffer.from(buffer));
|
|
3365
3365
|
task.log("Download successful");
|
|
3366
3366
|
};
|
|
3367
|
-
var downloadGtfsRealtimeData = async (
|
|
3368
|
-
|
|
3367
|
+
var downloadGtfsRealtimeData = async (urlAndHeaders, task) => {
|
|
3368
|
+
task.log(`Downloading GTFS-Realtime from ${urlAndHeaders.url}`);
|
|
3369
|
+
const response = await fetch(urlAndHeaders.url, {
|
|
3369
3370
|
method: "GET",
|
|
3370
3371
|
headers: {
|
|
3371
|
-
...
|
|
3372
|
+
...urlAndHeaders.headers ?? {},
|
|
3372
3373
|
"Accept-Encoding": "gzip"
|
|
3373
3374
|
},
|
|
3374
3375
|
signal: task.downloadTimeout ? AbortSignal.timeout(task.downloadTimeout) : void 0
|
|
3375
3376
|
});
|
|
3376
3377
|
if (response.status !== 200) {
|
|
3377
|
-
task.logWarning(
|
|
3378
|
+
task.logWarning(
|
|
3379
|
+
`Unable to download GTFS-Realtime from ${urlAndHeaders.url}`
|
|
3380
|
+
);
|
|
3378
3381
|
return null;
|
|
3379
3382
|
}
|
|
3380
3383
|
const buffer = await response.arrayBuffer();
|
|
@@ -3434,48 +3437,70 @@ var prepareRealtimeValue = (entity, column, task) => {
|
|
|
3434
3437
|
);
|
|
3435
3438
|
};
|
|
3436
3439
|
var updateRealtimeData = async (task) => {
|
|
3437
|
-
if (
|
|
3440
|
+
if (task.realtimeAlerts === void 0 && task.realtimeTripUpdates === void 0 && task.realtimeVehiclePositions === void 0) {
|
|
3438
3441
|
return;
|
|
3439
3442
|
}
|
|
3440
3443
|
const db = openDb({
|
|
3441
3444
|
sqlitePath: task.sqlitePath
|
|
3442
3445
|
});
|
|
3443
|
-
task.
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3446
|
+
if (task.realtimeAlerts?.url) {
|
|
3447
|
+
const gtfsRealtimeData = await downloadGtfsRealtimeData(
|
|
3448
|
+
task.realtimeAlerts,
|
|
3449
|
+
task
|
|
3450
|
+
);
|
|
3451
|
+
if (gtfsRealtimeData?.entity) {
|
|
3452
|
+
task.log(`Download successful`);
|
|
3453
|
+
let totalLineCount = 0;
|
|
3454
|
+
for (const entity of gtfsRealtimeData.entity) {
|
|
3455
|
+
const fieldValues = serviceAlerts.schema.map(
|
|
3456
|
+
(column) => prepareRealtimeValue(entity, column, task)
|
|
3457
|
+
);
|
|
3458
|
+
try {
|
|
3459
|
+
db.prepare(
|
|
3460
|
+
`REPLACE INTO ${serviceAlerts.filenameBase} (${serviceAlerts.schema.map((column) => column.name).join(", ")}) VALUES (${fieldValues.join(", ")})`
|
|
3461
|
+
).run();
|
|
3462
|
+
} catch (error) {
|
|
3463
|
+
task.logWarning("Import error: " + error.message);
|
|
3464
|
+
}
|
|
3465
|
+
const alertTargetArray = [];
|
|
3466
|
+
for (const informedEntity of entity.alert.informedEntity) {
|
|
3467
|
+
informedEntity.parent = entity;
|
|
3468
|
+
const subValues = serviceAlertTargets.schema.map(
|
|
3469
|
+
(column) => prepareRealtimeValue(informedEntity, column, task)
|
|
3470
|
+
);
|
|
3471
|
+
alertTargetArray.push(`(${subValues.join(", ")})`);
|
|
3472
|
+
totalLineCount++;
|
|
3473
|
+
}
|
|
3474
|
+
try {
|
|
3475
|
+
db.prepare(
|
|
3476
|
+
`REPLACE INTO ${serviceAlertTargets.filenameBase} (${serviceAlertTargets.schema.map((column) => column.name).join(", ")}) VALUES ${alertTargetArray.join(", ")}`
|
|
3477
|
+
).run();
|
|
3478
|
+
} catch (error) {
|
|
3479
|
+
task.logWarning("Import error: " + error.message);
|
|
3480
|
+
}
|
|
3481
|
+
task.log(`Importing - ${totalLineCount++} entries imported\r`, true);
|
|
3477
3482
|
}
|
|
3478
|
-
|
|
3483
|
+
}
|
|
3484
|
+
}
|
|
3485
|
+
if (task.realtimeTripUpdates?.url) {
|
|
3486
|
+
const gtfsRealtimeData = await downloadGtfsRealtimeData(
|
|
3487
|
+
task.realtimeTripUpdates,
|
|
3488
|
+
task
|
|
3489
|
+
);
|
|
3490
|
+
if (gtfsRealtimeData?.entity) {
|
|
3491
|
+
task.log(`Download successful`);
|
|
3492
|
+
let totalLineCount = 0;
|
|
3493
|
+
for (const entity of gtfsRealtimeData.entity) {
|
|
3494
|
+
const fieldValues = tripUpdates.schema.map(
|
|
3495
|
+
(column) => prepareRealtimeValue(entity, column, task)
|
|
3496
|
+
);
|
|
3497
|
+
try {
|
|
3498
|
+
db.prepare(
|
|
3499
|
+
`REPLACE INTO ${tripUpdates.filenameBase} (${tripUpdates.schema.map((column) => column.name).join(", ")}) VALUES (${fieldValues.join(", ")})`
|
|
3500
|
+
).run();
|
|
3501
|
+
} catch (error) {
|
|
3502
|
+
task.logWarning("Import error: " + error.message);
|
|
3503
|
+
}
|
|
3479
3504
|
const stopTimeUpdateArray = [];
|
|
3480
3505
|
for (const stopTimeUpdate of entity.tripUpdate.stopTimeUpdate) {
|
|
3481
3506
|
stopTimeUpdate.parent = entity;
|
|
@@ -3492,26 +3517,31 @@ var updateRealtimeData = async (task) => {
|
|
|
3492
3517
|
} catch (error) {
|
|
3493
3518
|
task.logWarning("Import error: " + error.message);
|
|
3494
3519
|
}
|
|
3520
|
+
task.log(`Importing - ${totalLineCount++} entries imported\r`, true);
|
|
3495
3521
|
}
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3522
|
+
}
|
|
3523
|
+
}
|
|
3524
|
+
if (task.realtimeVehiclePositions?.url) {
|
|
3525
|
+
const gtfsRealtimeData = await downloadGtfsRealtimeData(
|
|
3526
|
+
task.realtimeVehiclePositions,
|
|
3527
|
+
task
|
|
3528
|
+
);
|
|
3529
|
+
if (gtfsRealtimeData?.entity) {
|
|
3530
|
+
task.log(`Download successful`);
|
|
3531
|
+
let totalLineCount = 0;
|
|
3532
|
+
for (const entity of gtfsRealtimeData.entity) {
|
|
3533
|
+
const fieldValues = tripUpdates.schema.map(
|
|
3534
|
+
(column) => prepareRealtimeValue(entity, column, task)
|
|
3535
|
+
);
|
|
3506
3536
|
try {
|
|
3507
3537
|
db.prepare(
|
|
3508
|
-
`REPLACE INTO ${
|
|
3538
|
+
`REPLACE INTO ${tripUpdates.filenameBase} (${tripUpdates.schema.map((column) => column.name).join(", ")}) VALUES (${fieldValues.join(", ")})`
|
|
3509
3539
|
).run();
|
|
3510
3540
|
} catch (error) {
|
|
3511
3541
|
task.logWarning("Import error: " + error.message);
|
|
3512
3542
|
}
|
|
3543
|
+
task.log(`Importing - ${totalLineCount++} entries imported\r`, true);
|
|
3513
3544
|
}
|
|
3514
|
-
task.log(`Importing - ${totalLineCount++} entries imported\r`, true);
|
|
3515
3545
|
}
|
|
3516
3546
|
}
|
|
3517
3547
|
task.log(`GTFS-Realtime data import complete`);
|
|
@@ -3823,10 +3853,11 @@ async function importGtfs(initialConfig) {
|
|
|
3823
3853
|
const tempPath = temporaryDirectory();
|
|
3824
3854
|
const task = {
|
|
3825
3855
|
exclude: agency2.exclude,
|
|
3826
|
-
|
|
3856
|
+
url: agency2.url,
|
|
3827
3857
|
headers: agency2.headers,
|
|
3828
|
-
|
|
3829
|
-
|
|
3858
|
+
realtimeAlerts: agency2.realtimeAlerts,
|
|
3859
|
+
realtimeTripUpdates: agency2.realtimeTripUpdates,
|
|
3860
|
+
realtimeVehiclePositions: agency2.realtimeVehiclePositions,
|
|
3830
3861
|
downloadDir: tempPath,
|
|
3831
3862
|
downloadTimeout: config.downloadTimeout,
|
|
3832
3863
|
gtfsRealtimeExpirationSeconds: config.gtfsRealtimeExpirationSeconds,
|
|
@@ -3841,7 +3872,7 @@ async function importGtfs(initialConfig) {
|
|
|
3841
3872
|
logError: logError2
|
|
3842
3873
|
};
|
|
3843
3874
|
try {
|
|
3844
|
-
if (task.
|
|
3875
|
+
if (task.url) {
|
|
3845
3876
|
await downloadFiles(task);
|
|
3846
3877
|
}
|
|
3847
3878
|
await readFiles(task);
|