예제 #1
0
파일: simple.py 프로젝트: pbench/navitia
    def pt_objects(self, request, instance):
        req = request_pb2.Request()
        req.requested_api = type_pb2.pt_objects
        req.pt_objects.q = request['q']
        req.pt_objects.depth = request['depth']
        req.pt_objects.disable_geojson = request['disable_geojson']
        req.pt_objects.count = request['count']
        req.pt_objects.search_type = request['search_type']
        req._current_datetime = date_to_timestamp(request['_current_datetime'])
        if request["type[]"]:
            for type in request["type[]"]:
                req.pt_objects.types.append(pt_object_type[type])

        if request["admin_uri[]"]:
            for admin_uri in request["admin_uri[]"]:
                req.pt_objects.admin_uris.append(admin_uri)
        req.disable_disruption = request["disable_disruption"]
        req.pt_objects.filter = request['filter']

        resp = instance.send_and_receive(req)
        # The result contains places but not pt_objects,
        # object place is transformed to pt_object afterwards.
        if len(resp.places) == 0 and request['search_type'] == 0:
            request["search_type"] = 1
            return self.pt_objects(request, instance)
        build_pagination(request, resp)

        return resp
예제 #2
0
파일: simple.py 프로젝트: pbench/navitia
    def __on_ptref(self, resource_name, requested_type, request, instance):
        req = request_pb2.Request()
        req.requested_api = type_pb2.PTREFERENTIAL

        req.ptref.requested_type = requested_type
        req.ptref.filter = request.get("filter", '')
        req.ptref.depth = request["depth"]
        req.ptref.start_page = request["start_page"]
        req.ptref.count = request["count"]
        req.ptref.disable_geojson = request["disable_geojson"]
        req._current_datetime = date_to_timestamp(request["_current_datetime"])
        if request["odt_level"]:
            req.ptref.odt_level = pb_odt_level[request["odt_level"]]
        if request["forbidden_uris[]"]:
            for forbidden_uri in request["forbidden_uris[]"]:
                req.ptref.forbidden_uri.append(forbidden_uri)
        if request['since']:
            req.ptref.since_datetime = request['since']
        if request['until']:
            req.ptref.until_datetime = request['until']
        req.ptref.realtime_level = get_pb_data_freshness(request)
        req.disable_disruption = request["disable_disruption"]
        resp = instance.send_and_receive(req)
        build_pagination(request, resp)
        return resp
예제 #3
0
파일: kraken.py 프로젝트: Jamsta/navitia-1
    def get(self, request, instance):

        req = request_pb2.Request()
        req.requested_api = type_pb2.places
        req.places.q = request['q']
        req.places.depth = request['depth']
        req.places.count = request['count']
        req.places.search_type = request['search_type']
        req._current_datetime = date_to_timestamp(request['_current_datetime'])
        if request["type[]"]:
            for type in request["type[]"]:
                if type not in pb_type:
                    abort(422,
                          message="{} is not an acceptable type".format(type))

                req.places.types.append(pb_type[type])

        if request["admin_uri[]"]:
            for admin_uri in request["admin_uri[]"]:
                req.places.admin_uris.append(admin_uri)

        resp = instance.send_and_receive(req)

        if len(resp.places) == 0 and request['search_type'] == 0:
            req.places.search_type = 1
            resp = instance.send_and_receive(req)
        build_pagination(request, resp)
        return resp
예제 #4
0
    def get(self, request, instances):
        if len(instances) != 1:
            raise InvalidArguments('kraken autocomplete works only for one (and only one) instance')
        instance = instances[0]
        req = request_pb2.Request()
        req.requested_api = type_pb2.places
        req.places.q = request['q']
        req.places.depth = request['depth']
        req.places.count = request['count']
        req.places.search_type = request['search_type']
        req._current_datetime = date_to_timestamp(request['_current_datetime'])
        if request["type[]"]:
            for type in request["type[]"]:
                if type not in places_type:
                    abort(422, message="{} is not an acceptable type".format(type))

                req.places.types.append(places_type[type])

        if request["admin_uri[]"]:
            for admin_uri in request["admin_uri[]"]:
                req.places.admin_uris.append(admin_uri)

        resp = instance.send_and_receive(req)

        if len(resp.places) == 0 and request['search_type'] == 0:
            req.places.search_type = 1
            resp = instance.send_and_receive(req)

        build_pagination(request, resp)
        return resp
예제 #5
0
파일: simple.py 프로젝트: linvan/navitia
    def places_nearby(self, request, instance):
        req = request_pb2.Request()
        req.requested_api = type_pb2.places_nearby
        req.places_nearby.uri = request["uri"]
        req.places_nearby.distance = request["distance"]
        req.places_nearby.depth = request["depth"]
        req.places_nearby.count = request["count"]
        req.places_nearby.start_page = request["start_page"]
        if request["type[]"]:
            for type in request["type[]"]:
                if type not in pb_type:
                    abort(422,
                          message="{} is not an acceptable type".format(type))

                req.places_nearby.types.append(pb_type[type])
        req.places_nearby.filter = request["filter"]
        resp = instance.send_and_receive(req)
        build_pagination(request, resp)
        return resp
예제 #6
0
파일: simple.py 프로젝트: pbench/navitia
    def places_nearby(self, request, instance):
        req = request_pb2.Request()
        req.requested_api = type_pb2.places_nearby
        req.places_nearby.uri = request["uri"]
        req.places_nearby.distance = request["distance"]
        req.places_nearby.depth = request["depth"]
        req.places_nearby.count = request["count"]
        req.places_nearby.start_page = request["start_page"]
        req._current_datetime = date_to_timestamp(request["_current_datetime"])
        if request["type[]"]:
            for type in request["type[]"]:
                if type not in places_type:
                    abort(422, message="{} is not an acceptable type".format(type))

                req.places_nearby.types.append(places_type[type])
        req.places_nearby.filter = request["filter"]
        req.disable_disruption = request["disable_disruption"] if request.get("disable_disruption") else False
        resp = instance.send_and_receive(req)
        build_pagination(request, resp)
        return resp
예제 #7
0
    def __on_ptref(self, resource_name, requested_type, request, instance):
        req = request_pb2.Request()
        req.requested_api = type_pb2.PTREFERENTIAL

        req.ptref.requested_type = requested_type
        req.ptref.filter = request["filter"]
        req.ptref.depth = request["depth"]
        req.ptref.start_page = request["start_page"]
        req.ptref.count = request["count"]
        req.ptref.show_codes = request["show_codes"]
        req.ptref.datetime = date_to_timestamp(request["_current_datetime"])
        if request["odt_level"]:
            req.ptref.odt_level = pb_odt_level[request["odt_level"]]
        if request["forbidden_uris[]"]:
            for forbidden_uri in request["forbidden_uris[]"]:
                req.ptref.forbidden_uri.append(forbidden_uri)

        resp = instance.send_and_receive(req)
        build_pagination(request, resp)
        return resp