gtfs 4.14.2 → 4.14.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/README.md +1 -1
- package/dist/bin/gtfs-export.js +1 -0
- package/dist/bin/gtfs-export.js.map +1 -1
- package/dist/bin/gtfs-import.js +135 -104
- package/dist/bin/gtfs-import.js.map +1 -1
- package/dist/bin/gtfsrealtime-update.js +121 -89
- package/dist/bin/gtfsrealtime-update.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +146 -108
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -608,6 +608,7 @@ function setDefaultConfig(initialConfig) {
|
|
|
608
608
|
const defaults = {
|
|
609
609
|
sqlitePath: ":memory:",
|
|
610
610
|
ignoreDuplicates: false,
|
|
611
|
+
ignoreErrors: false,
|
|
611
612
|
gtfsRealtimeExpirationSeconds: 0
|
|
612
613
|
};
|
|
613
614
|
return {
|
|
@@ -633,7 +634,7 @@ var downloadGtfsRealtimeData = async (urlAndHeaders, task) => {
|
|
|
633
634
|
});
|
|
634
635
|
if (response.status !== 200) {
|
|
635
636
|
task.logWarning(
|
|
636
|
-
`Unable to download GTFS-Realtime from ${urlAndHeaders.url}
|
|
637
|
+
`Unable to download GTFS-Realtime from ${urlAndHeaders.url}. Got status ${response.status}.`
|
|
637
638
|
);
|
|
638
639
|
return null;
|
|
639
640
|
}
|
|
@@ -722,103 +723,127 @@ var updateRealtimeData = async (task) => {
|
|
|
722
723
|
sqlitePath: task.sqlitePath
|
|
723
724
|
});
|
|
724
725
|
if (task.realtimeAlerts?.url) {
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
const
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
try {
|
|
737
|
-
db.prepare(
|
|
738
|
-
`REPLACE INTO ${serviceAlerts.filenameBase} (${serviceAlerts.schema.map((column) => column.name).join(", ")}) VALUES (${fieldValues.join(", ")})`
|
|
739
|
-
).run();
|
|
740
|
-
} catch (error) {
|
|
741
|
-
task.logWarning("Import error: " + error.message);
|
|
742
|
-
}
|
|
743
|
-
const alertTargetArray = [];
|
|
744
|
-
for (const informedEntity of entity.alert.informedEntity) {
|
|
745
|
-
informedEntity.parent = entity;
|
|
746
|
-
const subValues = serviceAlertTargets.schema.map(
|
|
747
|
-
(column) => prepareRealtimeValue(informedEntity, column, task)
|
|
726
|
+
try {
|
|
727
|
+
const gtfsRealtimeData = await downloadGtfsRealtimeData(
|
|
728
|
+
task.realtimeAlerts,
|
|
729
|
+
task
|
|
730
|
+
);
|
|
731
|
+
if (gtfsRealtimeData?.entity) {
|
|
732
|
+
task.log(`Download successful`);
|
|
733
|
+
let totalLineCount = 0;
|
|
734
|
+
for (const entity of gtfsRealtimeData.entity) {
|
|
735
|
+
const fieldValues = serviceAlerts.schema.map(
|
|
736
|
+
(column) => prepareRealtimeValue(entity, column, task)
|
|
748
737
|
);
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
738
|
+
try {
|
|
739
|
+
db.prepare(
|
|
740
|
+
`REPLACE INTO ${serviceAlerts.filenameBase} (${serviceAlerts.schema.map((column) => column.name).join(", ")}) VALUES (${fieldValues.join(", ")})`
|
|
741
|
+
).run();
|
|
742
|
+
} catch (error) {
|
|
743
|
+
task.logWarning("Import error: " + error.message);
|
|
744
|
+
}
|
|
745
|
+
const alertTargetArray = [];
|
|
746
|
+
for (const informedEntity of entity.alert.informedEntity) {
|
|
747
|
+
informedEntity.parent = entity;
|
|
748
|
+
const subValues = serviceAlertTargets.schema.map(
|
|
749
|
+
(column) => prepareRealtimeValue(informedEntity, column, task)
|
|
750
|
+
);
|
|
751
|
+
alertTargetArray.push(`(${subValues.join(", ")})`);
|
|
752
|
+
totalLineCount++;
|
|
753
|
+
}
|
|
754
|
+
try {
|
|
755
|
+
db.prepare(
|
|
756
|
+
`REPLACE INTO ${serviceAlertTargets.filenameBase} (${serviceAlertTargets.schema.map((column) => column.name).join(", ")}) VALUES ${alertTargetArray.join(", ")}`
|
|
757
|
+
).run();
|
|
758
|
+
} catch (error) {
|
|
759
|
+
task.logWarning("Import error: " + error.message);
|
|
760
|
+
}
|
|
761
|
+
task.log(`Importing - ${totalLineCount++} entries imported\r`, true);
|
|
758
762
|
}
|
|
759
|
-
|
|
763
|
+
}
|
|
764
|
+
} catch (error) {
|
|
765
|
+
if (task.ignoreErrors) {
|
|
766
|
+
task.logError(error.message);
|
|
767
|
+
} else {
|
|
768
|
+
throw error;
|
|
760
769
|
}
|
|
761
770
|
}
|
|
762
771
|
}
|
|
763
772
|
if (task.realtimeTripUpdates?.url) {
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
const
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
try {
|
|
776
|
-
db.prepare(
|
|
777
|
-
`REPLACE INTO ${tripUpdates.filenameBase} (${tripUpdates.schema.map((column) => column.name).join(", ")}) VALUES (${fieldValues.join(", ")})`
|
|
778
|
-
).run();
|
|
779
|
-
} catch (error) {
|
|
780
|
-
task.logWarning("Import error: " + error.message);
|
|
781
|
-
}
|
|
782
|
-
const stopTimeUpdateArray = [];
|
|
783
|
-
for (const stopTimeUpdate of entity.tripUpdate.stopTimeUpdate) {
|
|
784
|
-
stopTimeUpdate.parent = entity;
|
|
785
|
-
const subValues = stopTimeUpdates.schema.map(
|
|
786
|
-
(column) => prepareRealtimeValue(stopTimeUpdate, column, task)
|
|
773
|
+
try {
|
|
774
|
+
const gtfsRealtimeData = await downloadGtfsRealtimeData(
|
|
775
|
+
task.realtimeTripUpdates,
|
|
776
|
+
task
|
|
777
|
+
);
|
|
778
|
+
if (gtfsRealtimeData?.entity) {
|
|
779
|
+
task.log(`Download successful`);
|
|
780
|
+
let totalLineCount = 0;
|
|
781
|
+
for (const entity of gtfsRealtimeData.entity) {
|
|
782
|
+
const fieldValues = tripUpdates.schema.map(
|
|
783
|
+
(column) => prepareRealtimeValue(entity, column, task)
|
|
787
784
|
);
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
785
|
+
try {
|
|
786
|
+
db.prepare(
|
|
787
|
+
`REPLACE INTO ${tripUpdates.filenameBase} (${tripUpdates.schema.map((column) => column.name).join(", ")}) VALUES (${fieldValues.join(", ")})`
|
|
788
|
+
).run();
|
|
789
|
+
} catch (error) {
|
|
790
|
+
task.logWarning("Import error: " + error.message);
|
|
791
|
+
}
|
|
792
|
+
const stopTimeUpdateArray = [];
|
|
793
|
+
for (const stopTimeUpdate of entity.tripUpdate.stopTimeUpdate) {
|
|
794
|
+
stopTimeUpdate.parent = entity;
|
|
795
|
+
const subValues = stopTimeUpdates.schema.map(
|
|
796
|
+
(column) => prepareRealtimeValue(stopTimeUpdate, column, task)
|
|
797
|
+
);
|
|
798
|
+
stopTimeUpdateArray.push(`(${subValues.join(", ")})`);
|
|
799
|
+
totalLineCount++;
|
|
800
|
+
}
|
|
801
|
+
try {
|
|
802
|
+
db.prepare(
|
|
803
|
+
`REPLACE INTO ${stopTimeUpdates.filenameBase} (${stopTimeUpdates.schema.map((column) => column.name).join(", ")}) VALUES ${stopTimeUpdateArray.join(", ")}`
|
|
804
|
+
).run();
|
|
805
|
+
} catch (error) {
|
|
806
|
+
task.logWarning("Import error: " + error.message);
|
|
807
|
+
}
|
|
808
|
+
task.log(`Importing - ${totalLineCount++} entries imported\r`, true);
|
|
797
809
|
}
|
|
798
|
-
|
|
810
|
+
}
|
|
811
|
+
} catch (error) {
|
|
812
|
+
if (task.ignoreErrors) {
|
|
813
|
+
task.logError(error.message);
|
|
814
|
+
} else {
|
|
815
|
+
throw error;
|
|
799
816
|
}
|
|
800
817
|
}
|
|
801
818
|
}
|
|
802
819
|
if (task.realtimeVehiclePositions?.url) {
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
const
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
+
try {
|
|
821
|
+
const gtfsRealtimeData = await downloadGtfsRealtimeData(
|
|
822
|
+
task.realtimeVehiclePositions,
|
|
823
|
+
task
|
|
824
|
+
);
|
|
825
|
+
if (gtfsRealtimeData?.entity) {
|
|
826
|
+
task.log(`Download successful`);
|
|
827
|
+
let totalLineCount = 0;
|
|
828
|
+
for (const entity of gtfsRealtimeData.entity) {
|
|
829
|
+
const fieldValues = vehiclePositions.schema.map(
|
|
830
|
+
(column) => prepareRealtimeValue(entity, column, task)
|
|
831
|
+
);
|
|
832
|
+
try {
|
|
833
|
+
db.prepare(
|
|
834
|
+
`REPLACE INTO ${vehiclePositions.filenameBase} (${vehiclePositions.schema.map((column) => column.name).join(", ")}) VALUES (${fieldValues.join(", ")})`
|
|
835
|
+
).run();
|
|
836
|
+
} catch (error) {
|
|
837
|
+
task.logWarning("Import error: " + error.message);
|
|
838
|
+
}
|
|
839
|
+
task.log(`Importing - ${totalLineCount++} entries imported\r`, true);
|
|
820
840
|
}
|
|
821
|
-
|
|
841
|
+
}
|
|
842
|
+
} catch (error) {
|
|
843
|
+
if (task.ignoreErrors) {
|
|
844
|
+
task.logError(error.message);
|
|
845
|
+
} else {
|
|
846
|
+
throw error;
|
|
822
847
|
}
|
|
823
848
|
}
|
|
824
849
|
}
|
|
@@ -841,14 +866,15 @@ async function updateGtfsRealtime(initialConfig) {
|
|
|
841
866
|
)} using SQLite database at ${config.sqlitePath}`
|
|
842
867
|
);
|
|
843
868
|
deleteExpiredRealtimeData(config);
|
|
844
|
-
await
|
|
845
|
-
|
|
869
|
+
await mapSeries(config.agencies, async (agency2) => {
|
|
870
|
+
try {
|
|
846
871
|
const task = {
|
|
847
872
|
realtimeAlerts: agency2.realtimeAlerts,
|
|
848
873
|
realtimeTripUpdates: agency2.realtimeTripUpdates,
|
|
849
874
|
realtimeVehiclePositions: agency2.realtimeVehiclePositions,
|
|
850
875
|
downloadTimeout: config.downloadTimeout,
|
|
851
876
|
gtfsRealtimeExpirationSeconds: config.gtfsRealtimeExpirationSeconds,
|
|
877
|
+
ignoreErrors: config.ignoreErrors,
|
|
852
878
|
sqlitePath: config.sqlitePath,
|
|
853
879
|
currentTimestamp: Math.floor(Date.now() / 1e3),
|
|
854
880
|
log: log2,
|
|
@@ -856,8 +882,14 @@ async function updateGtfsRealtime(initialConfig) {
|
|
|
856
882
|
logError: logError2
|
|
857
883
|
};
|
|
858
884
|
await updateRealtimeData(task);
|
|
859
|
-
})
|
|
860
|
-
|
|
885
|
+
} catch (error) {
|
|
886
|
+
if (config.ignoreErrors) {
|
|
887
|
+
logError2(error.message);
|
|
888
|
+
} else {
|
|
889
|
+
throw error;
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
});
|
|
861
893
|
log2(
|
|
862
894
|
`Completed GTFS-Realtime refresh for ${pluralize(
|
|
863
895
|
"agencies",
|