File size: 7,811 Bytes
a51a15b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
from typing import Dict
import logging
from agent.tools.data_providers.RapidDataProviderBase import RapidDataProviderBase, EndpointSchema
logger = logging.getLogger(__name__)
class ZillowProvider(RapidDataProviderBase):
def __init__(self):
endpoints: Dict[str, EndpointSchema] = {
"search": {
"route": "/search",
"method": "GET",
"name": "Zillow Property Search",
"description": "Search for properties by neighborhood, city, or ZIP code with various filters.",
"payload": {
"location": "Location can be an address, neighborhood, city, or ZIP code (required)",
"page": "Page number for pagination (optional, default: 0)",
"output": "Output format: json, csv, xlsx (optional, default: json)",
"status": "Status of properties: forSale, forRent, recentlySold (optional, default: forSale)",
"sortSelection": "Sorting criteria (optional, default: priorityscore)",
"listing_type": "Listing type: by_agent, by_owner_other (optional, default: by_agent)",
"doz": "Days on Zillow: any, 1, 7, 14, 30, 90, 6m, 12m, 24m, 36m (optional, default: any)",
"price_min": "Minimum price (optional)",
"price_max": "Maximum price (optional)",
"sqft_min": "Minimum square footage (optional)",
"sqft_max": "Maximum square footage (optional)",
"beds_min": "Minimum number of bedrooms (optional)",
"beds_max": "Maximum number of bedrooms (optional)",
"baths_min": "Minimum number of bathrooms (optional)",
"baths_max": "Maximum number of bathrooms (optional)",
"built_min": "Minimum year built (optional)",
"built_max": "Maximum year built (optional)",
"lotSize_min": "Minimum lot size in sqft (optional)",
"lotSize_max": "Maximum lot size in sqft (optional)",
"keywords": "Keywords to search for (optional)"
}
},
"search_address": {
"route": "/search_address",
"method": "GET",
"name": "Zillow Address Search",
"description": "Search for a specific property by its full address.",
"payload": {
"address": "Full property address (required)"
}
},
"propertyV2": {
"route": "/propertyV2",
"method": "GET",
"name": "Zillow Property Details",
"description": "Get detailed information about a specific property by zpid or URL.",
"payload": {
"zpid": "Zillow property ID (optional if URL is provided)",
"url": "Property details URL (optional if zpid is provided)"
}
},
"zestimate_history": {
"route": "/zestimate_history",
"method": "GET",
"name": "Zillow Zestimate History",
"description": "Get historical Zestimate values for a specific property.",
"payload": {
"zpid": "Zillow property ID (optional if URL is provided)",
"url": "Property details URL (optional if zpid is provided)"
}
},
"similar_properties": {
"route": "/similar_properties",
"method": "GET",
"name": "Zillow Similar Properties",
"description": "Find properties similar to a specific property.",
"payload": {
"zpid": "Zillow property ID (optional if URL or address is provided)",
"url": "Property details URL (optional if zpid or address is provided)",
"address": "Property address (optional if zpid or URL is provided)"
}
},
"mortgage_rates": {
"route": "/mortgage/rates",
"method": "GET",
"name": "Zillow Mortgage Rates",
"description": "Get current mortgage rates for different loan programs and conditions.",
"payload": {
"program": "Loan program (required): Fixed30Year, Fixed20Year, Fixed15Year, Fixed10Year, ARM3, ARM5, ARM7, etc.",
"state": "State abbreviation (optional, default: US)",
"refinance": "Whether this is for refinancing (optional, default: false)",
"loanType": "Type of loan: Conventional, etc. (optional)",
"loanAmount": "Loan amount category: Micro, SmallConforming, Conforming, SuperConforming, Jumbo (optional)",
"loanToValue": "Loan to value ratio: Normal, High, VeryHigh (optional)",
"creditScore": "Credit score category: Low, High, VeryHigh (optional)",
"duration": "Duration in days (optional, default: 30)"
}
},
}
base_url = "https://zillow56.p.rapidapi.com"
super().__init__(base_url, endpoints)
if __name__ == "__main__":
from dotenv import load_dotenv
from time import sleep
load_dotenv()
tool = ZillowProvider()
# Example for searching properties in Houston
search_result = tool.call_endpoint(
route="search",
payload={
"location": "houston, tx",
"status": "forSale",
"sortSelection": "priorityscore",
"listing_type": "by_agent",
"doz": "any"
}
)
logger.debug("Search Result: %s", search_result)
logger.debug("***")
logger.debug("***")
logger.debug("***")
sleep(1)
# Example for searching by address
address_result = tool.call_endpoint(
route="search_address",
payload={
"address": "1161 Natchez Dr College Station Texas 77845"
}
)
logger.debug("Address Search Result: %s", address_result)
logger.debug("***")
logger.debug("***")
logger.debug("***")
sleep(1)
# Example for getting property details
property_result = tool.call_endpoint(
route="propertyV2",
payload={
"zpid": "7594920"
}
)
logger.debug("Property Details Result: %s", property_result)
sleep(1)
logger.debug("***")
logger.debug("***")
logger.debug("***")
# Example for getting zestimate history
zestimate_result = tool.call_endpoint(
route="zestimate_history",
payload={
"zpid": "20476226"
}
)
logger.debug("Zestimate History Result: %s", zestimate_result)
sleep(1)
logger.debug("***")
logger.debug("***")
logger.debug("***")
# Example for getting similar properties
similar_result = tool.call_endpoint(
route="similar_properties",
payload={
"zpid": "28253016"
}
)
logger.debug("Similar Properties Result: %s", similar_result)
sleep(1)
logger.debug("***")
logger.debug("***")
logger.debug("***")
# Example for getting mortgage rates
mortgage_result = tool.call_endpoint(
route="mortgage_rates",
payload={
"program": "Fixed30Year",
"state": "US",
"refinance": "false",
"loanType": "Conventional",
"loanAmount": "Conforming",
"loanToValue": "Normal",
"creditScore": "Low",
"duration": "30"
}
)
logger.debug("Mortgage Rates Result: %s", mortgage_result)
|