def _are_valid_client_credentials(here_client: herepy.RoutingApi) -> bool: """Check if the provided credentials are correct using defaults.""" known_working_origin = [38.9, -77.04833] known_working_destination = [39.0, -77.1] try: here_client.car_route( known_working_origin, known_working_destination, [ herepy.RouteMode[ROUTE_MODE_FASTEST], herepy.RouteMode[TRAVEL_MODE_CAR], herepy.RouteMode[TRAFFIC_MODE_DISABLED], ], ) except herepy.InvalidCredentialsError: return False return True
def _are_valid_client_credentials(here_client: herepy.RoutingApi) -> bool: """Check if the provided credentials are correct using defaults.""" known_working_origin = [38.9, -77.04833] known_working_destination = [39.0, -77.1] try: here_client.public_transport_timetable( known_working_origin, known_working_destination, True, [ RouteMode[ROUTE_MODE_FASTEST], RouteMode[TRAVEL_MODE_CAR], RouteMode[TRAFFIC_MODE_ENABLED], ], arrival=None, departure="now", ) except herepy.InvalidCredentialsError: return False return True
def validate_api_key(api_key: str) -> None: """Validate the user input allows us to connect.""" known_working_origin = [38.9, -77.04833] known_working_destination = [39.0, -77.1] RoutingApi(api_key).public_transport_timetable( known_working_origin, known_working_destination, True, [ RouteMode[ROUTE_MODE_FASTEST], RouteMode[TRAVEL_MODE_CAR], RouteMode[TRAFFIC_MODE_ENABLED], ], arrival=None, departure="now", )
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: """Set up HERE Travel Time from a config entry.""" api_key = config_entry.data[CONF_API_KEY] here_client = RoutingApi(api_key) setup_options(hass, config_entry) arrival = (dt.parse_time(config_entry.options[CONF_ARRIVAL_TIME]) if config_entry.options[CONF_ARRIVAL_TIME] is not None else None) departure = (dt.parse_time(config_entry.options[CONF_DEPARTURE_TIME]) if config_entry.options[CONF_DEPARTURE_TIME] is not None else None) here_travel_time_config = HERETravelTimeConfig( destination_latitude=config_entry.data.get(CONF_DESTINATION_LATITUDE), destination_longitude=config_entry.data.get( CONF_DESTINATION_LONGITUDE), destination_entity_id=config_entry.data.get( CONF_DESTINATION_ENTITY_ID), origin_latitude=config_entry.data.get(CONF_ORIGIN_LATITUDE), origin_longitude=config_entry.data.get(CONF_ORIGIN_LONGITUDE), origin_entity_id=config_entry.data.get(CONF_ORIGIN_ENTITY_ID), travel_mode=config_entry.data[CONF_MODE], route_mode=config_entry.options[CONF_ROUTE_MODE], units=config_entry.options[CONF_UNIT_SYSTEM], arrival=arrival, departure=departure, ) coordinator = HereTravelTimeDataUpdateCoordinator( hass, here_client, here_travel_time_config, ) hass.data.setdefault(DOMAIN, {})[config_entry.entry_id] = coordinator hass.config_entries.async_setup_platforms(config_entry, PLATFORMS) return True
#!/usr/bin/env python from herepy import ( RoutingApi, RouteMode, MatrixRoutingType, MatrixSummaryAttribute, RoutingTransportMode, RoutingMode, RoutingApiReturnField, RoutingMetric, RoutingApiSpanField, ) routing_api = RoutingApi(api_key="api_key") # fetches a bicycle route between two points response = routing_api.bicycle_route( waypoint_a=[41.9798, -87.8801], waypoint_b=[41.9043, -87.9216] ) print(response.as_dict()) # fetches a driving route between two points response = routing_api.car_route( waypoint_a=[11.0, 12.0], waypoint_b=[22.0, 23.0], modes=[RouteMode.car, RouteMode.fastest], ) print(response.as_dict()) # fetches a pedastrian route between two points
#!/usr/bin/env python from herepy import RoutingApi, RouteMode routing_api = RoutingApi(api_key="api_key") # fetches a bicycle route between two points response = routing_api.bicycle_route(waypoint_a=[41.9798, -87.8801], waypoint_b=[41.9043, -87.9216]) print(response.as_dict()) # fetches a driving route between two points response = routing_api.car_route( waypoint_a=[11.0, 12.0], waypoint_b=[22.0, 23.0], modes=[RouteMode.car, RouteMode.fastest], ) print(response.as_dict()) # fetches a pedastrian route between two points response = routing_api.pedastrian_route( waypoint_a=[11.0, 12.0], waypoint_b=[22.0, 23.0], modes=[RouteMode.pedestrian, RouteMode.fastest], ) print(response.as_dict()) # fetches a intermediate route from three points response = routing_api.intermediate_route( waypoint_a=[11.0, 12.0], waypoint_b=[15.0, 16.0],
postgreSQL_select_Query = """select id, first_pt_coord_lat, first_pt_coord_lon, last_pt_coord_lat, last_pt_coord_lon from """ + schema + """.""" + table + """ where id > """ + str(min_id) + """ and id <= """ + str(max_id) + """;""" # select the columns cursor.execute(postgreSQL_select_Query) # put rows' data in Tab Tab = cursor.fetchall() return Tab #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - main() # connecting to db connection = connect_to_db("localhost", "5432", "SMA", "postgres", "password") # using RoutingAPI routing_api = RoutingApi(api_key=" ") # a while loop to bring coordinats from a specified number of rows at a time # and send it to the Api and insert the reponses in the table while (counter < id_final): # Convert to data_table the result Lists from the function select_row data_table = select_row(connection, id_min, id_max) id_min += 1000 id_max += 1000 if (id_max > id_final): id_max = id_final for row in data_table: cur = connection.cursor() # fetches a bicycle route between two points response = routing_api.bicycle_route(waypoint_a=[row[1], row[2]], waypoint_b=[row[3], row[4]]) response = response.as_dict()