def get_coordinate_of_city(self, city_name: str) -> Coordinates:
        geocode = self._client.pelias_search(text=city_name)

        if geocode is None:
            raise ValueError('Could not collect data from OpenRouteService. Maybe wrong api key?')

        coordinates = Coordinates()
        if len(geocode['features']) > 0:
            coordinates.longitude = geocode['features'][0]['geometry']['coordinates'][0]
            coordinates.latitude = geocode['features'][0]['geometry']['coordinates'][1]

        return coordinates
Пример #2
0
    def get_coordinates_from_city(self, city: str) -> Coordinates:
        self._connect_if_not_connected()

        sql_string = "SELECT longitude, latitude FROM cities WHERE city = ?"
        self._cursor.execute(sql_string, (city, ))

        answer = self._cursor.fetchone()

        coordinates = Coordinates()
        if answer:
            coordinates.longitude = answer[0]
            coordinates.latitude = answer[1]

        return coordinates