Skip to content
This repository has been archived by the owner on Oct 17, 2020. It is now read-only.

Commit

Permalink
fixes trip naming convention
Browse files Browse the repository at this point in the history
  • Loading branch information
avilaton committed Nov 6, 2015
1 parent cb34935 commit 3e9d76e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
22 changes: 13 additions & 9 deletions app/services/feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
import csv
import resource
import transitfeed
import StringIO
try:
from cStringIO import StringIO
except:
from StringIO import StringIO
import zipfile
import shutil

from app import db
from ..models import *
Expand All @@ -22,7 +26,7 @@ class Feed(object):
def __init__(self, filename='google_transit.zip', db=db):
self.db = db
self.filename = filename
self.fileObj = StringIO.StringIO()
self.fileObj = StringIO()
self.trip_start_times_default = None
self.schedule = transitfeed.Schedule(memory_db=False)

Expand All @@ -48,7 +52,9 @@ def build(self, mode='frequency'):
return self.fileObj

def saveTo(self, directory):
self.schedule.WriteGoogleTransitFeed(directory + self.filename)
self.fileObj.seek(0)
with open(directory + self.filename, 'w') as outfile:
shutil.copyfileobj(self.fileObj, outfile)

def validate(self):
"""Validate feed object"""
Expand Down Expand Up @@ -132,7 +138,7 @@ def loadTrips(self, route):
trip.service_id = service.service_id
trip.shape_id = tripRow.shape_id
trip.direction_id = tripRow.direction_id
logger.info("Loading trip_id:{0} ".format(trip_id))
# logger.info("Loading trip_id:{0} ".format(trip_id))
self.loadStopTimes(trip)

elif self.mode == 'initial-times':
Expand Down Expand Up @@ -272,13 +278,11 @@ def loadFeedInfo(self):

keys = ['feed_publisher_name', 'feed_start_date', 'feed_version',
'feed_end_date', 'feed_lang', 'feed_publisher_url']
feed_info_txt = StringIO.StringIO()
feed_info_txt = StringIO()
writer = csv.DictWriter(feed_info_txt, keys)
writer.writeheader()
for info in self.db.query(FeedInfo).all():
uDict = {k:v.encode('utf-8') for k, v in info.to_json.iteritems() if v}
writer.writerow(uDict)
with zipfile.ZipFile(self.fileObj, "a", zipfile.ZIP_DEFLATED) as z:
z.writestr('feed_info.txt', feed_info_txt.getvalue())
for item in z.filelist:
print item.filename
with zipfile.ZipFile(self.fileObj, "a", zipfile.ZIP_DEFLATED) as feed_file:
feed_file.writestr('feed_info.txt', feed_info_txt.getvalue())
1 change: 0 additions & 1 deletion app/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def extract_zip(filename, dest):

with zipfile.ZipFile(filename, "r") as z:
for filename in z.namelist():
print filename
with file(dest + filename, "w") as outfile:
outfile.write(z.read(filename))

Expand Down

0 comments on commit 3e9d76e

Please sign in to comment.