def save_route(route_xml, api_call): def save_directions(route_xml, route_obj, api_call): directions = route_xml.findall('direction') for direction in directions: d = Direction.get_or_create( db.session, tag=direction.get('tag'), title=direction.get('title'), name=direction.get('name'), route_id=route_obj.id, api_call_id=api_call.id) def save_stops(route_xml, route_obj, api_call): stops = route_xml.findall('stop') for stop in stops: s = Stop.get_or_create(db.session, title=stop.get('title'), lat=float(stop.get('lat')), lon=float(stop.get('lon')), stop_id=stop.get('stopId'), api_call_id=api_call.id) db.session.flush() rs = RouteStop.get_or_create(db.session, route_id=route_obj.id, stop_id=s.id, stop_tag=stop.get('tag')) r = Route.get_or_create( db.session, tag=route_xml.get('tag'), title=route_xml.get('title'), color=route_xml.get('color'), opposite_color=route_xml.get('oppositeColor'), lat_min=float(route_xml.get('latMin')), lat_max=float(route_xml.get('latMax')), lon_min=float(route_xml.get('lonMin')), lon_max=float(route_xml.get('lonMax')), agency_id=agency.id, api_call=api_call) db.session.flush() save_directions(route_xml, r, api_call) save_stops(route_xml, r, api_call) db.session.flush() return r
def save_route(route_xml, api_call): def save_directions(route_xml, route_obj, api_call): directions = route_xml.findall('direction') for direction in directions: d = Direction.get_or_create(db.session, tag = direction.get('tag'), title = direction.get('title'), name = direction.get('name'), route_id = route_obj.id, api_call_id = api_call.id) def save_stops(route_xml, route_obj, api_call): stops = route_xml.findall('stop') for stop in stops: s = Stop.get_or_create(db.session, title = stop.get('title'), lat = float(stop.get('lat')), lon = float(stop.get('lon')), stop_id = stop.get('stopId'), api_call_id = api_call.id) db.session.flush() rs = RouteStop.get_or_create(db.session, route_id = route_obj.id, stop_id = s.id, stop_tag = stop.get('tag')) r = Route.get_or_create(db.session, tag = route_xml.get('tag'), title = route_xml.get('title'), color = route_xml.get('color'), opposite_color = route_xml.get('oppositeColor'), lat_min = float(route_xml.get('latMin')), lat_max = float(route_xml.get('latMax')), lon_min = float(route_xml.get('lonMin')), lon_max = float(route_xml.get('lonMax')), agency_id = agency.id, api_call = api_call) db.session.flush() save_directions(route_xml, r, api_call) save_stops(route_xml, r, api_call) db.session.flush() return r