def post(self): route_loader_key = self.request.get('rll_key') logging.debug('work on %s' % self.request.get('rll_key')) route_loader = RouteListingLoader.get(route_loader_key) if route_loader is None: logging.error('total fail. unable to find %s' % route_loader_key) else: logging.debug(route_loader.routeID) # find the corresponding stop details stop = db.GqlQuery("SELECT * FROM StopLocation WHERE stopID = :1", route_loader.stopID).get() if stop is None: logging.error("Missing stop %s which should be impossible" % route_loader.stopID); try: url = CRAWL_URLBASE + '?r=' + route_loader.routeCode + '&d=' + route_loader.directionCode + '&s=' + route_loader.stopCode 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
def post(self): try: routeID = self.request.get('route') if len(routeID) == 1: routeID = '0' + routeID q = RouteListingLoader.all() q.filter("routeID = ", routeID) for r in q.run(keys_only=True): logging.debug('launch key query %s' % r) task = Task(url="/gtfs/port/routes/transform/task",params={'rll_key':r}) task.add('crawler') self.response.set_status(200) except Timeout: logging.error('FAIL : timeout getting the route loader tasks spawned') self.response.set_status(200) self.response.out.write("timeout") return