Created
May 9, 2011 05:49
-
-
Save wlach/962117 to your computer and use it in GitHub Desktop.
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
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>" | |
exit(1) | |
filename = sys.argv[1] | |
zf = ZipFile(filename) | |
contents = zf.read('calendar.txt') | |
rows = csv.reader(iterdecode( contents.split("\n"),"utf-8")) | |
header = rows.next() | |
headerdict = dict(zip(header, range(len(header)))) | |
(min_start_date, max_end_date) = map(lambda ds: datetime.date(int(ds[0:4]), | |
int(ds[4:6]), | |
int(ds[6:8])), | |
reduce(lambda x,y: (min(x[0],y[0]), | |
max(x[1],y[1])), | |
map(lambda x: (x[headerdict['start_date']], | |
x[headerdict['end_date']]), rows))) | |
print min_start_date | |
print max_end_date |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I did a version of this for Python3: https://gist.github.com/ian-weisser/9997196