Skip to content

Instantly share code, notes, and snippets.

@renjiexu
Created May 2, 2015 06:38
Show Gist options
  • Save renjiexu/3f1d8f618ad379847883 to your computer and use it in GitHub Desktop.
Save renjiexu/3f1d8f618ad379847883 to your computer and use it in GitHub Desktop.
Script to convert bart schedule to some format I want...
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