route_distances/distances.py
def route(self, from_long, from_lat, to_long, to_lat, mode = "walk",
              departure_time = None):
        """ Routes the distance between two coordinates

        Args:
            orig_long: The origin longitude.
            orig_lat: The origin latitude.
            dest_long: The destination longitude.
            dest_lat: The destination latitude.
            mode: A key of the self.mode_map dictionary that will be remapped to
                a different string and passed to the API.
            departure_time: A datetime.datetime object corresponding to the
                desired departure time.

        Returns:
            A dictionary containing the total duration in the "duration" key and
                the total distance in the "distance" key if there are no errors;
                False if there are errors. Distance is in meters; duration is in
                seconds.
        """

        url = ("http://%s/otp/routers/default/plan"
               "?fromPlace=%f,%f&toPlace=%f,%f&mode=%s" % (
            self.entrypoint,
            from_lat, from_long, to_lat, to_long,
            self.map_mode(mode)
        ))

        if (departure_time):
            #url += "&dateTime=%d" % (departure_time.timestamp() * 1000)
            url = "&".join([
                url,
                "date=%s" % (departure_time.strftime("%Y-%m-%d")),
                "time=%s" % (departure_time.strftime("%H:%M"))
            ])

        self.log("Sending request: %s" % url)
        response = requests.get(url, timeout = self.timeout)
        data = response.content.decode()
        self.log("Response: %s" % data)

        if (response.status_code == 200):
            content = json.loads(data)
            if (not "error" in content):
                return {
                    "duration": content["plan"]["itineraries"][0]["duration"],
                    "distance": sum([
                        leg["distance"]
                        for leg in content["plan"]["itineraries"][0]["legs"]
                    ]),
                    "response": content
                }

        return False
 Routes the distance between two coordinates

        Args:
            orig_long: The origin longitude.
            orig_lat: The origin latitude.
            dest_long: The destination longitude.
            dest_lat: The destination latitude.
            mode: A key of the self.mode_map dictionary that will be remapped to
                a different string and passed to the API.
            departure_time: A datetime.datetime object corresponding to the
                desired departure time.

        Returns:
            A dictionary containing the total duration in the "duration" key and
                the total distance in the "distance" key if there are no errors;
                False if there are errors. Distance is in meters; duration is in
                seconds.
        
Routes the distance between two coordinates
Routes the distance between two coordinates
def route(self, from_long, from_lat, to_long, to_lat, mode = "walk",
              departure_time = None):
        url = ("http://%s/otp/routers/default/plan"
               "?fromPlace=%f,%f&toPlace=%f,%f&mode=%s" % (
            self.entrypoint,
            from_lat, from_long, to_lat, to_long,
            self.map_mode(mode)
        ))
        if (departure_time):
            url = "&".join([
                url,
                "date=%s" % (departure_time.strftime("%Y-%m-%d")),
                "time=%s" % (departure_time.strftime("%H:%M"))
            ])
        self.log("Sending request: %s" % url)
        response = requests.get(url, timeout = self.timeout)
        data = response.content.decode()
        self.log("Response: %s" % data)
        if (response.status_code == 200):
            content = json.loads(data)
            if (not "error" in content):
                return {
                    "duration": content["plan"]["itineraries"][0]["duration"],
                    "distance": sum([
                        leg["distance"]
                        for leg in content["plan"]["itineraries"][0]["legs"]
                    ]),
                    "response": content
                }
        return False
def route ( self , from_long , from_lat , to_long , to_lat , mode = "walk" , departure_time = None ) : url = ( "http://%s/otp/routers/default/plan" "?fromPlace=%f,%f&toPlace=%f,%f&mode=%s" % ( self . entrypoint , from_lat , from_long , to_lat , to_long , self . map_mode ( mode ) ) ) if ( departure_time ) : url = "&" . join ( [ url , "date=%s" % ( departure_time . strftime ( "%Y-%m-%d" ) ) , "time=%s" % ( departure_time . strftime ( "%H:%M" ) ) ] ) self . log ( "Sending request: %s" % url ) response = requests . get ( url , timeout = self . timeout ) data = response . content . decode ( ) self . log ( "Response: %s" % data ) if ( response . status_code == 200 ) : content = json . loads ( data ) if ( not "error" in content ) : return { "duration" : content [ "plan" ] [ "itineraries" ] [ 0 ] [ "duration" ] , "distance" : sum ( [ leg [ "distance" ] for leg in content [ "plan" ] [ "itineraries" ] [ 0 ] [ "legs" ] ] ) , "response" : content } return False
Routes the distance between two coordinates
Routes the distance between two coordinates
""" Routes the distance between two coordinates

        Args:
            orig_long: The origin longitude.
            orig_lat: The origin latitude.
            dest_long: The destination longitude.
            dest_lat: The destination latitude.
            mode: A key of the self.mode_map dictionary that will be remapped to
                a different string and passed to the API.
            departure_time: A datetime.datetime object corresponding to the
                desired departure time.

        Returns:
            A dictionary containing the total duration in the "duration" key and
                the total distance in the "distance" key if there are no errors;
                False if there are errors. Distance is in meters; duration is in
                seconds.
        """ #url += "&dateTime=%d" % (departure_time.timestamp() * 1000)
A dictionary containing the total duration in the "duration" key and
the total distance in the "distance" key if there are no errors;
False if there are errors. Distance is in meters; duration is in
seconds.
A dictionary containing the total duration in the " duration " key and the total distance in the " distance " key if there are no errors ; False if there are errors . Distance is in meters ; duration is in seconds .
self
from_long
from_lat
to_long
to_lat
mode
A key of the self.mode_map dictionary that will be remapped to
a different string and passed to the API.
A key of the self . mode_map dictionary that will be remapped to a different string and passed to the API .
departure_time
A datetime.datetime object corresponding to the
desired departure time.
A datetime . datetime object corresponding to the desired departure time .
orig_long
The origin longitude.
The origin longitude .
orig_lat
The origin latitude.
The origin latitude .
dest_long
The destination longitude.
The destination longitude .
dest_lat
The destination latitude.
The destination latitude .