class ZillowAPI(object): """ A class to handle the ZillowAPI queries. """ def __init__(self, loc_x, loc_y): """ Constructor method. loc_x: float The latitude loc_y: float The longitude """ # Used to get the address, could be replaced with GoogleAPI class geolocator = GoogleV3(api_key=googleKey) locations = geolocator.reverse(str(loc_x) + ", " + str(loc_y)) # Format address for query to Zillow f = locations[0].address.split(",") n = re.sub("[^0-9]", "", f[2]) self.address = f[0] + "," + f[1] self.zipcode = n self.zillow_data = ZillowWrapper(zillowKey) def isHouse(self): """ Method that uses a try/catch block to determine if the coordinates (loc_x, loc_y) passed into the class is a household. Returns a boolean value. """ deep_search_response = self.zillow_data.get_deep_search_results( self.address, self.zipcode) try: return True except: return False def getResults(self): """ Method that returns a dict() of data about the house at the coordinates of loc_x, loc_y. """ deep_search_response = self.zillow_data.get_deep_search_results( self.address, self.zipcode) result = GetDeepSearchResults(deep_search_response) return result
def test_zillow_error_invalid_ZWSID(self): """ This test checks the correct error message if no ZWSID is provided. Expected error code: 2 """ set_get_deep_search_response( self.api_response_obj.get("error_2_zwsid_missing")) zillow_data = ZillowWrapper(None) with pytest.raises(ZillowError) as excinfo: zillow_data.get_deep_search_results(address=self.address, zipcode=None) error_msg = "Status 2: The specified ZWSID parameter was invalid" assert error_msg in str(excinfo.value)
def test_zillow_error_missing_zipcode(self): """ This test checks the correct error message if no zipcode is provided. Expected error code: 501 """ set_get_deep_search_response( self.api_response_obj.get("error_501_no_city_state")) zillow_data = ZillowWrapper(self.ZILLOW_API_KEY) with pytest.raises(ZillowError) as excinfo: zillow_data.get_deep_search_results(address=self.address, zipcode=None) error_msg = "Status 501: Invalid or missing citystatezip parameter" assert error_msg in str(excinfo.value)
def test_zillow_api_connect(self): # create response from zillow and check for error code '0' zillow_data = ZillowWrapper(self.ZILLOW_API_KEY) zillow_search_response = zillow_data.get_deep_search_results( self.address, self.zipcode) assert \ zillow_search_response.find('message').find('code').text == '0'
def test_zillow_error_account_not_authorized(self): """ This test checks for account not authorized error Expected error code: 6 """ set_get_deep_search_response( self.api_response_obj.get("error_6_account_not_authorized")) zillow_data = ZillowWrapper(self.ZILLOW_API_KEY) with pytest.raises(ZillowError) as excinfo: zillow_data.get_deep_search_results(address=self.address, zipcode=self.zipcode) error_msg = "Status 6: This account is not authorized to execute this API call" assert error_msg in str(excinfo.value)
def make_predict(): # read in data lines = request.get_json(force=True) address = lines['address'] city = lines['city'] state = lines['state'] zipcode = lines['zipcode'] bed = lines['bed'] bath = lines['bath'] SqFt = lines['SqFt'] year = lines['year'] # generate prediction using pickled model input = np.array([[bath, bed, SqFt, year, zipcode]]) prediction = model.predict(input) output = list(prediction[0])[0] # compare against zillow model zillow_data = ZillowWrapper(API_KEY_HERE) deep_search_response = zillow_data.get_deep_search_results( address, zipcode) result = GetDeepSearchResults(deep_search_response) output2 = result.zestimate_amount op = list([int(output), int(output2)]) return jsonify(results=op)
def make_predict(): lines = request.get_json(force=True) # was 'data' # predict_request = [data['address'], data['city'], data['state'], # data['zipcode'], data['bed'], data['bath'], data['SqFt'], # data['SqFt']] # predict_request = [np.array(predict_request)] # y_hat = reg.predict(predict_request) address = lines['address'] city = lines['city'] state = lines['state'] zipcode = lines['zipcode'] bed = lines['bed'] bath = lines['bath'] SqFt = lines['SqFt'] year = lines['year'] test_case = np.array([[bath, bed, SqFt, year, zipcode]]) reg.predict(test_case) prediction = reg.predict(test_case) output = list(prediction[0])[0] #return jsonify(results=address) zillow_data = ZillowWrapper('X1-ZWz1gyajrkda8b_76gmj') deep_search_response = zillow_data.get_deep_search_results(address,zipcode) result = GetDeepSearchResults(deep_search_response) output2 = result.zestimate_amount op = list([int(output),int(output2)]) return jsonify(results=op)
def store_property_data(): """ Stores the zillow response data for a given address/zipcode. """ zkey = current_app.config['ZKEY'] if not request.get_json() or 'address' not in request.json or 'zipcode' not in request.json: abort(400) zillow_data = ZillowWrapper(zkey) address = request.json['address'] zipcode = request.json['zipcode'] try: response = zillow_data.get_deep_search_results(address, zipcode) result = GetDeepSearchResults(response) except ZillowError as err: return jsonify({'error': err.message, 'estimate': 0}) # delete from db if already exists to prevent duplicates # (property data my have changed so need to refresh entry) pd = PropertyData.objects(zillow_id=result.zillow_id) for doc in pd: doc.delete() pd = fill_property_document(result) pd.save() return jsonify({'zillow_id': result.zillow_id, 'error': ''})
def search(self, query): address, zipcode = query.rsplit(" ", 1) data = ZillowWrapper("X1-ZWz19cu0z5xn9n_17jma") response = data.get_deep_search_results(address, zipcode) return GetDeepSearchResults(response)
def get_property_info(address, zipcode): if address and zipcode: zillow_data = ZillowWrapper(ZILLOW_API_KEY) deep_search_response = zillow_data.get_deep_search_results( address, zipcode) result = GetDeepSearchResults(deep_search_response) return result
def get_summary(address, zipcode): with open('/Users/pjadzinsky/.zillow') as f: key = f.read().replace('\n', '') zillow_data = ZillowWrapper(key) response = zillow_data.get_deep_search_results(address, zipcode) result = GetDeepSearchResults(response) return result
def generate_Comp_fields_txt(): f_name = open("UpdatedHomeLatLong.txt", "r") data_base = open("OnlyCompFields.txt", "+w") write_out = "street_address | zipcode | zillow_id | Zestimate | Home_type | num_bath | num_bed | home_size | Lat | Long | img url | home description " data_base.write(write_out) #f_name=["2893 Springdale Ln, Boulder, CO|80303|13239207|630640|Townhouse|3.5|1|1297|40.009373|-105.255454"] x = 0 for line in f_name: line = line.rstrip("\n") address = line if x == 100: break try: street_address = re.search("(.*?)(?<=CO)", address) street_address = street_address.group(0) zipcode = re.search("(?<=CO\|)(.*?)(?=\|)", address) zipcode = zipcode.group(0) #!Get information from first zillow call zillow_data = ZillowWrapper(zws_id) deep_search_response = zillow_data.get_deep_search_results( street_address, zipcode) result = GetDeepSearchResults(deep_search_response) #!!The following will be stored as values in database Home_type = result.home_type Zestimate = result.zestimate_amount zillow_id = result.zillow_id lat = str(result.latitude) long_res = str(result.longitude) num_bath = str(result.bathrooms) num_bed = str(result.bedrooms) home_size = str(result.home_size) #######CALL TO UPDATED HOME DETAILS zillow_data = ZillowWrapper(zws_id) updated_property_details_response = zillow_data.get_updated_property_details( zillow_id) result = GetUpdatedPropertyDetails( updated_property_details_response) photo_gall = result.photo_gallery home_d = result.home_description write_out = street_address + '|' + zipcode + "|" + zillow_id + "|" + Zestimate + "|" + num_bath + "|" + num_bed + "|" + lat + "|" + long_res + "\n" print(str(write_out)) data_base.write(write_out) x += 1 except: print("Nothing Added") #f_name.close() data_base.close()
def test_zillow_api_connect(self): set_get_deep_search_response( self.api_response_obj.get("get_deep_search_200_ok")) zillow_data = ZillowWrapper(self.ZILLOW_API_KEY) zillow_search_response = zillow_data.get_deep_search_results( self.address, self.zipcode) assert zillow_search_response.find("message").find("code").text == "0"
def test_zillow_error_no_property_match(self): """ This test checks the correct error message if no property is found. Expected error code: 508 Address and zip code of an exisiting property, but not listed """ address = "not a valid address" zipcode = "20001" set_get_deep_search_response( self.api_response_obj.get("error_508_invalid_address")) zillow_data = ZillowWrapper(self.ZILLOW_API_KEY) with pytest.raises(ZillowError) as excinfo: zillow_data.get_deep_search_results(address=address, zipcode=zipcode) error_msg = "Status 508: No exact match found for input address." assert error_msg in str(excinfo.value)
def deep_search(): cnxt = db.connect(user="******", password="******", host="localhost", database="sys", charset="utf8mb4") cursor = cnxt.cursor() cursor.execute("SELECT Address FROM PySpider") data = cursor.fetchall() A = [" ".join(j) for j in [i[0].split()[:-1] for i in data]] Z = [" ".join(j) for j in [i[0].split()[-1:] for i in data]] API = ZillowWrapper('X1-ZWz1gtmiat11xn_7ew1d') progbar = tqdm(total=len(A)) for i in range(len(A)): progbar.update(1) try: response = API.get_deep_search_results(A[i], Z[i]) result = GetDeepSearchResults(response) zestimate_amount = result.zestimate_amount address = A[i] zipcode = Z[i] home_type = result.home_type home_size = result.home_size property_size = result.property_size bedrooms = result.bedrooms bathrooms = result.bathrooms last_sold_price = result.last_sold_price last_sold_date = result.last_sold_date zestimate_last_updated = result.zestimate_last_updated zestimate_value_change = result.zestimate_value_change zestimate_percentile = result.zestimate_percentile zestimate_valuation_range_high = result.zestimate_valuation_range_high zestimate_valuationRange_low = result.zestimate_valuationRange_low year_built = result.year_built home_detail_link = result.home_detail_link query = "INSERT INTO PyZillow (zestimate_amount, address, zipcode, home_type, home_size,\ property_size, bedrooms, bathrooms, last_sold_price, last_sold_date,\ zestimate_last_updated, zestimate_value_change, zestimate_percentile,\ zestimate_valuation_range_high, zestimate_valuationRange_low, year_built,\ home_detail_link) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)" cursor.execute( query, (zestimate_amount, address, zipcode, home_type, home_size, property_size, bedrooms, bathrooms, last_sold_price, last_sold_date, zestimate_last_updated, zestimate_value_change, zestimate_percentile, zestimate_valuation_range_high, zestimate_valuationRange_low, year_built, home_detail_link)) cnxt.commit() except: continue progbar.close() return
def test_zillow_error_invalid_zipcode(self): """ This test checks the correct error message if an invalid zipcode is provided. Expected error code: 508 """ invalid_zipcode = "ABCDE" # invalid zipcode set_get_deep_search_response( self.api_response_obj.get("error_508_invalid_zipcode")) zillow_data = ZillowWrapper(self.ZILLOW_API_KEY) with pytest.raises(ZillowError) as excinfo: zillow_data.get_deep_search_results(address=self.address, zipcode=invalid_zipcode) error_msg = "Status 508: No exact match found for input address." assert error_msg in str(excinfo.value)
def test_zillow_error_no_coverage(self): """ This test checks the correct error message if no coverage is provided. Expected error code: 508 """ address = "Calle 21 y O, Vedado, Plaza, Ciudad de la Habana, Cuba" zipcode = "10400" # Cuban address, I assume Zillow doesn't cover Cuba set_get_deep_search_response( self.api_response_obj.get("error_508_outside_of_area")) zillow_data = ZillowWrapper(self.ZILLOW_API_KEY) with pytest.raises(ZillowError) as excinfo: zillow_data.get_deep_search_results(address=address, zipcode=zipcode) error_msg = "Status 508: No exact match found for input address." assert error_msg in str(excinfo.value)
def zillow_query(key, address, citystatezip): zillow = [] zillow_data = ZillowWrapper(key) deep_search_response = zillow_data.get_deep_search_results( address, citystatezip) result = GetDeepSearchResults(deep_search_response) #Print the results of the query return result
def get_home_description(address, zipcode): ZILLOW_API_KEY = "X1-ZWz1fssph6dr7v_2hwdv" zillow_data = ZillowWrapper(ZILLOW_API_KEY) # YOUR_ZILLOW_API_KEY deep_search_response = zillow_data.get_deep_search_results(address, zipcode) result = GetDeepSearchResults(deep_search_response) updated_property_details_response = zillow_data.get_updated_property_details(result.zillow_id) result_details = GetUpdatedPropertyDetails(updated_property_details_response) return result_details.get_attr("home_description")
def queryAndExtractFeatures(inputs, code): results = {} for address, zipcode in inputs: zillow_data = ZillowWrapper(code) try: deep_search_response = zillow_data.get_deep_search_results( address, zipcode) result = GetDeepSearchResults(deep_search_response) results[(address, zipcode)] = extractFeatures(result) + [zipcode] except: continue return results
def zillow_query(address, zipcode): ''' Given an address and zipcode as strings returns id, zestimate (or last sold price if zestimate unavilable), and latest tax appraisal value ''' zillow_data = ZillowWrapper(keys.zillow['api_key']) deep_search_response = zillow_data.get_deep_search_results( address, zipcode) result = GetDeepSearchResults(deep_search_response) if result.zestimate_amount == None: return result.last_sold_price else: return result.zillow_id, result.zestimate_amount, result.tax_value
def test_deep_search_results(self): """ """ address = '2114 Bigelow Ave Seattle, WA' zipcode = '98109' responses.add( responses.GET, 'http://www.zillow.com/webservice/GetDeepSearchResults.htm', body='<?xml version="1.0" encoding="utf-8"?><SearchResults:searchresults xsi:schemaLocation="http://www.zillow.com/static/xsd/SearchResults.xsd http://www.zillowstatic.com/vstatic/34794f0/static/xsd/SearchResults.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SearchResults="http://www.zillow.com/static/xsd/SearchResults.xsd"><request><address>2114 Bigelow Ave Seattle, WA</address><citystatezip>98109</citystatezip></request><message><text>Request successfully processed</text><code>0</code></message><response><results><result><zpid>48749425</zpid><links><homedetails>http://www.zillow.com/homedetails/2114-Bigelow-Ave-N-Seattle-WA-98109/48749425_zpid/</homedetails><graphsanddata>http://www.zillow.com/homedetails/2114-Bigelow-Ave-N-Seattle-WA-98109/48749425_zpid/#charts-and-data</graphsanddata><mapthishome>http://www.zillow.com/homes/48749425_zpid/</mapthishome><comparables>http://www.zillow.com/homes/comps/48749425_zpid/</comparables></links><address><street>2114 Bigelow Ave N</street><zipcode>98109</zipcode><city>Seattle</city><state>WA</state><latitude>47.637933</latitude><longitude>-122.347938</longitude></address><FIPScounty>53033</FIPScounty><useCode>SingleFamily</useCode><taxAssessmentYear>2014</taxAssessmentYear><taxAssessment>1060000.0</taxAssessment><yearBuilt>1924</yearBuilt><lotSizeSqFt>4680</lotSizeSqFt><finishedSqFt>3470</finishedSqFt><bathrooms>3.0</bathrooms><bedrooms>4</bedrooms><lastSoldDate>11/26/2008</lastSoldDate><lastSoldPrice currency="USD">1025000</lastSoldPrice><zestimate><amount currency="USD">1419804</amount><last-updated>09/10/2015</last-updated><oneWeekChange deprecated="true"></oneWeekChange><valueChange duration="30" currency="USD">20690</valueChange><valuationRange><low currency="USD">1292022</low><high currency="USD">1547586</high></valuationRange><percentile>0</percentile></zestimate><localRealEstate><region name="East Queen Anne" id="271856" type="neighborhood"><zindexValue>629,900</zindexValue><links><overview>http://www.zillow.com/local-info/WA-Seattle/East-Queen-Anne/r_271856/</overview><forSaleByOwner>http://www.zillow.com/east-queen-anne-seattle-wa/fsbo/</forSaleByOwner><forSale>http://www.zillow.com/east-queen-anne-seattle-wa/</forSale></links></region></localRealEstate></result></results></response></SearchResults:searchresults><!-- H:003 T:27ms S:1181 R:Sat Sep 12 23:30:47 PDT 2015 B:4.0.19615-release_20150908-endor.2fa5797~candidate.358c83d -->', content_type='application/xml', status=200 ) zillow_data = ZillowWrapper(api_key=None) deep_search_response = zillow_data.get_deep_search_results( address, zipcode) result = GetDeepSearchResults(deep_search_response) assert result.zillow_id == '48749425' assert result.home_type == 'SingleFamily' assert result.home_detail_link == \ 'http://www.zillow.com/homedetails/' + \ '2114-Bigelow-Ave-N-Seattle-WA-98109/48749425_zpid/' assert result.graph_data_link == \ 'http://www.zillow.com/homedetails/' + \ '2114-Bigelow-Ave-N-Seattle-WA-98109/' + \ '48749425_zpid/#charts-and-data' assert result.map_this_home_link == \ 'http://www.zillow.com/homes/48749425_zpid/' assert result.tax_year == '2014' assert result.tax_value == '1060000.0' assert result.year_built == '1924' assert result.property_size == '4680' assert result.home_size == '3470' assert result.bathrooms == '3.0' assert result.bedrooms == '4' assert result.last_sold_date == '11/26/2008' assert result.last_sold_price_currency == 'USD' assert result.last_sold_price == '1025000' lat = float(result.latitude) assert lat - 0.01 <= 47.637933 <= lat + 0.01 lng = float(result.longitude) assert lng - 0.01 <= -122.347938 <= lng + 0.01 assert result.zestimate_amount == '1419804' # assert result.zestimate_currency == 'USD' assert result.zestimate_last_updated == '09/10/2015' assert result.zestimate_value_change == '20690' assert result.zestimate_valuation_range_high == '1547586' assert result.zestimate_valuationRange_low == '1292022' assert result.zestimate_percentile == '0'
def test_deep_search_results(self): """ """ address = '2114 Bigelow Ave Seattle, WA' zipcode = '98109' responses.add( responses.GET, 'http://www.zillow.com/webservice/GetDeepSearchResults.htm', body= '<?xml version="1.0" encoding="utf-8"?><SearchResults:searchresults xsi:schemaLocation="http://www.zillow.com/static/xsd/SearchResults.xsd http://www.zillowstatic.com/vstatic/34794f0/static/xsd/SearchResults.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SearchResults="http://www.zillow.com/static/xsd/SearchResults.xsd"><request><address>2114 Bigelow Ave Seattle, WA</address><citystatezip>98109</citystatezip></request><message><text>Request successfully processed</text><code>0</code></message><response><results><result><zpid>48749425</zpid><links><homedetails>http://www.zillow.com/homedetails/2114-Bigelow-Ave-N-Seattle-WA-98109/48749425_zpid/</homedetails><graphsanddata>http://www.zillow.com/homedetails/2114-Bigelow-Ave-N-Seattle-WA-98109/48749425_zpid/#charts-and-data</graphsanddata><mapthishome>http://www.zillow.com/homes/48749425_zpid/</mapthishome><comparables>http://www.zillow.com/homes/comps/48749425_zpid/</comparables></links><address><street>2114 Bigelow Ave N</street><zipcode>98109</zipcode><city>Seattle</city><state>WA</state><latitude>47.637933</latitude><longitude>-122.347938</longitude></address><FIPScounty>53033</FIPScounty><useCode>SingleFamily</useCode><taxAssessmentYear>2014</taxAssessmentYear><taxAssessment>1060000.0</taxAssessment><yearBuilt>1924</yearBuilt><lotSizeSqFt>4680</lotSizeSqFt><finishedSqFt>3470</finishedSqFt><bathrooms>3.0</bathrooms><bedrooms>4</bedrooms><lastSoldDate>11/26/2008</lastSoldDate><lastSoldPrice currency="USD">1025000</lastSoldPrice><zestimate><amount currency="USD">1419804</amount><last-updated>09/10/2015</last-updated><oneWeekChange deprecated="true"></oneWeekChange><valueChange duration="30" currency="USD">20690</valueChange><valuationRange><low currency="USD">1292022</low><high currency="USD">1547586</high></valuationRange><percentile>0</percentile></zestimate><localRealEstate><region name="East Queen Anne" id="271856" type="neighborhood"><zindexValue>629,900</zindexValue><links><overview>http://www.zillow.com/local-info/WA-Seattle/East-Queen-Anne/r_271856/</overview><forSaleByOwner>http://www.zillow.com/east-queen-anne-seattle-wa/fsbo/</forSaleByOwner><forSale>http://www.zillow.com/east-queen-anne-seattle-wa/</forSale></links></region></localRealEstate></result></results></response></SearchResults:searchresults><!-- H:003 T:27ms S:1181 R:Sat Sep 12 23:30:47 PDT 2015 B:4.0.19615-release_20150908-endor.2fa5797~candidate.358c83d -->', content_type='application/xml', status=200) zillow_data = ZillowWrapper(api_key=None) deep_search_response = zillow_data.get_deep_search_results( address, zipcode) result = GetDeepSearchResults(deep_search_response) assert result.zillow_id == '48749425' assert result.home_type == 'SingleFamily' assert result.home_detail_link == \ 'http://www.zillow.com/homedetails/' + \ '2114-Bigelow-Ave-N-Seattle-WA-98109/48749425_zpid/' assert result.graph_data_link == \ 'http://www.zillow.com/homedetails/' + \ '2114-Bigelow-Ave-N-Seattle-WA-98109/' + \ '48749425_zpid/#charts-and-data' assert result.map_this_home_link == \ 'http://www.zillow.com/homes/48749425_zpid/' assert result.tax_year == '2014' assert result.tax_value == '1060000.0' assert result.year_built == '1924' assert result.property_size == '4680' assert result.home_size == '3470' assert result.bathrooms == '3.0' assert result.bedrooms == '4' assert result.last_sold_date == '11/26/2008' assert result.last_sold_price_currency == 'USD' assert result.last_sold_price == '1025000' lat = float(result.latitude) assert lat - 0.01 <= 47.637933 <= lat + 0.01 lng = float(result.longitude) assert lng - 0.01 <= -122.347938 <= lng + 0.01 assert result.zestimate_amount == '1419804' # assert result.zestimate_currency == 'USD' assert result.zestimate_last_updated == '09/10/2015' assert result.zestimate_value_change == '20690' assert result.zestimate_valuation_range_high == '1547586' assert result.zestimate_valuation_range_low == '1292022' assert result.zestimate_percentile == '0'
def call_zillow_api(address, zipcode): #YOUR_ZILLOW_API_KEY = 'X1-ZWz1ffghcdgzkb_a80zd' #[email protected] YOUR_ZILLOW_API_KEY = 'X1-ZWz19ktnpd1lor_67ceq' #[email protected] zillow_data = ZillowWrapper(YOUR_ZILLOW_API_KEY) try: deep_search_response = zillow_data.get_deep_search_results( address, zipcode) result = GetDeepSearchResults(deep_search_response) print 'User input zillow_id = {}'.format(result.zillow_id) except: result = -9999 return result
def getZillowData(address="1600 Pennsylvania Avenue NW", zipcode="20500"): global g_MyApiKey webResponse = "" zillowData = ZillowWrapper(g_MyApiKey) webResponse = zillowData.get_deep_search_results(address, zipcode) result = GetDeepSearchResults(webResponse) print(result.zestimate_percentile) return result
def get_zillow_data(addr_list, zip_list): meta = "https://maps.googleapis.com/maps/api/streetview/metadata?" base = "https://maps.googleapis.com/maps/api/streetview?size=1200x800&" myloc = "C:\\Users\\sumukh210991\\Desktop\\Study\\Thesis\\popularity_score_for_houses\\python\\img" key = "&key=" + "AIzaSyC7-APuKb-aknoKymJdflh2jTC91HBe8rY" data = [] count = 4960 # 4959 for i in range(0, len(addr_list)): address = addr_list[i] zipcode = zip_list[i] zillow_data = ZillowWrapper("X1-ZWz1fpv5bng2rv_799rh" ) # nishant_masc 'X1-ZWz19gfhe5z8y3_8xo7s' # nishant:'X1-ZWz1fk2vm7fkln_8tgid'; # sumukh: 'X1-ZWz1fijmr1w9hn_9fxlx'; # Sumukh@sdsu: 'X1-ZWz19anfkueyob_77v70'; # other: 'X1-ZWz1fpv5bng2rv_799rh'; try: deep_search_response = zillow_data.get_deep_search_results( address, zipcode) result = GetDeepSearchResults(deep_search_response) loc = str(result.latitude) + "," + str(result.longitude) print(loc) params = { "location": loc, "width": "600", "height": "400", "key": "AIzaSyC7-APuKb-aknoKymJdflh2jTC91HBe8rY", "fov": "90", "pitch": "0", "heading": "1" } metaurl = meta + urllib.urlencode(params) MyUrl = base + urllib.urlencode(params) file_loc = "img/file" + (str(count)) + ".png" print(file_loc) status = requests.get(metaurl) if ("ZERO_RESULTS" in str(status.content)): print("NO CONTENT") continue else: count = count + 1 res = urllib.urlretrieve(MyUrl, os.path.join(file_loc)) data.append(result) except: # data.append("none") continue return (data)
def test_deep_search_results(self): """ Tests parsing of deep_search results """ address = "2114 Bigelow Ave Seattle, WA" zipcode = "98109" set_get_deep_search_response( self.api_response_obj.get("get_deep_search_200_ok")) zillow_data = ZillowWrapper(api_key=None) deep_search_response = zillow_data.get_deep_search_results( address, zipcode) result = GetDeepSearchResults(deep_search_response) assert result.zillow_id == "48749425" assert result.home_type == "SingleFamily" assert ( result.home_detail_link == "http://www.zillow.com/homedetails/" + "2114-Bigelow-Ave-N-Seattle-WA-98109/48749425_zpid/") assert ( result.graph_data_link == "http://www.zillow.com/homedetails/" + "2114-Bigelow-Ave-N-Seattle-WA-98109/" + "48749425_zpid/#charts-and-data") assert result.map_this_home_link == "http://www.zillow.com/homes/48749425_zpid/" assert result.tax_year == "2018" assert result.tax_value == "1534000.0" assert result.year_built == "1924" assert result.property_size == "4680" assert result.home_size == "3470" assert result.bathrooms == "3.0" assert result.bedrooms == "4" assert result.last_sold_date == "11/26/2008" assert result.last_sold_price_currency == "USD" assert result.last_sold_price == "995000" lat = float(result.latitude) assert lat - 0.01 <= 47.637933 <= lat + 0.01 lng = float(result.longitude) assert lng - 0.01 <= -122.347938 <= lng + 0.01 assert result.zestimate_amount == "2001121" # assert result.zestimate_currency == 'USD' assert result.zestimate_last_updated == "05/28/2020" assert result.zestimate_value_change == "-16739" assert result.zestimate_valuation_range_high == "2121188" assert result.zestimate_valuation_range_low == "1881054" assert result.zestimate_percentile == "0"
class ZillowPuller(Puller): def __init__(self, zwid): super().__init__() self._headers = ['Zillow Estimate', 'Zillow Last Sold'] self._zillow_data = ZillowWrapper(zwid) @property def headers(self): return self._headers def parse(self, address): address, zip_code, _ = re.search(r'(.*)(\d{5}(-\d{4})?)$', address).groups() result = GetDeepSearchResults(self._zillow_data.get_deep_search_results(address, zip_code)) return { self.headers[0]: result.zestimate_amount, self.headers[1]: result.last_sold_date }
def find_zillow_by_zip(address, zip): zillow_data = ZillowWrapper("X1-ZWz1fe5w83qcjv_70ucn") try: deep_search_response = zillow_data.get_deep_search_results(address, zip) result = GetDeepSearchResults(deep_search_response) zid = result.zillow_id #print zid url = 'http://www.zillow.com/webservice/GetZestimate.htm?zws-id=X1-ZWz1fe5w83qcjv_70ucn&zpid=' + zid #print url page = requests.get(url) tree = html.fromstring(page.content) prices = tree.xpath('//amount/text()') zillow = [zid, prices[0]] return zillow except ZillowError as err: print ("No Zillow Found!") return ['','']
def test_deep_search_results(self): """ """ address = '2114 Bigelow Ave Seattle, WA' zipcode = '98109' zillow_data = ZillowWrapper(self.ZILLOW_API_KEY) deep_search_response = zillow_data.get_deep_search_results( address, zipcode) result = GetDeepSearchResults(deep_search_response) assert result.zillow_id == '48749425' assert result.home_type == 'SingleFamily' assert result.home_detail_link == \ 'http://www.zillow.com/homedetails/' + \ '2114-Bigelow-Ave-N-Seattle-WA-98109/48749425_zpid/' assert result.graph_data_link == \ 'http://www.zillow.com/homedetails/' + \ '2114-Bigelow-Ave-N-Seattle-WA-98109/' + \ '48749425_zpid/#charts-and-data' assert result.map_this_home_link == \ 'http://www.zillow.com/homes/48749425_zpid/' assert result.tax_year == '2013' assert result.tax_value == '995000.0' assert result.year_built == '1924' assert result.property_size == '4680' assert result.home_size == '3470' assert result.bathrooms == '3.0' assert result.bedrooms == '4' assert result.last_sold_date == '11/26/2008' assert result.last_sold_price_currency == 'USD' assert result.last_sold_price == '995000' lat = float(result.latitude) assert lat - 0.01 <= 47.637933 <= lat + 0.01 lng = float(result.longitude) assert lng - 0.01 <= -122.347938 <= lng + 0.01 assert result.zestimate_amount == '1433441' # assert result.zestimate_currency == 'USD' assert result.zestimate_last_updated == '01/06/2015' assert result.zestimate_value_change == '7838' assert result.zestimate_valuation_range_high == '1591120' assert result.zestimate_valuationRange_low == '1275762' assert result.zestimate_percentile == '0'
def get(): lines = request.get_json(force=True) address_: str = lines['address'] #predictants: List[float] = lines['predictands'] # NOTE: TODO: edit in the TEST_REQUESTS notebook to ONLY SEND THE ADDRESS KEY. # # The predicands key _hasn't evne been being used_ address, zipcode = addr_zip_split(address_) try: # doing this in try-except is crucial, because of the way zillow fails # when you give it an address that it doesn't want to / can't use zillow_data = ZillowWrapper(ZILLOW_KEY) deep_search_response = zillow_data.get_deep_search_results( address, zipcode) result = GetDeepSearchResults(deep_search_response) # ['home_size', 'bedrooms', 'bathrooms'] predictants: List[float] = [ result.home_size, result.bedrooms, result.bathrooms ] valuation: float = rfr.model.predict(np.array([predictants]))[0] outdat = { 'upper_lower_bound_by_city': cityfunc(address), 'valuation': valuation } response = app.response_class(response=json.dumps(outdat), status=200, mimetype='application/json') print(outdat) return response except ZillowError as e1: message = "address given not available in zillow api. Please try another address" print(message) return app.response_class(response=json.dumps({"FAIL": message}), status=200, mimetype='application/json')
def find_zillow_by_zip(address, zip): zillow_data = ZillowWrapper("X1-ZWz1fe5w83qcjv_70ucn") try: deep_search_response = zillow_data.get_deep_search_results( address, zip) result = GetDeepSearchResults(deep_search_response) zid = result.zillow_id #print zid url = 'http://www.zillow.com/webservice/GetZestimate.htm?zws-id=X1-ZWz1fe5w83qcjv_70ucn&zpid=' + zid #print url page = requests.get(url) tree = html.fromstring(page.content) prices = tree.xpath('//amount/text()') zillow = [zid, prices[0]] return zillow except ZillowError as err: print("No Zillow Found!") return ['', '']
def zillow_query(address, zipcode, key='YOURAPIKEYHERE'): """Function for obtaining data for a given address location Args: address (str): street address zipcode (str): zipcode corresponding with street address key (str): (default='YOURAPIKEYHERE') zillow api key Returns: returns a GetDeepSearchResults object which has following attributes available: 'zillow_id' 'home_type' 'home_detail_link' 'graph_data_link' 'map_this_home_link' 'latitude' 'longitude' 'tax_year' 'tax_value' 'year_built' 'property_size' 'home_size' 'bathrooms' 'bedrooms' 'last_sold_date' 'last_sold_price' 'zestimate_amount' 'zestimate_last_updated' 'zestimate_value_change' 'zestimate_valuation_range_high' 'zestimate_valuationRange_low' 'zestimate_percentile' """ zillow_data = ZillowWrapper(key) deep_search_response = zillow_data.get_deep_search_results( address, zipcode) result = GetDeepSearchResults(deep_search_response) return result
def get_estimated_price(zillow_id): """ Returns the zillow estimated price given a property ID. """ zkey = current_app.config['ZKEY'] zillow_data = ZillowWrapper(zkey) # check if already exists in DB and if so, that data is less than a week old, otherwise call zillow API db_results = PropertyData.objects(zillow_id=zillow_id) if db_results.count() > 0 and db_results[0].created_at > datetime.now()-timedelta(days=7): zestimate_amount = db_results[0].zestimate_amount else: try: detail_result = PropDetailsWithAddressAndZip(zillow_data.get_updated_property_details(zillow_id)) deep_search_result = GetDeepSearchResults(zillow_data.get_deep_search_results( detail_result.street, detail_result.zip)) zestimate_amount = deep_search_result.zestimate_amount except ZillowError as err: return jsonify({'error': err.message, 'estimate': 0}) return jsonify({'estimate': zestimate_amount, 'error': ''})
def get_property_info(address, zipcode): if address and zipcode: zillow_data = ZillowWrapper(ZILLOW_API_KEY) deep_search_response = zillow_data.get_deep_search_results(address, zipcode) result = GetDeepSearchResults(deep_search_response) return result
list2 = soup.findAll('span', {'itemprop' : 'postalCode'}) list10 = [] for item in list1: text = item.text list10.append(text) list11 = [] for item in list2: text = item.text list11.append(text) zillow_data = ZillowWrapper('X1-ZWz1a2ngha04jv_8s1xw') list6 = [] list7 = [] list9 = [] for i in range (0,len(list10)): deep_search_response = zillow_data.get_deep_search_results(list10[i], list11[i]) result = GetDeepSearchResults(deep_search_response) #print(result.get_attr('home_detail_link')) url2 = result.get_attr('home_detail_link') response = requests.get(url2) html = response.content soup2 = BeautifulSoup(html) list4 = soup2.findAll('ul', { 'class' : 'zsg-list_square zsg-lg-1-3 zsg-md-1-2 zsg-sm-1-1'}) list8 = soup2.findAll('div', {'class':'zsg-lg-2-3 zsg-sm-1-1 hdp-header-description'}) list5 = soup2.findAll('div', {'class': 'main-row home-summary-row'}) for item in list4: text = item.text list6.append(text) for item in list5:
class ZillowClient(object): ''' classdocs ''' def __init__(self, zillow_api_key): if os.path.isfile(ZILLOW_RATE_LIMITER_FILE): self.rate_limiter = RequestRateLimiter.fromFile(ZILLOW_RATE_LIMITER_FILE) else: self.rate_limiter = RequestRateLimiter(max_requests=ZILLOW_QUOTA_MAX_REQUESTS, time_interval=ZILLOW_QUOTA_TIME_INTERVAL, state_file=ZILLOW_RATE_LIMITER_FILE) self.zillow_wrapper = ZillowWrapper(zillow_api_key) @retry(retry_on_exception=isRetryableException, wait_exponential_multiplier=1000, wait_exponential_max=10000) def getDeepSearchResults(self, address, citystatezip, rentzestimate=True): self.rate_limiter.limit() deep_search_response = self.zillow_wrapper.get_deep_search_results( address=address, zipcode=citystatezip, rentzestimate=rentzestimate) return GetDeepSearchResults(deep_search_response) def updatePropertiesWithZillowData(self, properties): for prop in properties: updated_prop = copy.deepcopy(prop) is_updated = False result = None logging.info("Updating: %s, %s, %s", prop["address"], prop["city"], prop["zip"]) try: result = self.getDeepSearchResults( address=prop["address"], citystatezip=prop["city"] + ", " + prop["zip"]) except ZillowError as e: logging.error("No Zillow data found for: %s, %s, %s", prop["address"], prop["city"], prop["zip"]) logging.error("ZillowError: %s", e.message) # Set invalid zillow-id if no exact match was found for input address if e.status in [500, 501, 502, 503, 504, 506, 507, 508]: result = GetDeepSearchResults( data=ElementTree.fromstring(ZILLOW_NOT_FOUND_RESPONSE)) if result: for field in ZILLOW_FIELDS: # Map property fields to Zillow fields. if field == "zillow_url": zillow_field = "home_detail_link" else: zillow_field = field if not hasattr(result, zillow_field): continue old_value = prop.get(field, "") new_value = getattr(result, zillow_field) # Only update fields that have changed. if (new_value != None and str(new_value) != str(old_value)): logging.info("%s: %s -> %s", field, old_value, new_value) updated_prop[field] = new_value is_updated = True if is_updated: logging.info("Updating: %s", prop["address"]) updated_prop["last_update"] = strftime("%Y-%m-%d %H:%M:%S", localtime()) updated_prop["zillow_last_update"] = updated_prop["last_update"] yield updated_prop, is_updated
def zillow(): """ returns r_id with a valid search returns VALID_ZAZ_ERR with invalid search returns VALID_ZWSID_ERR with missing zwsid returns VALID_ADDRESS_ERR with missing address returns VALID_ZIPCODE_ERR with missing zipcode """ if request.method in ['POST', 'GET']: if request.values.get('zwsid'): zwsid = request.values.get('zwsid') log.debug(zwsid) else: return VALID_ZWSID_ERR if request.values.get('address'): address = request.values.get('address') log.debug(address) else: return VALID_ADDRESS_ERR if request.values.get('zipcode'): zipcode = request.values.get('zipcode') log.debug(request) else: return VALID_ZIPCODE_ERR try: zillow_data = ZillowWrapper(zwsid) deep_search_response = zillow_data.get_deep_search_results(address, zipcode) result = GetDeepSearchResults(deep_search_response) except ZillowError as e: log.error(e) return VALID_ZAZ_ERR client = MongoClient() db = client.zillow mongo_result = db.zillow.insert_one( { "request_time":datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M:%S'), "zillow_responce": { "zillow_id": getattr(result, "zillow_id"), "home_type": getattr(result, "home_type"), "home_detail_link": getattr(result, "home_detail_link"), "graph_data_link": getattr(result, "graph_data_link"), "map_this_home_link": getattr(result, "map_this_home_link"), "latitude": getattr(result, "latitude"), "longitude": getattr(result, "longitude"), "tax_year": getattr(result, "tax_year"), "tax_value": getattr(result, "tax_value"), "year_built": getattr(result, "year_built"), "property_size": getattr(result, "property_size"), "home_size": getattr(result, "home_size"), "bathrooms": getattr(result, "bathrooms"), "bedrooms": getattr(result, "bedrooms"), "last_sold_date": getattr(result, "last_sold_date"), "last_sold_price_currency": getattr(result, "last_sold_price_currency"), "last_sold_price": getattr(result, "last_sold_price"), "zestimate_amount": getattr(result, "zestimate_amount"), "zestimate_last_updated": getattr(result, "zestimate_last_updated"), "zestimate_value_change": getattr(result, "zestimate_value_change"), "zestimate_valuation_range_high": getattr(result, "zestimate_valuation_range_high"), "zestimate_valuationRange_low": getattr(result, "zestimate_valuationRange_low"), "zestimate_percentile": getattr(result, "zestimate_percentile") }, "request_information": { 'zwsid':zwsid, 'address': address, 'zipcode': zipcode }, } ) return str(mongo_result.inserted_id) return VALID_ZAZ_ERR
import os from pyzillow.pyzillow import ZillowWrapper, GetDeepSearchResults, GetUpdatedPropertyDetails ZILLOW_API_KEY = os.environ['ZILLOW_API_KEY'] address = '13680 SW Berea Dr Tigard OR' zipcode = '97223' zillow_data = ZillowWrapper(ZILLOW_API_KEY) deep_search_response = zillow_data.get_deep_search_results(address, zipcode) result = GetDeepSearchResults(deep_search_response) zillow_id = result.zillow_id # zillow id, needed for the GetUpdatedPropertyDetails zillow_data = ZillowWrapper(ZILLOW_API_KEY) updated_property_details_response = zillow_data.get_updated_property_details(zillow_id) result = GetUpdatedPropertyDetails(updated_property_details_response) print result.year_built # number of rooms of the home