Created
May 2, 2015 06:38
-
-
Save renjiexu/3f1d8f618ad379847883 to your computer and use it in GitHub Desktop.
Script to convert bart schedule to some format I want...
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
amFile = open('am', 'r') | |
pmFile = open('pm', 'r') | |
extraAmFile = open('extraAm', 'r') | |
stopSchedules = {} | |
#isPM = True | |
names = ["Fremont", "Union City", "South Hayward", "Hayward", "Bay Fair", "San Leandro", "Coliseum", "Fruitvale", "Lake Merritt", "12th St. Oakland City Center", "19th St. Oakland", "MacArthur", "Ashby", "Downtown Berkeley", "North Berkeley", "El Cerrito Plaza", "El Cerrito del Norte", "Richmond"] | |
for line in amFile.readlines(): | |
times = line.split('\t') | |
column = 0 | |
for time in times: | |
if time.strip() == '': | |
column += 1 | |
continue | |
if column not in stopSchedules: | |
stopSchedules[column] = [] | |
digits = time.split(":") | |
amOrPm = "AM" | |
if int(digits[0]) == 12 or int(digits[0]) == 1: | |
amOrPm = "PM" | |
s = time.rstrip() + amOrPm | |
stopSchedules[column].append(s) | |
column += 1 | |
for line in pmFile.readlines(): | |
times = line.split('\t') | |
column = 0 | |
for time in times: | |
if time.strip() == '': | |
column += 1 | |
continue | |
if column not in stopSchedules: | |
stopSchedules[column] = [] | |
digits = time.split(":") | |
amOrPm = "PM" | |
s = time.rstrip() + amOrPm | |
stopSchedules[column].append(s) | |
column += 1 | |
for line in extraAmFile.readlines(): | |
times = line.split('\t') | |
column = 0 | |
for time in times: | |
if time.strip() == '': | |
column += 1 | |
continue | |
if column not in stopSchedules: | |
stopSchedules[column] = [] | |
digits = time.split(":") | |
amOrPm = "PM" | |
if int(digits[0]) == 12 or int(digits[0]) == 1: | |
amOrPm = "AM" | |
s = time.rstrip() + amOrPm | |
stopSchedules[column].append(s) | |
column += 1 | |
index = len(names) - 1 | |
#index = 0 | |
for stop in stopSchedules: | |
print '{"name":"%s","children":[' % names[index] | |
index -= 1 | |
first = True | |
for schedule in stopSchedules[stop]: | |
if not first: | |
print ',', | |
first = False | |
print '{"name":"%s"}' % schedule, | |
#print '{"name":"', schedule, '"}', | |
print ']},' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment