Esempio n. 1
0
    def get(self, region=None):
        args = self.parsers['get'].parse_args()

        if args.get('origin_mode') is None:
            args['origin_mode'] = ['walking']
        if args.get('destination_mode') is None:
            args['destination_mode'] = ['walking']

        self.region = i_manager.get_region(region)
        if args['origin']:
            args['origin'] = transform_id(args['origin'])
        if args['destination']:
            args['destination'] = transform_id(args['destination'])
        if not (args['destination'] or args['origin']):
            abort(400,
                  message="you should provide a 'from' or a 'to' argument")
        if not args['max_duration']:
            abort(400, message="you should provide a 'max_duration' argument")
        if not args['datetime']:
            args['datetime'] = args['_current_datetime']

        set_request_timezone(self.region)
        args['original_datetime'] = args['datetime']
        original_datetime = args['original_datetime']
        new_datetime = self.convert_to_utc(original_datetime)
        args['datetime'] = date_to_timestamp(new_datetime)

        response = i_manager.dispatch(args,
                                      "graphical_isochrons",
                                      instance_name=region)

        return response
Esempio n. 2
0
 def get(self, region=None, lon=None, lat=None, uri=None):
     self.region = i_manager.get_region(region, lon, lat)
     timezone.set_request_timezone(self.region)
     args = self.parsers["get"].parse_args()
     if args['disable_geojson']:
         g.disable_geojson = True
     if uri:
         if uri[-1] == '/':
             uri = uri[:-1]
         uris = uri.split("/")
         if len(uris) >= 2:
             args["uri"] = transform_id(uris[-1])
             # for coherence we check the type of the object
             obj_type = uris[-2]
             if obj_type not in places_types:
                 abort(404, message='places_nearby api not available for {}'.format(obj_type))
         else:
             abort(404)
     elif lon and lat:
         # check if lon and lat can be converted to float
         float(lon)
         float(lat)
         args["uri"] = "coord:{}:{}".format(lon, lat)
     else:
         abort(404)
     args["filter"] = args["filter"].replace(".id", ".uri")
     self._register_interpreted_parameters(args)
     response = i_manager.dispatch(args, "places_nearby", instance_name=self.region)
     return response, 200
Esempio n. 3
0
    def get(self, region=None, uri=None):

        args = self.parsers['get'].parse_args()
        self.region = i_manager.get_region(region)
        args.update(self.parse_args(region, uri))

        if not (args['destination'] or args['origin']):
            abort(400,
                  message="you should provide a 'from' or a 'to' argument")
        if not args['max_duration']:
            abort(400, message="you should provide a 'max_duration' argument")
        if args['destination'] and args['origin']:
            abort(400,
                  message="you cannot provide a 'from' and a 'to' argument")

        set_request_timezone(self.region)
        original_datetime = args['original_datetime']
        if original_datetime:
            new_datetime = self.convert_to_utc(original_datetime)
        else:
            new_datetime = args['_current_datetime']
        args['datetime'] = date_to_timestamp(new_datetime)

        response = i_manager.dispatch(args, "heat_maps", self.region)

        return response
Esempio n. 4
0
    def get(self, region=None, lon=None, lat=None, uri=None):
        self.region = i_manager.get_region(region, lon, lat)
        timezone.set_request_timezone(self.region)
        args = self.parsers["get"].parse_args()

        if args['disable_geojson']:
            g.disable_geojson = True

        uris = []
        if uri:
            if uri[-1] == "/":
                uri = uri[:-1]
            uris = uri.split("/")
        args["filter"] = self.get_filter(uris, args)

        if args['since']:
            args['since'] = date_to_timestamp(
                self.convert_to_utc(args['since']))
        if args['until']:
            args['until'] = date_to_timestamp(
                self.convert_to_utc(args['until']))

        response = i_manager.dispatch(args,
                                      "line_reports",
                                      instance_name=self.region)

        return response
Esempio n. 5
0
 def get(self, id, region=None, lon=None, lat=None):
     self.region = i_manager.get_region(region, lon, lat)
     args = {"uri": transform_id(id)}
     response = i_manager.dispatch(args,
                                   "place_uri",
                                   instance_name=self.region)
     return response, 200
Esempio n. 6
0
    def get(self, region=None, lon=None, lat=None, uri=None):
        self.region = i_manager.get_region(region, lon, lat)
        timezone.set_request_timezone(self.region)
        args = self.parsers["get"].parse_args()

        if uri:
            if uri[-1] == "/":
                uri = uri[:-1]
            uris = uri.split("/")
            args["filter"] = self.get_filter(uris)
        else:
            args["filter"] = ""

        self._register_interpreted_parameters(args)

        response = i_manager.dispatch(args,
                                      "disruptions",
                                      instance_name=self.region)

        # we store in g if we want the disruptions in the old or in the new format
        # It's not well designed, but it is temporary
        # DELETE that asap
        g.use_old_disruptions = args['_use_old_disruptions']

        return response
Esempio n. 7
0
    def get(self, region=None, lon=None, lat=None, uri=None):

        args = self.parsers['get'].parse_args()
        self.region = i_manager.get_region(region, lon, lat)
        args.update(self.parse_args(region, uri))

        if not (args['destination'] or args['origin']):
            abort(400,
                  message="you should provide a 'from' or a 'to' argument")
        if not args['max_duration'] and not args["boundary_duration[]"]:
            abort(
                400,
                message=
                "you should provide a 'boundary_duration[]' or a 'max_duration' argument"
            )
        if args['destination'] and args['origin']:
            abort(400,
                  message="you cannot provide a 'from' and a 'to' argument")
        if 'ridesharing' in args['origin_mode'] or 'ridesharing' in args[
                'destination_mode']:
            abort(400, message='ridesharing isn\'t available on isochrone')

        set_request_timezone(self.region)
        original_datetime = args['original_datetime']
        if original_datetime:
            new_datetime = self.convert_to_utc(original_datetime)
        args['datetime'] = date_to_timestamp(new_datetime)

        response = i_manager.dispatch(args, "graphical_isochrones",
                                      self.region)

        return response
Esempio n. 8
0
    def get(self, region=None, lon=None, lat=None, uri=None):
        self.region = i_manager.get_region(region, lon, lat)
        timezone.set_request_timezone(self.region)
        args = self.parsers["get"].parse_args()

        if args['disable_geojson']:
            g.disable_geojson = True

        # for retrocompatibility purpose
        for forbid_id in args['__temporary_forbidden_id[]']:
            args['forbidden_uris[]'].append(forbid_id)

        if uri:
            if uri[-1] == "/":
                uri = uri[:-1]
            uris = uri.split("/")
            args["filter"] = self.get_filter(uris, args)
        else:
            args["filter"] = ""

        response = i_manager.dispatch(args,
                                      "traffic_reports",
                                      instance_name=self.region)

        return response
Esempio n. 9
0
    def get(self, region=None, lon=None, lat=None, uri=None, id=None):
        self.region = i_manager.get_region(region, lon, lat)
        args = self.parsers["get"].parse_args()

        # for retrocompatibility purpose
        for forbid_id in args['__temporary_forbidden_id[]']:
            args['forbidden_uris[]'].append(forbid_id)

        if id:
            args["filter"] = "calendar.uri=" + id
        elif uri:
            # Calendars of line
            args["filter"] = self.get_filter(split_uri(uri), args)
        else:
            args["filter"] = ""

        # change dt to utc
        args['_current_datetime'] = self.convert_to_utc(
            args['_current_datetime'])

        self._register_interpreted_parameters(args)
        response = i_manager.dispatch(args,
                                      "calendars",
                                      instance_name=self.region)
        return response
Esempio n. 10
0
    def get(self, region=None, lon=None, lat=None, uri=None):

        args = self.parsers['get'].parse_args()
        self.region = i_manager.get_region(region, lon, lat)
        args.update(self.parse_args(region, uri))

        # We set default modes for fallback modes.
        # The reason why we cannot put default values in parser_get.add_argument() is that, if we do so,
        # fallback modes will always have a value, and traveler_type will never override fallback modes.
        args['origin_mode'] = args.get('origin_mode') or ['walking']
        args['destination_mode'] = args['destination_mode'] or ['walking']

        if not (args['destination'] or args['origin']):
            abort(400,
                  message="you should provide a 'from' or a 'to' argument")
        if not args['max_duration']:
            abort(400, message="you should provide a 'max_duration' argument")
        if args['destination'] and args['origin']:
            abort(400,
                  message="you cannot provide a 'from' and a 'to' argument")
        if 'ridesharing' in args['origin_mode'] or 'ridesharing' in args[
                'destination_mode']:
            abort(400, message='ridesharing isn\'t available on heatmaps')

        set_request_timezone(self.region)
        original_datetime = args['original_datetime']
        if original_datetime:
            new_datetime = self.convert_to_utc(original_datetime)
        args['datetime'] = date_to_timestamp(new_datetime)

        response = i_manager.dispatch(args, "heat_maps", self.region)

        return response
Esempio n. 11
0
 def get(self, region=None, lon=None, lat=None, uri=None):
     self.region = i_manager.get_region(region, lon, lat)
     timezone.set_request_timezone(self.region)
     args = self.parsers["get"].parse_args()
     if uri:
         if uri[-1] == '/':
             uri = uri[:-1]
         uris = uri.split("/")
         if len(uris) > 1:
             args["uri"] = transform_id(uris[-1])
         else:
             abort(404)
     elif lon and lat:
         # check if lon and lat can be converted to float
         float(lon)
         float(lat)
         args["uri"] = "coord:{}:{}".format(lon, lat)
     else:
         abort(404)
     args["filter"] = args["filter"].replace(".id", ".uri")
     self._register_interpreted_parameters(args)
     response = i_manager.dispatch(args,
                                   "places_nearby",
                                   instance_name=self.region)
     return response, 200
Esempio n. 12
0
 def _response_from_place_uri(self, instance_name, args):
     response = i_manager.dispatch(args,
                                   "place_uri",
                                   instance_name=instance_name)
     if response.get('places', []):
         return {"address": response['places'][0]['address']}
     return None
Esempio n. 13
0
    def get(self, region=None, lon=None, lat=None, uri=None):
        self.region = i_manager.get_region(region, lon, lat)
        timezone.set_request_timezone(self.region)
        args = self.parsers["get"].parse_args()

        if args['disable_geojson']:
            g.disable_geojson = True

        # for retrocompatibility purpose
        for forbid_id in args['__temporary_forbidden_id[]']:
            args['forbidden_uris[]'].append(forbid_id)

        args["filter"] = self.get_filter(split_uri(uri), args)

        since = args.get('since')
        until = args.get('until')
        if since and until and since > until:
            abort(400, message='until must be >= since')

        if since:
            args['since'] = date_to_timestamp(self.convert_to_utc(since))
        if until:
            args['until'] = date_to_timestamp(self.convert_to_utc(until))

        response = i_manager.dispatch(args,
                                      "traffic_reports",
                                      instance_name=self.region)

        return response
Esempio n. 14
0
 def get(self, region=None, lon=None, lat=None, uri=None):
     self.region = i_manager.get_region(region, lon, lat)
     args = self.parsers["get"].parse_args()
     if uri:
         if uri[-1] == '/':
             uri = uri[:-1]
         uris = uri.split("/")
         if len(uris) > 1:
             id = uris[-1]
             if id.count(";") == 1:
                 lon, lat = id.split(";")
                 try:
                     args["uri"] = "coord:" + str(float(lon)) + ":"
                     args["uri"] += str(float(lat))
                 except ValueError:
                     pass
             elif id[:5] == "admin":
                 args["uri"] = "admin:" + id.split(":")[-1]
             else:
                 args["uri"] = id
         else:
             abort(404)
     elif lon and lat:
         args["uri"] = "coord:" + str(float(lon)) + ":" + str(float(lat))
     else:
         abort(404)
     args["filter"] = args["filter"].replace(".id", ".uri")
     response = i_manager.dispatch(args,
                                   "places_nearby",
                                   instance_name=self.region)
     return response, 200
Esempio n. 15
0
    def get(self, id, region=None, lon=None, lat=None):
        args = self.parsers["get"].parse_args()
        args.update({
            "uri": transform_id(id),
            "_current_datetime": datetime.utcnow()
        })
        request_id = "places_{}".format(flask.request.id)
        args["request_id"] = request_id

        if any([region, lon, lat]):
            self.region = i_manager.get_region(region, lon, lat)
            timezone.set_request_timezone(self.region)
            response = i_manager.dispatch(args,
                                          "place_uri",
                                          instance_name=self.region)
        else:
            user = authentication.get_user(token=authentication.get_token(),
                                           abort_if_no_token=False)
            available_instances = get_all_available_instances(user)
            autocomplete = global_autocomplete.get('bragi')
            if not autocomplete:
                raise TechnicalError(
                    'world wide autocompletion service not available')
            response = autocomplete.get_by_uri(args["uri"],
                                               request_id=request_id,
                                               instances=available_instances)

        return response, 200
Esempio n. 16
0
    def get(self, region=None, lon=None, lat=None):
        args = self.parsers["get"].parse_args()
        self._register_interpreted_parameters(args)
        if len(args['q']) == 0:
            abort(400, message="Search word absent")

        if args['disable_geojson']:
            g.disable_geojson = True

        user = authentication.get_user(token=authentication.get_token(), abort_if_no_token=False)

        if args['shape'] is None and user and user.shape:
            args['shape'] = json.loads(user.shape)

        if user and user.default_coord:
            if args['from'] is None:
                args['from'] = CoordFormat()(user.default_coord)
        else:
            if args['from'] == '':
                raise InvalidArguments("if 'from' is provided it cannot be null")

        # If a region or coords are asked, we do the search according
        # to the region, else, we do a word wide search

        if any([region, lon, lat]):
            self.region = i_manager.get_region(region, lon, lat)
            timezone.set_request_timezone(self.region)
            response = i_manager.dispatch(args, "places", instance_name=self.region)
        else:
            available_instances = get_all_available_instances(user)
            autocomplete = global_autocomplete.get('bragi')
            if not autocomplete:
                raise TechnicalError('world wide autocompletion service not available')
            response = autocomplete.get(args, instances=available_instances)
        return response, 200
Esempio n. 17
0
    def get(self, region=None, lon=None, lat=None, uri=None, id=None):
        args = self.parsers["get"].parse_args()

        if args['disable_geojson']:
            g.disable_geojson = True

        # for retrocompatibility purpose
        for forbid_id in args['__temporary_forbidden_id[]']:
            args['forbidden_uris[]'].append(forbid_id)

        if "odt_level" in args and args["odt_level"] != "all" and "lines" not in self.collection:
            abort(404, message="bad request: odt_level filter can only be applied to lines")

        if region is None and lat is None and lon is None:
            if "external_code" in args and args["external_code"]:
                type_ = collections_to_resource_type[self.collection]
                for instance in i_manager.get_regions():
                    res = i_manager.instances[instance].has_external_code(type_, args["external_code"])
                    if res:
                        region = instance
                        id = res
                        break
                if not region:
                    abort(404, message="Unable to find an object for the uri %s" % args["external_code"])
            else:
                abort(503, message="Not implemented yet")

        self.region = i_manager.get_region(region, lon, lat)

        # we store the region in the 'g' object, which is local to a request
        set_request_timezone(self.region)

        # change dt to utc
        if args['since']:
            args['_original_since'] = args['since']
            args['since'] = date_to_timestamp(self.convert_to_utc(args['since']))
        if args['until']:
            args['_original_until'] = args['until']
            args['until'] = date_to_timestamp(self.convert_to_utc(args['until']))

        if not self.region:
            return {"error": "No region"}, 404
        uris = []
        if uri:
            if uri[-1] == "/":
                uri = uri[:-1]
            uris = uri.split("/")
            if self.collection is None:
                self.collection = uris[-1] if len(uris) % 2 != 0 else uris[-2]
        args["filter"] = self.get_filter(uris, args)

        if self.collection and id:
            f = u'{o}.uri={v}'.format(o=collections_to_resource_type[self.collection], v=protect(id))
            if args.get("filter"):
                args["filter"] = '({}) and {}'.format(args["filter"], f)
            else:
                args["filter"] = f

        response = i_manager.dispatch(args, self.collection, instance_name=self.region)
        return response
Esempio n. 18
0
    def get(self, region=None, lon=None, lat=None):
        args = self.parsers["get"].parse_args()
        self._register_interpreted_parameters(args)
        if len(args['q']) == 0:
            abort(400, message="Search word absent")

        if args['disable_geojson']:
            g.disable_geojson = True

        user = authentication.get_user(token=authentication.get_token(),
                                       abort_if_no_token=False)

        args['shape'] = json.loads(user.shape) if user and user.shape else None

        # If a region or coords are asked, we do the search according
        # to the region, else, we do a word wide search

        if any([region, lon, lat]):
            self.region = i_manager.get_region(region, lon, lat)
            timezone.set_request_timezone(self.region)
            response = i_manager.dispatch(args,
                                          "places",
                                          instance_name=self.region)
        else:
            authentication.check_access_to_global_places(user)
            autocomplete = global_autocomplete.get('bragi')
            if autocomplete:
                response = autocomplete.get(args, instance=None)
            else:
                raise TechnicalError(
                    'world wide autocompletion service not available')
        return response, 200
Esempio n. 19
0
    def get(self, region=None, lon=None, lat=None, uri=None):
        self.region = i_manager.get_region(region, lon, lat)
        timezone.set_request_timezone(self.region)
        args = self.parsers["get"].parse_args()

        if args['disable_geojson']:
            g.disable_geojson = True

        args["filter"] = self.get_filter(split_uri(uri), args)

        # change dt to utc
        args['_current_datetime'] = self.convert_to_utc(
            args['_current_datetime'])

        if args['since']:
            args['since'] = date_to_timestamp(
                self.convert_to_utc(args['since']))
        if args['until']:
            args['until'] = date_to_timestamp(
                self.convert_to_utc(args['until']))

        response = i_manager.dispatch(args,
                                      "line_reports",
                                      instance_name=self.region)

        return response
Esempio n. 20
0
 def get(self, region):
     response = protobuf_to_dict(i_manager.dispatch({},
                                                    "status",
                                                    instance_name=region),
                                 use_enum_labels=True)
     instance = i_manager.instances[region]
     response['status']['parameters'] = instance
     return response, 200
Esempio n. 21
0
    def get(self, region=None, lon=None, lat=None, uri=None):
        args = self.parsers['get'].parse_args()
        # TODO : Changer le protobuff pour que ce soit propre
        if args['destination_mode'] == 'vls':
            args['destination_mode'] = 'bss'
        if args['origin_mode'] == 'vls':
            args['origin_mode'] = 'bss'

        #count override min_nb_journey or max_nb_journey
        if 'count' in args and args['count']:
            args['min_nb_journeys'] = args['count']
            args['max_nb_journeys'] = args['count']

        # for last and first section mode retrocompatibility
        if 'first_section_mode' in args and args['first_section_mode']:
            args['origin_mode'] = args['first_section_mode']
        if 'last_section_mode' in args and args['last_section_mode']:
            args['destination_mode'] = args['last_section_mode']

        if region:
            self.region = i_manager.get_region(region)
            #we check that the user can use this api
            authentification.authenticate(region, 'ALL', abort=True)
            if uri:
                objects = uri.split('/')
                if objects and len(objects) % 2 == 0:
                    args['origin'] = objects[-1]
                else:
                    abort(503,
                          message="Unable to compute journeys "
                          "from this object")

        if not args[
                "origin"]:  #@vlara really ? I though we could do reverse isochrone ?
            #shoudl be in my opinion if not args["origin"] and not args["destination"]:
            abort(400, message="from argument is required")

        if not region:
            #TODO how to handle lon/lat ? don't we have to override args['origin'] ?
            self.region = compute_regions(args)

        #we transform the origin/destination url to add information
        if args['origin']:
            args['origin'] = self.transform_id(args['origin'])
        if args['destination']:
            args['destination'] = self.transform_id(args['destination'])

        if not args['datetime']:
            args['datetime'] = datetime.now().strftime('%Y%m%dT1337')

        api = None
        if args['destination']:
            api = 'journeys'
        else:
            api = 'isochrone'

        response = i_manager.dispatch(args, api, instance_name=self.region)
        return response
Esempio n. 22
0
 def get(self, region=None, lon=None, lat=None):
     self.region = i_manager.get_region(region, lon, lat)
     args = self.parsers["get"].parse_args()
     if len(args['q']) == 0:
         abort(400, message="Search word absent")
     response = i_manager.dispatch(args,
                                   "places",
                                   instance_name=self.region)
     return response, 200
Esempio n. 23
0
    def get(self, region=None, lon=None, lat=None, uri=None):
        args = self.parsers['get'].parse_args()
        # TODO : Changer le protobuff pour que ce soit propre
        if args['destination_mode'] == 'vls':
            args['destination_mode'] = 'bss'
        if args['origin_mode'] == 'vls':
            args['origin_mode'] = 'bss'

        #count override min_nb_journey or max_nb_journey
        if 'count' in args and args['count']:
            args['min_nb_journeys'] = args['count']
            args['max_nb_journeys'] = args['count']

        # for last and first section mode retrocompatibility
        if 'first_section_mode' in args and args['first_section_mode']:
            args['origin_mode'] = args['first_section_mode']
        if 'last_section_mode' in args and args['last_section_mode']:
            args['destination_mode'] = args['last_section_mode']

        if region or (lon and lat):
            self.region = i_manager.get_region(region, lon, lat)
            if uri:
                objects = uri.split('/')
                if objects and len(objects) % 2 == 0:
                    args['origin'] = objects[-1]
                else:
                    abort(503,
                          message="Unable to compute journeys "
                          "from this object")
        else:
            if args['origin']:
                self.region = i_manager.key_of_id(args['origin'])
            elif args['destination']:
                self.region = i_manager.key_of_id(args['destination'])
            # else:
            #    raise RegionNotFound("")

        #we transform the origin/destination url to add information
        if args['origin']:
            args['origin'] = self.transform_id(args['origin'])
        if args['destination']:
            args['destination'] = self.transform_id(args['destination'])

        if not args['datetime']:
            args['datetime'] = datetime.now().strftime('%Y%m%dT1337')
        api = None
        if args['destination']:
            api = 'journeys'
        else:
            api = 'isochrone'

        if not args["origin"]:
            abort(400, message="from argument is required")

        response = i_manager.dispatch(args, api, instance_name=self.region)
        return response
Esempio n. 24
0
 def get(self, region=None, lon=None, lat=None):
     self.region = i_manager.get_region(region, lon, lat)
     timezone.set_request_timezone(self.region)
     args = self.parsers["get"].parse_args()
     self._register_interpreted_parameters(args)
     if len(args['q']) == 0:
         abort(400, message="Search word absent")
     response = i_manager.dispatch(args, "pt_objects",
                                   instance_name=self.region)
     return response, 200
Esempio n. 25
0
    def _response_from_places_nearby(self, instance_name, args):
        response = i_manager.dispatch(args, "places_nearby", instance_name=instance_name)
        if len(response.places_nearby) > 0:
            e_type = response.places_nearby[0].embedded_type
            if _NAVITIATYPE.values_by_name["ADDRESS"].number == e_type:
                from jormungandr.interfaces.v1.serializer.api import PlacesNearbySerializer

                new_address = PlacesNearbySerializer(response).data
                return {"address": new_address["places_nearby"][0]["address"]}
        return None
Esempio n. 26
0
 def get(self, region=None):
     args = self.parsers["get"].parse_args()
     if region is None:
         region = i_manager.key_of_id(args["origin"])
     response = i_manager.dispatch(args, "isochrone", instance_name=region)
     if response.journeys:
         (before, after) = extremes(response, request)
         if before and after:
             response.prev = before
             response.next = after
     return protobuf_to_dict(response, use_enum_labels=True), 200
Esempio n. 27
0
    def get(self, region=None, lon=None, lat=None):
        args = self.parsers["get"].parse_args()
        self._register_interpreted_parameters(args)
        size_q = len(args['q'])
        if size_q == 0:
            abort(400, message="Search word absent")

        if size_q > 1024:
            abort(
                413,
                message="Number of characters allowed for the search is 1024")

        if args['disable_geojson']:
            g.disable_geojson = True

        user = authentication.get_user(token=authentication.get_token(),
                                       abort_if_no_token=False)

        if args['shape'] is None and user and user.shape:
            args['shape'] = json.loads(user.shape)

        if not args.get("shape_scope[]") and user:
            args.update({"shape_scope[]": user.shape_scope})

        if user and user.default_coord:
            if args['from'] is None:
                args['from'] = CoordFormat()(user.default_coord)
        else:
            if args['from'] == '':
                raise InvalidArguments(
                    "if 'from' is provided it cannot be null")

        # If a region or coords are asked, we do the search according
        # to the region, else, we do a word wide search
        args["request_id"] = args.get('request_id', flask.request.id)
        if any([region, lon, lat]):
            self.region = i_manager.get_region(region, lon, lat)

            # when autocompletion is done on a specific coverage we want to filter on its shape
            if not args['shape']:
                instance = i_manager.instances.get(self.region)
                args['shape'] = build_instance_shape(instance)
            timezone.set_request_timezone(self.region)
            response = i_manager.dispatch(args,
                                          "places",
                                          instance_name=self.region)
        else:
            available_instances = get_all_available_instances(user)
            autocomplete = global_autocomplete.get('bragi')
            if not autocomplete:
                raise TechnicalError(
                    'world wide autocompletion service not available')
            response = autocomplete.get(args, instances=available_instances)
        return response, 200
Esempio n. 28
0
 def get(self, id, region=None, lon=None, lat=None):
     self.region = i_manager.get_region(region, lon, lat)
     args = self.parsers["get"].parse_args()
     args.update({
         "uri": transform_id(id),
         "_current_datetime": datetime.datetime.utcnow()
     })
     response = i_manager.dispatch(args,
                                   "place_uri",
                                   instance_name=self.region)
     return response, 200
Esempio n. 29
0
    def get(self, region=None, lon=None, lat=None, id=None, *args, **kwargs):
        if id is not None:
            splitted = id.split(";")
            if len(splitted) != 2:
                abort(
                    404,
                    message='invalid coords [{}], should be <lon:lon>;<lat:lat>'
                    .format(id))
            lon, lat = splitted
            try:
                float(lon)
                float(lat)
            except ValueError:
                abort(
                    404,
                    message='invalid coords [{}], should be <lon:lon>;<lat:lat>'
                    .format(id))

        if region is None:
            regions = i_manager.get_regions("", lon, lat)
        else:
            regions = [region]

        args = {
            "uri": "coord:{}:{}".format(lon, lat),
            "count": 1,
            "distance": 200,
            "type[]": ["address"],
            "depth": 1,
            "start_page": 0,
            "filter": "",
            "_current_datetime": datetime.datetime.utcnow()
        }

        self._register_interpreted_parameters(args)
        result = OrderedDict()

        for r in regions:
            self.region = r
            result.update(regions=[r])
            pb_result = i_manager.dispatch(args,
                                           "places_nearby",
                                           instance_name=r)
            if len(pb_result.places_nearby) > 0:
                e_type = pb_result.places_nearby[0].embedded_type
                if _NAVITIATYPE.values_by_name["ADDRESS"].number == e_type:
                    new_address = marshal(pb_result.places_nearby[0].address,
                                          address)
                    result.update(address=new_address)
                    return result, 200

        result.update(regions=regions)
        result.update(message="No address for these coords")
        return result, 404
Esempio n. 30
0
 def get(self, region=None, lon=None, lat=None):
     region_str = i_manager.get_region(region, lon, lat)
     response = protobuf_to_dict(
         i_manager.dispatch({}, "status", instance_name=region_str), use_enum_labels=True
     )
     instance = i_manager.instances[region_str]
     add_common_status(response, instance)
     response['status']['parameters'] = instance
     response['status']['traveler_profiles'] = travelers_profile.TravelerProfile.get_profiles_by_coverage(
         region_str
     )
     return response, 200