Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Simple and stupid python script to get the range of dates covered by its service periods (useful for telling if a feed is way out of date, or will be soon)
import os
import sys
from codecs import iterdecode
from zipfile import ZipFile
import csv
import datetime
if len(sys.argv) < 2:
print "Usage: %prog <gtfs feed>"
filename = sys.argv[1]
zf = ZipFile(filename)
contents ='calendar.txt')
rows = csv.reader(iterdecode( contents.split("\n"),"utf-8"))
header =
headerdict = dict(zip(header, range(len(header))))
(min_start_date, max_end_date) = map(lambda ds:[0:4]),
reduce(lambda x,y: (min(x[0],y[0]),
map(lambda x: (x[headerdict['start_date']],
x[headerdict['end_date']]), rows)))
print min_start_date
print max_end_date

This comment has been minimized.

Copy link

ian-weisser commented Apr 5, 2014

I did a version of this for Python3:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.