# Path: data_model.py
# class StopLocation(GeoModel):
#     stopID       = db.StringProperty()
#     intersection = db.StringProperty()
#     direction    = db.StringProperty()
#     description  = db.StringProperty(multiline=True)
# 
# Path: data_model.py
# class StopLocationLoader(db.Model):
#     stopID       = db.StringProperty()
#     name         = db.StringProperty()
#     description  = db.StringProperty(multiline=True)
#     lat          = db.FloatProperty()
#     lon          = db.FloatProperty()
#     direction    = db.StringProperty()
# 
# Path: data_model.py
# class RouteListing(db.Model):
#     route        = db.StringProperty()
#     routeCode    = db.StringProperty()
#     direction    = db.StringProperty()
#     stopID       = db.StringProperty()
#     stopCode     = db.StringProperty()
#     scheduleURL  = db.StringProperty(indexed=False)
#     stopLocation = db.ReferenceProperty(StopLocation,collection_name="stops")
# 
# Path: data_model.py
# class RouteListingLoader(db.Model):
#     routeID       = db.StringProperty()
#     routeCode     = db.StringProperty()
#     direction     = db.StringProperty()
#     directionCode = db.StringProperty()
#     stopID        = db.StringProperty()
#     stopCode      = db.StringProperty()
# 
# Path: data_model.py
# class DestinationListing(db.Model):
#     id    = db.StringProperty()
#     label = db.StringProperty()


import logging
from google.appengine.api.taskqueue import Task
from google.appengine.ext import webapp
from google.appengine.ext import db
from google.appengine.ext.db import GeoPt
from google.appengine.ext.db import TransactionFailedError
from google.appengine.ext.db import Timeout
from google.appengine.runtime import DeadlineExceededError
from data_model import StopLocation
from data_model import StopLocationLoader
from data_model import RouteListing
from data_model import RouteListingLoader
from data_model import DestinationListing
                logging.debug(url)
                route = RouteListing()
                route.route = route_loader.routeID
                route.routeCode = route_loader.routeCode
                route.direction = route_loader.directionCode
                route.stopID = route_loader.stopID
                route.stopCode = route_loader.stopCode
                route.scheduleURL = url
                route.stopLocation = stop
                route.put()
                logging.info("added new route listing entry to the database!")

                DestinationListing.get_or_insert(route_loader.direction, id=route_loader.directionCode, label=route_loader.direction)
            except TransactionFailedError:
                logging.error('FAIL : unable to store RouteListing for route %s, stop %s', (route_loader.routeID,route_loader.stopID))
                self.response.set_status(2)
                self.response.out.write('transaction fail')

        return

## end RouteTransformationChild

#
# This handler is designed to port the GTFS Stops loaded via the bulk loader
# It simply creates a number of background tasks to do the grunt work
#
class PortStopsHandler(webapp.RequestHandler):
    def get(self):

        # query the StopLocationLoader for all stops

# Path: data_model.py
# class StopLocation(GeoModel):
#     stopID       = db.StringProperty()
#     intersection = db.StringProperty()
#     direction    = db.StringProperty()
#     description  = db.StringProperty(multiline=True)
# 
# Path: data_model.py
# class StopLocationLoader(db.Model):
#     stopID       = db.StringProperty()
#     name         = db.StringProperty()
#     description  = db.StringProperty(multiline=True)
#     lat          = db.FloatProperty()
#     lon          = db.FloatProperty()
#     direction    = db.StringProperty()
# 
# Path: data_model.py
# class RouteListing(db.Model):
#     route        = db.StringProperty()
#     routeCode    = db.StringProperty()
#     direction    = db.StringProperty()
#     stopID       = db.StringProperty()
#     stopCode     = db.StringProperty()
#     scheduleURL  = db.StringProperty(indexed=False)
#     stopLocation = db.ReferenceProperty(StopLocation,collection_name="stops")
# 
# Path: data_model.py
# class RouteListingLoader(db.Model):
#     routeID       = db.StringProperty()
#     routeCode     = db.StringProperty()
#     direction     = db.StringProperty()
#     directionCode = db.StringProperty()
#     stopID        = db.StringProperty()
#     stopCode      = db.StringProperty()
# 
# Path: data_model.py
# class DestinationListing(db.Model):
#     id    = db.StringProperty()
#     label = db.StringProperty()


# Path: crawl/load_gtfs.py
import logging
from google.appengine.api.taskqueue import Task
from google.appengine.ext import webapp
from google.appengine.ext import db
from google.appengine.ext.db import GeoPt
from google.appengine.ext.db import TransactionFailedError
from google.appengine.ext.db import Timeout
from google.appengine.runtime import DeadlineExceededError
from data_model import StopLocation
from data_model import StopLocationLoader
from data_model import RouteListing
from data_model import RouteListingLoader
from data_model import DestinationListing

                logging.debug(url)
                route = RouteListing()
                route.route = route_loader.routeID
                route.routeCode = route_loader.routeCode
                route.direction = route_loader.directionCode
                route.stopID = route_loader.stopID
                route.stopCode = route_loader.stopCode
                route.scheduleURL = url
                route.stopLocation = stop
                route.put()
                logging.info("added new route listing entry to the database!")

                DestinationListing.get_or_insert(route_loader.direction, id=route_loader.directionCode, label=route_loader.direction)
            except TransactionFailedError:
                logging.error('FAIL : unable to store RouteListing for route %s, stop %s', (route_loader.routeID,route_loader.stopID))
                self.response.set_status(2)
                self.response.out.write('transaction fail')

        return

## end RouteTransformationChild

#
# This handler is designed to port the GTFS Stops loaded via the bulk loader
# It simply creates a number of background tasks to do the grunt work
#
class PortStopsHandler(webapp.RequestHandler):
    def get(self):

        # query the StopLocationLoader for all stops

        stops = StopLocationLoader.all()