コード例 #1
0
def latlong_to_address(img_list):
    # run get_coordinates function for lat, long
    addresses = []
    #add your api keys here to use this function
    bing_key = 'your_key_here'
    zillow_key = 'your_key_here'
    #instantiating the zillow api
    zillow_api = zillow.ValuationApi()

    for img in img_list:
        #get address from Lat/lon
        coords = get_coordinates(img)


        #instantiate bing geocoder
        bing_locator = geocoders.Bing(bing_key)
        #pulling mailing address from bing
        address = bing_locator.reverse(coords).raw
        street_address = address['name']
        house = address['address']['addressLine']
        postal_code = address['address']['postalCode']
        #zillow api call
        try:
            #attempt to pull a price from the zillow api
            house_data = zillow_api.GetSearchResults(zillow_key, house, postal_code)
            price = house_data.zestimate.amount
        except:
            #if no zillow price leave empty
            price='$__'

        #add zillow price to address
        addresses.append(f'{street_address}: ${price}')
        #sleep so that we are not pinging api in too rapid of sucession
        time.sleep(.5)
    return addresses
コード例 #2
0
ファイル: zillowAPI.py プロジェクト: jotk/GHAR
 def __init__(self, apikey, ad, city, state, zipcode, COMPNUMBER=25):
     self.compnum = COMPNUMBER
     api = zillow.ValuationApi()  # initialize api
     address = ad + "," + city + "," + state
     postal_code = str(zipcode)
     self.data = api.GetDeepSearchResults(
         apikey, address,
         postal_code).get_dict()  # basic data retrieved from address
     self.city = self.data['full_address']['city']
     self.state = self.data['full_address']['state']
     self.region = self.data['local_realestate']['region_name']
     self.regionType = self.data['local_realestate']['region_type']
     self.homeType = self.data['extended_data']['usecode']
     self.zpid = self.data[
         'zpid']  # home identifier assigned by zillow, needed for other api calls
     self.zestimate_data = api.GetZEstimate(
         apikey, self.zpid).get_dict()  # retrieves zestimate details
     self.comps_data = api.GetDeepComps(
         apikey, self.zpid,
         count=COMPNUMBER)['comps']  # returns comps in the form of a dict
     self.pp = pprint.PrettyPrinter(indent=4)
     self.comps = []
     self.upper_val = None
     self.lower_val = None
     self.price = None
     self.comp_mean_weighted_sim = None
     self.comp_mean_weighted_dist = None
     self.comp_mean_weighted_sim_low = None
     self.comp_mean_weighted_dist_low = None
     self.comp_mean_weighted_sim_high = None
     self.comp_mean_weighted_dist_high = None
     self.comp_change_mean_weighted_sim = None
     self.comp_change_mean_weighted_dist = None
     self.change_30_days = None
コード例 #3
0
def latlong_to_address(img_list):
    # run get_coordinates function for lat, long
    addresses = []
    bing_key = ''
    zillow_key = ''
    zillow_api = zillow.ValuationApi()

    for img in img_list:
        #get address from Lat/lon
        coords = get_coordinates(img)

        #instantiate bing geocoder
        bing_locator = geocoders.Bing(bing_key)

        address = bing_locator.reverse(coords).raw
        street_address = address['name']
        house = address['address']['addressLine']
        postal_code = address['address']['postalCode']
        #zillow api call
        try:
            house_data = zillow_api.GetSearchResults(zillow_key, house,
                                                     postal_code)
            price = house_data.zestimate.amount
        except:
            price = '$__'

        addresses.append(f'{street_address}: ${price}')
        time.sleep(.5)
    return addresses
コード例 #4
0
def zillow_data(zipcode):
    key = get_key()
    url = URL_generator(zipcode)
    driver = driver_generator()
    zpids = get_zpids(url, driver)
    api = zillow.ValuationApi()
    df = house_data(key, api, zpids)
    return df
コード例 #5
0
def retrieve_zillow_data(zillow_addresses, api_key):
    api = zillow.ValuationApi()
    zillow_data = dict()
    for address, zipcode in zillow_addresses.itertuples(index=False):
        try:
            data = api.GetDeepSearchResults(api_key, address, zipcode)
            zillow_data[address] = format_zillow_data(data.get_dict())
        except zillow.error.ZillowError:
            logging.error(
                "Could not retrieve data for address: {}".format(address))
    return zillow_data
コード例 #6
0
def textaddress():
    #adding form that accepts address
    form = AddressForm()

    # text to address and value form
    if form.validate_on_submit():

        address = form.address.data

        # bing address grabber
        bing_locator = geocoders.Bing(bing_key)
        address = bing_locator.geocode(address).raw

        # Zillow call (could be replaced with Zillow function)
        zillow_api = zillow.ValuationApi()
        house = address['address']['addressLine']
        postal_code = address['address']['postalCode']

        house_data = zillow_api.GetSearchResults(zillow_key, house,
                                                 postal_code)
        price = house_data.zestimate.amount

        # set address back to street address and zip code
        address = address['name']

        ### START GOOGLE STREET VIEW IMAGE HANDLING ###

        # Set image_url to Google Street View of address

        image_url = f'https://maps.googleapis.com/maps/api/streetview?size=600x600&location={address}&key={google_key}'

        # Image write out to uploads folder
        image = requests.get(image_url)

        basepath = os.path.abspath('app/')
        filelist = re.findall(r'\w+', address)
        filename = ''.join(filelist)
        final_path = f'{basepath}/uploads/{filename}.jpg'
        open(f'{final_path}', 'wb').write(image.content)

        # render template with passed variables when form validates
        return render_template('text_form.html',
                               title='Output',
                               price=price,
                               address=address,
                               file_path=f'{filename}.jpg',
                               photo=open(f'{final_path}', 'rb'))

    #keep same page with form if form does not validate
    return render_template('textaddress.html',
                           title='Submit Address',
                           form=form)
コード例 #7
0
 def get_zillow_data(self):
     api = zillow.ValuationApi()
     zillow_data = api.GetSearchResults(self.zillow_key, self.address,
                                        self.zip)
     z_data = {
         'valuation_high': zillow_data.zestimate.valuation_range_high,
         'zestimate': zillow_data.zestimate.amount,
         'valuation_low': zillow_data.zestimate.valuation_range_low,
         'zestimate_30_day_change':
         zillow_data.zestimate.amount_change_30days,
         'details': zillow_data.links.home_details,
         'overview_link': zillow_data.local_realestate.overview_link
     }
     print(z_data)
コード例 #8
0
    def set_zillow(self):
        zillow_api = zillow.ValuationApi()
        house = f'{self.street_number} {self.street_name}'

        # estimate int, baths str, bedrooms str
        try:
            house_data = zillow_api.GetDeepSearchResults(
                zillow_key, house, self.postal_code)
            self.zillow_estimate = house_data.zestimate.amount
            self.zillow_baths = house_data.extended_data.bathrooms
            self.zillow_bedrooms = house_data.extended_data.bedrooms
        #Error if zillow doesnt have price for property
        except:
            print('Zillow does not have price for this address')
コード例 #9
0
ファイル: routes.py プロジェクト: zstern/Mapping_disasters
def textaddress():
    form = AddressForm()

    if form.validate_on_submit():
        # flash('Login requested for user {}'.format(form.address.data))

        address = form.address.data

        bing_key = ''
        bing_locator = geocoders.Bing(bing_key)
        address = bing_locator.geocode(address).raw

        zillow_key = ''
        zillow_api = zillow.ValuationApi()
        house = address['address']['addressLine']
        postal_code = address['address']['postalCode']

        house_data = zillow_api.GetSearchResults(zillow_key, house,
                                                 postal_code)
        price = house_data.zestimate.amount
        address = address['name']

        google_key = ''

        ### START GOOGLE STREET VIEW IMAGE HANDLING ###

        # Set image_url to Google Street View of address
        # I don't know how this will need to be saved / returned for use in Flask
        image_url = f'https://maps.googleapis.com/maps/api/streetview?size=600x600&location={address}&key={google_key}'

        # Put image handling code for Flask here
        image = requests.get(image_url)

        basepath = os.path.abspath('app/')
        filelist = re.findall(r'\w+', address)
        filename = ''.join(filelist)
        final_path = f'{basepath}/uploads/{filename}.jpg'
        open(f'{final_path}', 'wb').write(image.content)

        return render_template('text_form.html',
                               title='Output',
                               price=price,
                               file_path=f'{filename}.jpg',
                               photo=open(f'{final_path}', 'rb'))

        # return redirect('/textaddress')

    return render_template('textaddress.html',
                           title='Submit Address',
                           form=form)
コード例 #10
0
    def __init__(self):
        with open("keys/zws_key", "r") as zws_file:
            self.zws_id = zws_file.read().replace("\n", "")

        if not self.zws_id:
            print_err("Cannot find Zillow API key")

        with open("keys/gapi_key", "r") as gapi_file:
            google_id = gapi_file.read().replace("\n", "")

        if not google_id:
            print_err("Cannot find Google API key")

        self.zapi = zillow.ValuationApi()
        self.gmaps = googlemaps.Client(key=google_id)
        self.browser = None
コード例 #11
0
def zillow_pull(address):
    #instantiate zillow api
    zillow_api = zillow.ValuationApi()

    # get house and postal code info from dictionary
    house = address['address']['addressLine']
    postal_code = address['address']['postalCode']

    # Grab Zillow price and set to price variable
    try:
        house_data = zillow_api.GetSearchResults(zillow_key, house, postal_code)
        price = house_data.zestimate.amount
    #Error if zillow doesnt have price for property
    except:
        price = 'Zillow does not have price for this address'

    return price
コード例 #12
0
def zillow_api(address):
    home_address = Address(address)
    if home_address.is_zip_good():
        zip_code = home_address.zip_code
    else:
        zip_code = '98058'
        address = '1309 Harrington Ave SE, Renton'
    key = dec('M1-OLo18g1trev4fo_pu1if', 15)
    api = zillow.ValuationApi()
    data = api.GetDeepSearchResults(key, address, zip_code)
    if not isinstance(data, str):
        full_data = api.GetDeepComps(key, data.zpid)
        if not isinstance(full_data, str):
            full_data['principal'].extended_data = data.extended_data
        else:
            full_data = {'principal': data, 'comps': [data]}
        return full_data
    else:
        return "Wrong address"
コード例 #13
0
ファイル: functions.py プロジェクト: zstern/Mapping_disasters
def zillow_pull(address):
    zillow_api = zillow.ValuationApi()
    zillow_key = ''

    # get house and postal code info from dictionary
    house = address['address']['addressLine']
    postal_code = address['address']['postalCode']

    # Grab Zillow price and set to price variable
    try:
        house_data = zillow_api.GetSearchResults(zillow_key, house,
                                                 postal_code)
        price = house_data.zestimate.amount

    except:
        price = 'Zillow does not have price for this address'

# Error handling if Zillow has no price output
    if price == None:
        price = 'This address does not have a price estimate in Zillow'

    return price
コード例 #14
0
def api_invoke():

    config = configparser.ConfigParser()
    config.read('./api_key.conf')
    key = config.get('Zillow_API_Key_ZWSID', 'api_key')

    api = zillow.ValuationApi()

    address = "16229 North 22nd drive, Phoenix, AZ"
    postal_code = "85023"

    data = api.GetSearchResults(key, address, postal_code)
    pp = pprint.PrettyPrinter(indent=4)
    pp.pprint((data.get_dict()))

    detail_data = api.GetZEstimate(key, data.zpid)
    pp.pprint(detail_data.get_dict())

    comp_data = api.GetComps(key, data.zpid)
    pp.pprint(detail_data.get_dict())

    deep_results = api.GetDeepSearchResults(key, address, postal_code)
    pp.pprint(deep_results.get_dict())
コード例 #15
0
"""


import zillow
import pprint

if __name__=="__main__":
    key = ""
    with open("./zillow_key.conf", 'r') as f:
        key = f.readline().replace("\n", "")
    print(key)

    address = "3400 Pacific Ave., Marina Del Rey, CA"
    postal_code = "90292"

    api = zillow.ValuationApi()
    data = api.GetSearchResults(key, address, postal_code)

    pp = pprint.PrettyPrinter(indent=4)
    pp.pprint(data.get_dict())

    detail_data = api.GetZEstimate(key, data.zpid)

    comp_data = api.GetComps(key, data.zpid)

    pp.pprint(comp_data['comps'][1].get_dict())

    deep_results = api.GetDeepSearchResults(key, "1920 1st Street South Apt 407, Minneapolis, MN", "55454")
    pp.pprint(deep_results.get_dict())
    
    http://www.zillow.com/webservice/GetSearchResults.htm?zws-id=X1-ZWz179yot8r9jf_282ek&address=2114+Bigelow+Ave&citystatezip=Seattle%2C+WA
コード例 #16
0
ファイル: calculations.py プロジェクト: bishdj22/HomeSlice
def address_search(address, postal_code):
    connection_string = database_key
    engine = create_engine(f'postgresql://{connection_string}')
    api = zillow.ValuationApi()
    key = zillow_key
    try:
        request_data = api.GetSearchResults(key, address, postal_code)
        result = request_data.get_dict()
        address = result['full_address']
        zestimate = result['zestimate']

        #Combined returned results to a single dictionary and then to a dataframe
        comb_dict = dict(zestimate)
        comb_dict.update(address)
        combined_df = pd.DataFrame.from_dict(comb_dict, orient='index').T

        #Add Risk Adjustment calculations columns to the data frame
        combined_df['risk_adj_value'] = (
            combined_df['amount'] * .85
        )  #Risk adjusting home by 15%, reducing home val by 15%
        combined_df['max_cash_limit'] = combined_df[
            'risk_adj_value'] * .30  #Not to buy more than 30% of someones home equity, to avoid controlling interest
        combined_df['time_stamp'] = pd.Timestamp.now()

        #Log the data frame to the database using SQL
        combined_df.to_sql(name='zillow',
                           con=engine,
                           if_exists='append',
                           index=False)
        print("connecting to db")

        #API call and results returned
        try:
            #Using API-returned Zip Code, compare that value with our risk data table ('sales_price' table). Will return True/False response from the 'equity_risk' column
            def result_getter(postal_code):
                connection = engine.connect()
                query = "select sp.equity_risk from sales_price sp where sp.zip_code = " + postal_code + ";"
                result = connection.execute(query)
                for i in result:
                    results = i
                return results

            results = result_getter(postal_code)
            print("query finished")
            print(results[0])
            print("Success")

            # Decision tree - if True, allowable investment 30% of risk adj home value. If False, 10% of risk adj home value
            if results[0] == True:
                offer = (zestimate['amount'] * .85) * .30
                print(f'$ {offer}')

            else:
                offer = (zestimate['amount'] * .85) * .10
                print(combined_df['risk_adj_value'] * .10)

            return ((zestimate['amount']), offer)

        except:
            return ((zestimate['amount']), ((zestimate['amount'] * .85) * .20))
    except:
        return ("Bad", "Address")


# def update_dash_data():
#     return()
コード例 #17
0
key = 'X1-ZWz1gk74zflatn_5jgqp'


# In[2]:

#The latitude and longitudinal points enclosing Manhattan, 96th street and below. 
p1 = [40.796,-73.975]
p2 = [40.783,-73.944]
p3 = [40.707,-74.029]
p4 = [40.701,-73.990]

points = [p1,p2,p3,p4]


api = zillow.ValuationApi()  #initialize zillow API. 


houses = pd.DataFrame([])  #start with this, can clean later on... 

nbeds = []
addresses = []
housekind = []
high_estimates = []
low_estimates = []
costs = []
sqfts = []
last_updated = []
cpss = []
dcost = []
コード例 #18
0
def house_info(source_df, start, stop):
    # Gets information from Zillow, returns pandas DataFrame of range of houses
    key = apikey
    houses_df = DataFrame()
    # Call Zillow API for each house
    errors = 0
    successes = 0
    for row in range(start, stop):
        address = source_df.iloc[row][5]
        postal_code = source_df.iloc[row][4]
        api = zillow.ValuationApi()
        # Handle exceptions for lack of information from Zillow
        while True:
            try:
                data = api.GetDeepSearchResults(key, address, postal_code)
                house = {
                    'bathrooms': data.extended_data.bathrooms,
                    'bedrooms': data.extended_data.bedrooms,
                    'sqft': data.extended_data.finished_sqft,
                    'last_sold_price': data.extended_data.last_sold_price,
                    'last_sold_date': data.extended_data.last_sold_date,
                    'lot_size_sqft': data.extended_data.lot_size_sqft,
                    'year_built': data.extended_data.year_built,
                    'comps_link': data.links.comparables,
                    'home_details': data.links.home_details,
                    'graphs_data': data.links.graphs_and_data,
                    'map': data.links.map_this_home,
                    'zestimate': data.zestiamte.amount,
                    'valuation_range_high':
                    data.zestiamte.valuation_range_high,
                    'valuation_range_low': data.zestiamte.valuation_range_low
                }
                s_house = pd.Series(
                    house,
                    index=[
                        'bathrooms', 'bedrooms', 'sqft', 'last_sold_price',
                        'last_sold_date', 'lot_size_sqft', 'year_built',
                        'comps_link', 'home_details', 'graphs_data', 'map',
                        'zestimate', 'valuation_range_high',
                        'valuation_range_low'
                    ])
                successes += 1
                # print "one pass"
                break
            except ValueError:
                s_house = pd.Series(
                    [
                        np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN,
                        np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN
                    ],
                    index=[
                        'bathrooms', 'bedrooms', 'sqft', 'last_sold_price',
                        'last_sold_date', 'lot_size_sqft', 'year_built',
                        'comps_link', 'home_details', 'graphs_data', 'map',
                        'zestimate', 'valuation_range_high',
                        'valuation_range_low'
                    ])
                errors += 1
                break
            except:
                s_house = pd.Series(
                    [
                        np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN,
                        np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN
                    ],
                    index=[
                        'bathrooms', 'bedrooms', 'sqft', 'last_sold_price',
                        'last_sold_date', 'lot_size_sqft', 'year_built',
                        'comps_link', 'home_details', 'graphs_data', 'map',
                        'zestimate', 'valuation_range_high',
                        'valuation_range_low'
                    ])
                errors += 1
                # print "ZillowError likely"
                break
        # Append each new pd.Series house to dataframe, and pause for next loop
        houses_df = houses_df.append(s_house, ignore_index=True)
        time.sleep(1)
    # Log success/error counts
    with open("Errors.txt", "a") as text_file:
        text_file.write("Successes: {} ".format(successes))
        text_file.write("Errors: {}\n".format(errors))
    return houses_df
コード例 #19
0
    def __init__(self, **kwargs):
        """Initialize, loading data."""
        import eia
        import googlemaps
        import zillow
        from shapely.geometry import Polygon

        self._p = kwargs.get('logger')

        load_canopy_polys = kwargs.get('load_canopy_polys', True)

        self._dir_name = os.path.dirname(os.path.realpath(__file__))

        # Load meta.json.
        self.prt('Loading meta file...')
        meta_path = os.path.join(self._dir_name, '..', 'meta.json')
        if os.path.exists(meta_path):
            with open(meta_path, 'r') as f:
                meta = json.load(f)
            self._imgs_mean = meta['mean']
            self._imgs_std = meta['std']
            self._train_count = meta['train_count']

        # Load parcel data.
        self._parcels_fname = self.download_file(self._PARCELS_URL)

        with open(self._parcels_fname, 'r') as f:
            self._parcels = json.load(f)

        self._parcel_polygons = [
            x.get('geometry', {}).get('coordinates', [])
            for x in self._parcels.get('features', [])
        ]

        self._parcel_polygons = list(
            filter(None, ([[y for y in x if len(y) >= 3]
                           for x in self._parcel_polygons])))

        self._parcel_polygons = [[Polygon(y) for y in x if len(y) >= 3]
                                 for x in self._parcel_polygons]

        with open(os.path.join(self._dir_name, '..', 'google.key'), 'r') as f:
            self._google_key = f.readline().strip()
        self._google_client = googlemaps.Client(key=self._google_key)

        with open(os.path.join(self._dir_name, '..', 'eia.key'), 'r') as f:
            self._eia_key = f.readline().strip()
        self._eia_client = eia.API(self._eia_key)

        with open(os.path.join(self._dir_name, '..', 'zillow.key'), 'r') as f:
            self._zillow_key = f.readline().strip()
        self._zillow_client = zillow.ValuationApi()

        self._cropsize = self._INPUT_IMG_SIZE - 2 * self._CROPPIX

        # Load canopy data.
        if not load_canopy_polys:
            return

        self._canopy_fname = os.path.join(self._dir_name, '..', 'geo',
                                          'ENVIRONMENTAL_TreeCanopy2014.json')
        with open(self._canopy_fname, 'r') as f:
            self._canopies = json.load(f)

        raw_canpols = [
            x.get('geometry', {}).get('coordinates', [])
            for x in self._canopies.get('features', [])
            if x.get('geometry', {}) is not None
        ]

        raw_canpols = list(
            filter(None,
                   ([[y for y in x if len(y) >= 3] for x in raw_canpols])))

        raw_canpols = [[
            Polygon([(a, b + self._LAT_OFFSET) for a, b in y]) for y in x
            if len(y) >= 3
        ] for x in raw_canpols]

        self._canopy_polygons = []
        for canpoly in tqdm(raw_canpols, desc='Extracting canopy polygons'):
            cps = [x.buffer(0) for x in canpoly]
            cps = self._canopy_polygons.extend([
                a for b in [
                    list(x.geoms) if 'multi' in str(type(x)).lower() else [x]
                    for x in cps
                ] for a in b
            ])

        self._model = None