Beispiel #1
0
    def __init__(self,
                 depart,
                 arrivee,
                 heure_debut,
                 date_format="%Y-%m-%d %H:%M:%S"):
        self.depart = depart
        self.arrivee = arrivee
        self.heure_debut = heure_debut

        # Préparation de l'URL pour l'API
        base = 'https://maps.googleapis.com/maps/api/distancematrix/json?'
        origine = 'origins=' + str(depart["lat"]) + "," + str(depart["lon"])
        destination = '&destinations='
        for lieu in arrivee:
            destination = destination + str(lieu["lat"]) + "," + str(
                lieu["lon"]) + "|"
        departure_time = '&departure_time=' + str(
            round(utile.convert_date(heure_debut, date_format)))
        fin_url = '&traffic_model=best_guess&mode=driving&language=fr-FR&key=AIzaSyCQnaoaMu6GVo3AwRzN62l0onao2TPN_u0'

        # Concaténation des éléments de l'URL
        url = base + origine + destination + departure_time + fin_url
        response = utile.requete_http(url)
        json_response = json.loads(response)
        trajet = []
        i = 0
        # Récupération des distances et des temps de parcours des trajets
        for element in json_response["rows"][0]["elements"]:
            temp = arrivee[i]
            temp["distance"] = round(element['distance']['value'] / 1000, 2)
            temp["temps"] = round(element['duration_in_traffic']['value'] / 60,
                                  2)
            trajet.append(temp)
            i = i + 1
        self.trajet = trajet
Beispiel #2
0
    def __init__(self, depart, arrivee, heure_debut, date_format="%Y-%m-%d %H:%M:%S"):
        self.depart = depart
        self.arrivee = arrivee
        self.heure_debut = heure_debut

        # Préparation de l'URL pour l'API
        base = "https://maps.googleapis.com/maps/api/distancematrix/json?"
        origine = "origins=" + str(depart["lat"]) + "," + str(depart["lon"])
        destination = "&destinations="
        for lieu in arrivee:
            destination = destination + str(lieu["lat"]) + "," + str(lieu["lon"]) + "|"
        departure_time = "&departure_time=" + str(round(utile.convert_date(heure_debut, date_format)))
        fin_url = "&traffic_model=best_guess&mode=driving&language=fr-FR&key=AIzaSyCQnaoaMu6GVo3AwRzN62l0onao2TPN_u0"

        # Concaténation des éléments de l'URL
        url = base + origine + destination + departure_time + fin_url
        response = utile.requete_http(url)
        json_response = json.loads(response)
        trajet = []
        i = 0
        # Récupération des distances et des temps de parcours des trajets
        for element in json_response["rows"][0]["elements"]:
            temp = arrivee[i]
            temp["distance"] = round(element["distance"]["value"] / 1000, 2)
            temp["temps"] = round(element["duration_in_traffic"]["value"] / 60, 2)
            trajet.append(temp)
            i = i + 1
        self.trajet = trajet
Beispiel #3
0
    def __init__(self,
                 depart,
                 arrivee,
                 heure_debut,
                 date_format="%Y-%m-%d %H:%M:%S"):
        self.depart = depart
        self.arrivee = arrivee
        self.heure_debut = heure_debut

        base = 'https://maps.googleapis.com/maps/api/directions/json?'
        origine = 'origin=' + str(depart["lat"]) + "," + str(depart["lon"])
        destination = '&destination=' + str(arrivee["lat"]) + "," + str(
            arrivee["lon"])
        departure_time = '&departure_time=' + str(
            round(utile.convert_date(heure_debut, date_format)))
        fin_url = '&traffic_model=best_guess&mode=driving&language=fr-FR&key=AIzaSyCQnaoaMu6GVo3AwRzN62l0onao2TPN_u0'
        '''Ajouter l'heure de depart à l'url'''
        url = base + origine + destination + departure_time + fin_url
        reponse = utile.requete_http(url)
        data_response = json.loads(reponse)

        self.distance = round(
            data_response['routes'][0]['legs'][0]['distance']['value'] / 1000,
            2)
        self.temps = round(
            data_response['routes'][0]['legs'][0]['duration_in_traffic']
            ['value'] / 60, 2)
Beispiel #4
0
 def construire(self):
     # Préparation de l'URL pour l'API
     origine = 'origins=' + str(self.depart["lat"]) + "," + str(
         self.depart["lon"])
     destination = 'destinations='
     for lieu in self.arrivee:
         destination = destination + str(lieu["lat"]) + "," + str(
             lieu["lon"]) + "|"
     depart = 'departure_time=' + str(round(utile.convert_date(self.debut)))
     self.url = '{0}?{1}&{2}&{3}&{4}&{5}'.format(self.base, origine,
                                                 destination, depart,
                                                 self.parametres, self.cle)
Beispiel #5
0
def parcours(depart, arrivee, heure_debut):
    '''Fonction permettant de formater l'url et de calculer les distances
    Attention à la key qu'il faudra changer'''
    base = 'https://maps.googleapis.com/maps/api/directions/json?'
    origine = 'origin=' + utile.formatage_url(depart)
    destination = '&destination=' + utile.formatage_url(arrivee)
    departure_time = '&departure_time=' + str(round(utile.convert_date(heure_debut)))
    fin_url = '&traffic_model=pessimistic&mode=driving&language=fr-FR&key=AIzaSyCQnaoaMu6GVo3AwRzN62l0onao2TPN_u0'
    
    '''Ajouter l'heure de depart à l'url'''
    url = base + origine + destination + departure_time + fin_url
    reponse = utile.requete_http(url)
    return json.loads(reponse)
Beispiel #6
0
    def __init__(self,depart, arrivee, heure_debut, date_format = "%Y-%m-%d %H:%M:%S"):
        self.depart = depart
        self.arrivee = arrivee
        self.heure_debut = heure_debut
        
        base = 'https://maps.googleapis.com/maps/api/directions/json?'
        origine = 'origin=' + str(depart["lat"]) + "," + str(depart["lon"])
        destination = '&destination=' + str(arrivee["lat"]) + "," + str(arrivee["lon"])
        departure_time = '&departure_time=' + str(round(utile.convert_date(heure_debut,date_format)))
        fin_url = '&traffic_model=best_guess&mode=driving&language=fr-FR&key=AIzaSyCQnaoaMu6GVo3AwRzN62l0onao2TPN_u0'
    
        '''Ajouter l'heure de depart à l'url'''
        url = base + origine + destination + departure_time + fin_url
        reponse = utile.requete_http(url)
        data_response = json.loads(reponse)

        self.distance=  round(data_response['routes'][0]['legs'][0]['distance']['value'] / 1000,2)
        self.temps= round(data_response['routes'][0]['legs'][0]['duration_in_traffic']['value'] / 60,2)