Skip to content

Commit

Permalink
Replace /gtfs-date with /gtfs-feed-info for more descriptive date info (
Browse files Browse the repository at this point in the history
  • Loading branch information
alanna-zhou authored Oct 20, 2019
1 parent 7c43ffb commit 861cfac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
8 changes: 3 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from flask import Flask, jsonify

from src.alerts import fetch_alerts, get_alerts_data
from src.gtfs import fetch_gtfs, get_gtfs_data, get_gtfs_date_updated
from src.gtfs import fetch_gtfs, get_gtfs_data, get_gtfs_feed_info
from src.live_tracking import fetch_rtf, get_rtf_data
from src.stops import fetch_stops, get_stops_data

Expand All @@ -28,11 +28,9 @@ def get_rtf():
def get_all_stops():
return jsonify(get_stops_data())

@app.route('/gtfs-date')
@app.route('/gtfs-feed-info')
def get_gtfs_date():
if get_gtfs_date_updated():
return jsonify(get_gtfs_date_updated())
return jsonify('Unknown when GTFS was last updated')
return jsonify(get_gtfs_feed_info())

if __name__ == '__main__':
alerts_event, gtfs_event, rtf_event, stops_event = [threading.Event() for i in range(4)]
Expand Down
19 changes: 11 additions & 8 deletions src/gtfs.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import csv

# from subprocess import PIPE, Popen, STDOUT
# import datetime
# import threading
# import zipfile

TCAT_NY_US = "tcat-ny-us"
TEN_SECONDS = 10

gtfs_data = []
date_updated = None
gtfs_feed_info = {}


def fetch_gtfs(event):
Expand All @@ -28,8 +23,16 @@ def extract_gtfs():
gtfs_data.append(route)


def get_gtfs_date_updated():
return date_updated
def get_gtfs_feed_info():
global gtfs_feed_info
with open(f"{TCAT_NY_US}/feed_info.txt") as csv_file:
csv_reader = csv.reader(csv_file, delimiter=",")
column_names = next(csv_reader)
for row in csv_reader:
for index, column in enumerate(column_names):
if column in {"feed_start_date", "feed_end_date", "feed_version"}:
gtfs_feed_info[column] = row[index]
return gtfs_feed_info


def get_gtfs_data():
Expand Down

0 comments on commit 861cfac

Please sign in to comment.