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

Provide option GTFS_RANGE to configure schedules included #97

Merged
merged 1 commit into from
Aug 7, 2024
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
7 changes: 6 additions & 1 deletion src/cli/OutputGTFSCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ export class OutputGTFSCommand implements CLICommand {
throw new Error(`Output path ${this.baseDir} does not exist.`);
}

if (Object.hasOwn(process.env, "GTFS_RANGE")) {
console.log(`Using GTFS_RANGE = ${process.env.GTFS_RANGE}\n`);
}
const range = process.env.GTFS_RANGE || "3 MONTH";

const associationsP = this.repository.getAssociations();
const scheduleResultsP = this.repository.getSchedules();
const scheduleResultsP = this.repository.getSchedules(range);
const transfersP = this.copy(this.repository.getTransfers(), "transfers.txt");
const stopsP = this.copy(this.repository.getStops(), "stops.txt");
const agencyP = this.copy(agencies, "agency.txt");
Expand Down
4 changes: 4 additions & 0 deletions src/cli/ShowHelpCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ The --get-* and --download-* commands require SFTP environment properties:
SFTP_USERNAME SFTP username
SFTP_PASSWORD SFTP password
SFTP_HOSTNAME SFTP hostname (defaults to dtd.atocrsp.org)

The --gtfs and --gtfs-zip commands take the following environment properties:

GTFS_RANGE A mysql interval expression for the scedules to include. This is NOT SANITIZED so it cannot be untrusted user input (defaults to '3 MONTH')

`);

Expand Down
7 changes: 5 additions & 2 deletions src/gtfs/repository/CIFRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@ export class CIFRepository {
*
* The second query selects all the z-trains (usually replacement buses) within three months. They already use CRS
* codes as the location so avoid the disaster above.
*
* The argument range is a mysql expression like '3 MONTH'.
* It is NOT SANITIZED so it cannot be untrusted user input.
*/
public async getSchedules(): Promise<ScheduleResults> {
public async getSchedules(range: string): Promise<ScheduleResults> {
const scheduleBuilder = new ScheduleBuilder();
const [[lastSchedule]] = await this.db.query<{id: number}>("SELECT id FROM schedule ORDER BY id desc LIMIT 1");

Expand All @@ -103,7 +106,7 @@ export class CIFRepository {
(
stop_time.id IS NULL OR crs_code IS NOT NULL
)
AND runs_from < CURDATE() + INTERVAL 3 MONTH
AND runs_from < CURDATE() + INTERVAL ${range}
AND runs_to >= CURDATE()
AND scheduled_pass_time is null
ORDER BY stp_indicator DESC, id, stop_id
Expand Down
Loading