예제 #1
0
파일: run.py 프로젝트: vihanchaudhry/hermes
def get_cost():
    template = Template(filename='templates/cost.html')
    locations = request.form
    arcgis_token = geo.get_token()
    pickup_location = geo.geocode(arcgis_token, locations.getlist('pickup_location')[0])
    destination = geo.geocode(arcgis_token, locations.getlist('destination')[0])
    lyft_public_token = lyft.get_public_token()
    cost = lyft.get_cost(lyft_public_token, pickup_location, destination).json()
    parameters = {
        'pickup_location': pickup_location.json()['locations'][0]['name'],
        'destination': destination.json()['locations'][0]['name'],
        'lyft_line_percentage': cost['cost_estimates'][0]['primetime_percentage'],
        'lyft_line_cost_max': cost['cost_estimates'][0]['estimated_cost_cents_max'] / 100,
        'lyft_line_cost_min': cost['cost_estimates'][0]['estimated_cost_cents_min'] / 100,
        'lyft_line_distance': cost['cost_estimates'][0]['estimated_distance_miles'],
        'lyft_line_duration': cost['cost_estimates'][0]['estimated_duration_seconds'] / 60,
        'lyft_percentage': cost['cost_estimates'][1]['primetime_percentage'],
        'lyft_cost_max': cost['cost_estimates'][1]['estimated_cost_cents_max'] / 100,
        'lyft_cost_min': cost['cost_estimates'][1]['estimated_cost_cents_min'] / 100,
        'lyft_distance': cost['cost_estimates'][1]['estimated_distance_miles'],
        'lyft_duration': cost['cost_estimates'][1]['estimated_duration_seconds'] / 60,
        'lyft_plus_percentage': cost['cost_estimates'][2]['primetime_percentage'],
        'lyft_plus_cost_max': cost['cost_estimates'][2]['estimated_cost_cents_max'] / 100,
        'lyft_plus_cost_min': cost['cost_estimates'][2]['estimated_cost_cents_min'] / 100,
        'lyft_plus_distance': cost['cost_estimates'][2]['estimated_distance_miles'],
        'lyft_plus_duration': cost['cost_estimates'][2]['estimated_duration_seconds'] / 60
    }
    return template.render(**parameters)
예제 #2
0
파일: run.py 프로젝트: vihanchaudhry/hermes
def ride_request():
    template = Template(filename='templates/request.html')
    locations = request.form
    arcgis_token = geo.get_token()
    pickup_location = geo.geocode(arcgis_token,
                                  locations.getlist('pickup_location')[0])
    destination = geo.geocode(arcgis_token,
                              locations.getlist('destination')[0])
    orig_dict = {
        'lat':
        pickup_location.json()['locations'][0]['feature']['geometry']['y'],
        'lng':
        pickup_location.json()['locations'][0]['feature']['geometry']['x'],
        'address': pickup_location.json()['locations'][0]['name']
    }
    dest_dict = {
        'lat': destination.json()['locations'][0]['feature']['geometry']['y'],
        'lng': destination.json()['locations'][0]['feature']['geometry']['x'],
        'address': destination.json()['locations'][0]['name']
    }
    ride_type = locations.getlist('ride_type')[0]
    lyft_user_token = locations.getlist('user_token')[0]
    ride = lyft.request_ride(lyft_user_token, orig_dict, dest_dict, ride_type)
    print ride.json()
    parameters = {}
    return template.render()
예제 #3
0
파일: run.py 프로젝트: vihanchaudhry/hermes
def get_cost():
    template = Template(filename='templates/cost.html')
    locations = request.form
    arcgis_token = geo.get_token()
    pickup_location = geo.geocode(arcgis_token,
                                  locations.getlist('pickup_location')[0])
    destination = geo.geocode(arcgis_token,
                              locations.getlist('destination')[0])
    lyft_public_token = lyft.get_public_token()
    cost = lyft.get_cost(lyft_public_token, pickup_location,
                         destination).json()
    parameters = {
        'pickup_location':
        pickup_location.json()['locations'][0]['name'],
        'destination':
        destination.json()['locations'][0]['name'],
        'lyft_line_percentage':
        cost['cost_estimates'][0]['primetime_percentage'],
        'lyft_line_cost_max':
        cost['cost_estimates'][0]['estimated_cost_cents_max'] / 100,
        'lyft_line_cost_min':
        cost['cost_estimates'][0]['estimated_cost_cents_min'] / 100,
        'lyft_line_distance':
        cost['cost_estimates'][0]['estimated_distance_miles'],
        'lyft_line_duration':
        cost['cost_estimates'][0]['estimated_duration_seconds'] / 60,
        'lyft_percentage':
        cost['cost_estimates'][1]['primetime_percentage'],
        'lyft_cost_max':
        cost['cost_estimates'][1]['estimated_cost_cents_max'] / 100,
        'lyft_cost_min':
        cost['cost_estimates'][1]['estimated_cost_cents_min'] / 100,
        'lyft_distance':
        cost['cost_estimates'][1]['estimated_distance_miles'],
        'lyft_duration':
        cost['cost_estimates'][1]['estimated_duration_seconds'] / 60,
        'lyft_plus_percentage':
        cost['cost_estimates'][2]['primetime_percentage'],
        'lyft_plus_cost_max':
        cost['cost_estimates'][2]['estimated_cost_cents_max'] / 100,
        'lyft_plus_cost_min':
        cost['cost_estimates'][2]['estimated_cost_cents_min'] / 100,
        'lyft_plus_distance':
        cost['cost_estimates'][2]['estimated_distance_miles'],
        'lyft_plus_duration':
        cost['cost_estimates'][2]['estimated_duration_seconds'] / 60
    }
    return template.render(**parameters)
예제 #4
0
    def test_geocode_success(self, geolocator, logger):

        (geolocator.is_a_stub().expects('geocode').with_args(
            'an address').returns('geolocator.geocode result'))
        logger.is_a_stub().provides('exception')

        result = geocode('an address')

        self.assertEqual(result, 'geolocator.geocode result')
예제 #5
0
    def test_geocode_error(self, geolocator, logger):

        (geolocator.is_a_stub().expects('geocode').with_args(
            'an address').raises(GeopyError))
        logger.is_a_stub().expects('exception')

        result = geocode('an address')

        self.assertEqual(result, None)
예제 #6
0
    def test_geocode_success(self, geolocator, logger):

        (geolocator.is_a_stub()
            .expects('geocode').with_args('an address').returns('geolocator.geocode result'))
        logger.is_a_stub().provides('exception')

        result = geocode('an address')

        self.assertEqual(result, 'geolocator.geocode result')
예제 #7
0
    def test_geocode_error(self, geolocator, logger):

        (geolocator.is_a_stub()
            .expects('geocode').with_args('an address').raises(GeopyError))
        logger.is_a_stub().expects('exception')

        result = geocode('an address')

        self.assertEqual(result, None)
예제 #8
0
 def save(self, **kwargs):
     location_hash = md5(
         '{}@{}'.format(self.name, self.address).encode('utf-8')).hexdigest()
     if self.location_hash != location_hash and self.address:
         location_geocode = geocode(self.address)
         if location_geocode:
             self.meta = location_geocode.raw
             pos = [float(self.meta.get(coord)) for coord in ['lon', 'lat']]
             self.location = Point(*pos)
             self.location_hash = location_hash
         else:
             self.meta = {"geocoded": False}
             self.location = None
     super().save(**kwargs)
예제 #9
0
 def save(self, **kwargs):
     location_hash = md5('{}@{}'.format(
         self.name, self.address).encode('utf-8')).hexdigest()
     if self.location_hash != location_hash and self.address:
         location_geocode = geocode(self.address)
         if location_geocode:
             self.meta = location_geocode.raw
             pos = [float(self.meta.get(coord)) for coord in ['lon', 'lat']]
             self.location = Point(*pos)
             self.location_hash = location_hash
         else:
             self.meta = {"geocoded": False}
             self.location = None
     super().save(**kwargs)
예제 #10
0
파일: run.py 프로젝트: vihanchaudhry/hermes
def get_eta():
    template = Template(filename='templates/eta.html')
    location = request.form
    arcgis_token = geo.get_token()
    pickup_location = geo.geocode(arcgis_token, location.getlist('pickup_location')[0])
    lyft_public_token = lyft.get_public_token()
    eta = lyft.get_eta(lyft_public_token, pickup_location).json()
    parameters = {
        'location_address': pickup_location.json()['locations'][0]['name'],
        'lyft_line_eta': eta['eta_estimates'][0]['eta_seconds'],
        'lyft_eta': eta['eta_estimates'][1]['eta_seconds'],
        'lyft_plus_eta': eta['eta_estimates'][2]['eta_seconds']
    }
    return template.render(**parameters)
예제 #11
0
파일: run.py 프로젝트: vihanchaudhry/hermes
def get_eta():
    template = Template(filename='templates/eta.html')
    location = request.form
    arcgis_token = geo.get_token()
    pickup_location = geo.geocode(arcgis_token,
                                  location.getlist('pickup_location')[0])
    lyft_public_token = lyft.get_public_token()
    eta = lyft.get_eta(lyft_public_token, pickup_location).json()
    parameters = {
        'location_address': pickup_location.json()['locations'][0]['name'],
        'lyft_line_eta': eta['eta_estimates'][0]['eta_seconds'],
        'lyft_eta': eta['eta_estimates'][1]['eta_seconds'],
        'lyft_plus_eta': eta['eta_estimates'][2]['eta_seconds']
    }
    return template.render(**parameters)
예제 #12
0
파일: run.py 프로젝트: vihanchaudhry/hermes
def ride_request():
    template = Template(filename='templates/request.html')
    locations = request.form
    arcgis_token = geo.get_token()
    pickup_location = geo.geocode(arcgis_token, locations.getlist('pickup_location')[0])
    destination = geo.geocode(arcgis_token, locations.getlist('destination')[0])
    orig_dict = {
        'lat': pickup_location.json()['locations'][0]['feature']['geometry']['y'],
        'lng': pickup_location.json()['locations'][0]['feature']['geometry']['x'],
        'address': pickup_location.json()['locations'][0]['name']
    }
    dest_dict = {
        'lat': destination.json()['locations'][0]['feature']['geometry']['y'],
        'lng': destination.json()['locations'][0]['feature']['geometry']['x'],
        'address': destination.json()['locations'][0]['name']
    }
    ride_type = locations.getlist('ride_type')[0]
    lyft_user_token = locations.getlist('user_token')[0]
    ride = lyft.request_ride(lyft_user_token, orig_dict, dest_dict, ride_type)
    print ride.json()
    parameters = {

    }
    return template.render()
예제 #13
0
from run import app
from utils import geo
from utils import lyft

# get ArcGIS API token
arcgis_token = geo.get_token()

# geocode address - get address from frontend
locations = geo.geocode(arcgis_token, "Empire State Building")

# get 2-legged lyft token
lyft_public_token = lyft.get_public_token()

# get cost and ETA
eta = lyft.get_eta(lyft_public_token, locations)

# get 3-legged lyft token

# request lyft

app.run(debug=True)