Skip to content
Open
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# GTFS-examples

Here you can find scripts written in Python and PHP, as an example on how you can use GTFS, and what's possible with it.
Here you can find scripts written in Python and PHP, as an example on how you can use GTFS, and what's possible with it.

## Contributing

Expand All @@ -10,6 +10,6 @@ If you would like to see a new feature added, you can also create a feature requ
## Help

If you're stuck with a question, feel free to ask help through the Issue tracker.
- Need help with API keys? Please read [www.trafiklab.se/api-nycklar](https://www.trafiklab.se/api-nycklar) first.
- Need help with API keys? Please read [Getting Started](https://www.trafiklab.se/docs/getting-started/using-trafiklab) first.
- Do you want to check the current systems status? Service disruptions
are published on the [Trafiklab homepage](https://www.trafiklab.se/)
4 changes: 2 additions & 2 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ see a new feature added, you can also create a feature request by creating an is

If you're stuck with a question, feel free to ask help through the Issue tracker.

- Need help with API keys? Please read [www.trafiklab.se/api-nycklar](https://www.trafiklab.se/api-nycklar) first.
- Need help with API keys? Please read [Getting Started](https://www.trafiklab.se/docs/getting-started/using-trafiklab) first.
- Do you want to check the current systems status? Service disruptions are published on
the [Trafiklab homepage](https://www.trafiklab.se/)
the [Trafiklab homepage](https://www.trafiklab.se/)
6 changes: 3 additions & 3 deletions python/gtfsToTimetableApi/GtfsTimeTable.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def is_archive_outdated(directory):
if is_outdated:
logging.info("GTFS archive is older than 1 day")
else:
logging.info("GTFS archive is less than 1 day old")
logging.debug("GTFS archive is less than 1 day old") # Since we check this on every call loglevel is set to DEBUG when the archive is up to date
return is_outdated


Expand Down Expand Up @@ -350,7 +350,7 @@ def get_seconds_since_midnight(self, time_str: str) -> int:
required.add_argument("--vehicle-positions",
help="the url to the vehiclepositions.pb file. Include an API key if the realtime feed requires this.",
dest="vehicle_positions", required=True)
required.add_argument("--stop-id", help="the id of the stop to create a timetable for", dest="stop-id",
required.add_argument("--stop-id", help="the id of the stop to create a timetable for", dest="stop_id",
required=True)
args = parser.parse_args()

Expand All @@ -362,5 +362,5 @@ def get_seconds_since_midnight(self, time_str: str) -> int:
# will be offset by the reduced startup time.
query_engine = TimeTableQueryEngine(gtfs_path, realtime_data_fetcher, reduce_memory_usage=True)
# Run a sample query and print the result
result = query_engine.create_departures_timetable('9021012080000000')
result = query_engine.create_departures_timetable(args.stop_id)
print(result)
7 changes: 6 additions & 1 deletion python/gtfsToTimetableApi/TimeTableApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import json
import logging
import sys
from datetime import datetime, timedelta

import flask

Expand All @@ -28,14 +29,18 @@

@app.route('/departures/<stop_id>', methods=['GET'])
def departures(stop_id):
resp = flask.Response(json.dumps(query_engine.create_departures_timetable(stop_id)))
gtfs_path = GtfsArchiveFetcher.fetch_and_extract(args.gtfs_url, "gtfs/")
window_start = datetime.now() - timedelta(minutes=10)
window_end = datetime.now() + timedelta(hours=2)
resp = flask.Response(json.dumps(query_engine.create_departures_timetable(stop_id, window_start, window_end)))
resp.headers['Content-encoding'] = 'UTF-8'
resp.headers['Content-type'] = 'Application/json'
return resp


@app.route('/stops/', methods=['GET'])
def stops():
gtfs_path = GtfsArchiveFetcher.fetch_and_extract(args.gtfs_url, "gtfs/")
resp = flask.Response(json.dumps(query_engine.list_queryable_stops()))
resp.headers['Content-encoding'] = 'UTF-8'
resp.headers['Content-type'] = 'Application/json'
Expand Down
8 changes: 4 additions & 4 deletions python/gtfsToTimetableApi/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Flask==1.1.2
gtfs-realtime-bindings==0.0.7
urllib3==1.26.5
requests==2.31.0
Flask==3.0.3
gtfs-realtime-bindings==1.0.0
urllib3==2.2.2
requests==2.31.0