Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import csv
import gps
from uber_rides.session import Session
from uber_rides.client import UberRidesClient
token = '<redacted>'
session = Session(server_token=token)
client = UberRidesClient(session)
def _read_csv(file_name):
houses = []
with open(file_name, 'r') as f:
for row in csv.DictReader(f):
houses.append(row)
return houses
def get_homes_by_zip(houses=[], zip_code=98122):
homes = []
for house in houses:
if str(house['zip']) == str(zip_code):
homes.append(house)
return homes
def how_much_airport(lat=47.602, lon=-122.306):
response = client.get_price_estimates(
start_latitude=lat,
start_longitude=lon,
end_latitude=47.444, # seatac airport
end_longitude=-122.302,
seat_count=1
)
return response.json.get('prices')
# Script begins
houses = _read_csv('seattle.csv')
print('total houses: {}'.format(len(houses)))
zip_codes = 98121, 98122
for zip_code in zip_codes:
print('')
print('')
print(zip_code)
print('')
print('')
homes = get_homes_by_zip(houses=houses, zip_code=zip_code)
print('total houses in {}: {}'.format(zip_code, len(homes)))
for home in homes:
try:
lat, lon = gps.get_gps(home['address'], home['city'], home['state'], home['zip'])
estimate = how_much_airport(lat=lat, lon=lon)
for e in estimate:
if e['display_name'] == 'UberX':
print('{}, {}, {}, {}'.format(home['address'] + ' ' + home['city'] + ' ' + home['state'] + ' ' + home['zip'], home['price'], e['low_estimate'], e['high_estimate']))
except Exception, e:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.