-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples.py
More file actions
256 lines (202 loc) · 7.76 KB
/
examples.py
File metadata and controls
256 lines (202 loc) · 7.76 KB
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#!/usr/bin/env python3
"""
Redfin Scraper API - Quick Start Examples
Powered by RealtyAPI.io
These examples demonstrate how to use the Redfin Scraper API
to extract real estate data from Redfin programmatically.
Get your API key at: https://www.realtyapi.io
"""
import json
from redfin_api import RedfinAPI
# ─────────────────────────────────────────────
# Replace with your API key from https://www.realtyapi.io
# ─────────────────────────────────────────────
API_KEY = "YOUR_API_KEY_HERE"
api = RedfinAPI(API_KEY)
# ─────────────────────────────────────────────
# Property Search
# ─────────────────────────────────────────────
def example_search_by_location():
"""Search homes for sale by location."""
print("\n=== Search by Location ===")
data = api.search_by_location(
location_name="New York",
search_type="For_Sale",
sort_order="Newest",
min_beds="Two",
baths="OnePlus",
min_price="500000",
max_price="2000000",
home_type="House,Condo",
page=1,
)
print(json.dumps(data, indent=2))
def example_search_rentals():
"""Search rentals by location."""
print("\n=== Search Rentals ===")
data = api.search_by_location(
location_name="Los Angeles, CA",
search_type="For_Rent",
sort_order="Price_Low_to_High",
min_beds="One",
home_type="Apartment",
)
print(json.dumps(data, indent=2))
def example_search_sold():
"""Search recently sold homes."""
print("\n=== Recently Sold ===")
data = api.search_by_location(
location_name="Miami, FL",
search_type="Sold",
sold_within="Last_1_Month",
sort_order="Most_Recently_Sold",
)
print(json.dumps(data, indent=2))
def example_search_by_coordinates():
"""Circle search by coordinates."""
print("\n=== Search by Coordinates ===")
data = api.search_by_coordinates(
latitude="40.748817",
longitude="-73.985428",
radius="1.5",
search_type="For_Sale",
result_count=50,
)
print(json.dumps(data, indent=2))
def example_search_by_url():
"""Search by Redfin URL."""
print("\n=== Search by URL ===")
data = api.search_by_url(
search_url="https://www.redfin.com/zipcode/10002/filter/property-type=house,min-price=150k,max-price=2M",
result_count=50,
)
print(json.dumps(data, indent=2))
def example_search_by_region_id():
"""Search by Redfin region ID."""
print("\n=== Search by Region ID ===")
data = api.search_by_region_id(
region_id="4_3244",
search_type="For_Sale",
)
print(json.dumps(data, indent=2))
def example_autocomplete():
"""Autocomplete suggestions."""
print("\n=== Autocomplete ===")
data = api.autocomplete("Texas")
print(json.dumps(data, indent=2))
# ─────────────────────────────────────────────
# Property Details
# ─────────────────────────────────────────────
def example_details_by_address():
"""Get property details by address."""
print("\n=== Details by Address ===")
data = api.get_details_by_address("166 W 22nd St Unit 1D, New York, NY 10011")
print(json.dumps(data, indent=2))
def example_details_by_id():
"""Get property details by ID pair."""
print("\n=== Details by ID ===")
data = api.get_details_by_id(
property_id="20739181",
listing_id="192575318",
)
print(json.dumps(data, indent=2))
def example_details_by_url():
"""Get property details by Redfin URL."""
print("\n=== Details by URL ===")
data = api.get_details_by_url(
"https://www.redfin.com/NY/Saint-Albans/10970-203rd-St-11412/home/20739181"
)
print(json.dumps(data, indent=2))
# ─────────────────────────────────────────────
# Individual Property Data
# ─────────────────────────────────────────────
def example_agent_info():
"""Get listing agent info."""
print("\n=== Agent Info ===")
data = api.get_agent_info("20739181", "192575318")
print(json.dumps(data, indent=2))
def example_avm_estimate():
"""Get AVM (Automated Valuation Model) estimate."""
print("\n=== AVM Estimate ===")
data = api.get_avm_estimate("13543215", "207197529")
print(json.dumps(data, indent=2))
def example_walk_score():
"""Get walk, transit, and bike scores."""
print("\n=== Walk Score ===")
data = api.get_walk_score("13543215", "207197529")
print(json.dumps(data, indent=2))
def example_amenities():
"""Get property amenities."""
print("\n=== Amenities ===")
data = api.get_amenities("13543215", "207197529")
print(json.dumps(data, indent=2))
def example_flood_info():
"""Get flood risk information."""
print("\n=== Flood Info ===")
data = api.get_flood_info(
fips_code="36081",
apn="4109420115",
lat="40.7059662",
lng="-73.754585",
)
print(json.dumps(data, indent=2))
def example_mortgage_calculator():
"""Get mortgage calculator data."""
print("\n=== Mortgage Calculator ===")
data = api.get_mortgage_calculator("13543215", "207197529")
print(json.dumps(data, indent=2))
def example_overview():
"""Get property overview."""
print("\n=== Overview ===")
data = api.get_overview("20739181", "192575318")
print(json.dumps(data, indent=2))
def example_insights():
"""Get property insights."""
print("\n=== Insights ===")
data = api.get_insights("20739181", "192575318")
print(json.dumps(data, indent=2))
def example_hot_market():
"""Get hot market info."""
print("\n=== Hot Market Info ===")
data = api.get_hot_market_info("13543215")
print(json.dumps(data, indent=2))
def example_price_drop():
"""Get price drop info."""
print("\n=== Price Drop Info ===")
data = api.get_price_drop_info("207197529")
print(json.dumps(data, indent=2))
def example_basic_details():
"""Get basic details from URL (useful for getting IDs)."""
print("\n=== Basic Details ===")
data = api.get_basic_details(
"https://www.redfin.com/NY/Hollis/9452-199th-St-11423/home/13543215"
)
print(json.dumps(data, indent=2))
# ─────────────────────────────────────────────
# Run examples (uncomment the ones you want)
# ─────────────────────────────────────────────
if __name__ == "__main__":
# Search
example_search_by_location()
# example_search_rentals()
# example_search_sold()
# example_search_by_coordinates()
# example_search_by_url()
# example_search_by_region_id()
# example_autocomplete()
# Property Details
# example_details_by_address()
# example_details_by_id()
# example_details_by_url()
# Individual Data
# example_agent_info()
# example_avm_estimate()
# example_walk_score()
# example_amenities()
# example_flood_info()
# example_mortgage_calculator()
# example_overview()
# example_insights()
# example_hot_market()
# example_price_drop()
# example_basic_details()