def stopRouteRequest(stopID, routeID, devStoreKey): logging.debug("Stop/Route Request started") # got fetch all of the data for this stop sid = stopID + str(devStoreKey) + str(time.time()) routes = asynch.aggregateBusesAsynch(sid,stopID,routeID) if routes is None: response_dict = {'status':'0', 'timestamp':utils.getLocalTimestamp(), 'info':'No routes found' } return response_dict response_dict = {'status':'0', 'timestamp':utils.getLocalTimestamp() } # there should only be results. we assume the results are sorted by time stop_dict = {'stopID':stopID,} route_results = [] for r in routes: if not utils.inthepast(r.arrivalTime): route_results.append(dict({'routeID':r.routeID, 'vehicleID':'unknown', 'minutes':str(utils.computeCountdownMinutes(r.arrivalTime)), 'arrivalTime':r.arrivalTime, 'destination':r.destination, })) # add the populated stop details to the response stop_dict.update({'route':route_results}); response_dict.update({'stop':stop_dict}) return response_dict
def stopRequest(stopID, devStoreKey): logging.debug("Stop Request started") response_dict = {'status':'0', 'timestamp':utils.getLocalTimestamp() } # unique key to track this request t = str(time.time()).split('.')[0] sid = stopID + str(devStoreKey) + t # got fetch all of the data for this stop routes = asynch.aggregateBusesAsynch(sid,stopID) if routes is None or len(routes) == 0: response_dict['status'] = '-1' response_dict['description'] = 'No routes found for this stop' response_dict['stopID'] = stopID return response_dict # get the stop details stop_dict = {'stopID':stopID,} # take the first 10 results. we assume the results are sorted by time #route_results = sorted(route_results, key=attrgetter('time')) route_results = [] for r in routes: minutes = utils.computeCountdownMinutes(r.arrivalTime) if minutes > 0: route_results.append(dict({'routeID':r.routeID, 'vehicleID':'unknown', 'minutes':str(minutes), 'arrivalTime':r.arrivalTime, 'destination':r.destination, })) # add the populated stop details to the response stop_dict.update({'route':route_results}); response_dict.update({'stop':stop_dict}) # cleanup the results asynch.clean(sid) return response_dict