Exemplo n.º 1
0
    def poi(self, name, city=None):
        poi = Fetch.try_fetch(self._db.get_poi, name)

        if poi:
            return poi

        content = request_point(name=name,
                                api_key=self._api_key,
                                city=city,
                                osm_only=True)

        try:
            id, type = Geocode.get_id_type(content)
        except BufferError as e:
            log('Warning: {}'.format(e))
            log('Skipping: {}'.format(name))
            return None

        name = Geocode.get_name(content)
        self._db.put_geocode(id=id, content=content)

        if type == 'polyline':
            geocode = Fetch.try_fetch(self._db.get_geocode, id)
            poi = Poi(init_from='geocode', content=geocode)
        else:
            content = request_node(id=id, api_key=self._api_key)
            node = self._db.put_node(id=id, content=content)
            poi = Poi(init_from='node', content=node)

        poi = self._db.put_poi(name=name, content=poi)

        return poi
Exemplo n.º 2
0
    def try_fetch(query, argument):
        try:
            city = query(argument)
        except AssertionError:
            log('Warning: Invalid content of {}!'.format(argument))
            city = None

        return city
Exemplo n.º 3
0
    def optimization(self, targets, params):
        if not targets:
            log('Warning: Nothing to optimize!')
            exit(0)

        content = request_route_optimization(targets=targets,
                                             params=params,
                                             profile=self._profile,
                                             api_key=self._api_key)

        return content
Exemplo n.º 4
0
Arquivo: scp.py Projeto: qurit/raiven
def handle_association_request(event):
    requestor_ae_title, called_ae_title = get_ae_titles(event)

    with DicomNodeService() as node_service:
        node_service.update_or_create_from_connection(
            title=requestor_ae_title,
            host=event.assoc.requestor.address,
            implementation_version_name=encode_aet(
                event.assoc.requestor.implementation_version_name))

    # TODO: Not in list of allowed connections and allow push to pipe
    if not is_valid_ae_title(called_ae_title):
        event.assoc.acse.send_reject(REJECTED_PERMANENT, SOURCE_SERVICE_USER,
                                     DIAG_CALLED_AET_NOT_RECOGNIZED)
        logger.log(
            f"REJECTED REQUEST ASSOCIATION FROM {requestor_ae_title} DUE TO UNKNOWN CALLED AET: {called_ae_title}"
        )

    # ALREADY CONNECTED
    elif requestor_ae_title in CONNECTIONS:
        event.assoc.acse.send_reject(REJECTED_TRANSIENT, SOURCE_PROVIDER_USER,
                                     DIAG_LOCAL_LIMIT_EXCEEDED)
        logger.log(
            f"REJECTED REQUEST ASSOCIATION FROM {requestor_ae_title} AS IT IS ALREADY CONNECTED"
        )
    else:
        path = pathlib.Path(config.UPLOAD_DIR) / 'tmp' / str(uuid.uuid1())
        CONNECTIONS[requestor_ae_title] = path
        path.mkdir(parents=True)
        logger.log(f"ACCEPTED REQUEST ASSOCIATION FROM {requestor_ae_title}")
Exemplo n.º 5
0
if __name__ == '__main__':
    try:
        args = parse_args()
        db = Database()
        params = Params(args.params)
        fetch = Fetch(db=db, profile=params.profile, api_key=args.api_key)

        city = params.city
        pois = params.pois

        if len(pois) > 20:
            input('Do you really want to process {} pois? (Enter)'.format(
                len(pois)))

        city = fetch.city(name=city)
        log(city, indent=0, verbose=True)

        start_point = fetch.point(name=params.from_place, city=city)
        log(start_point, indent=0, verbose=True)

        end_point = fetch.point(name=params.to_place, city=city)
        log(end_point, indent=0, verbose=True)

        params.set_coordinates(coord_from=start_point.coordinates,
                               coord_to=end_point.coordinates)

        targets = []
        pois_to_visualize = []

        pois_to_visualize.append(start_point)