House hunting with data
House hunting is a pain in the ass. There's lots of websites that will show you many many house listings and their filters are all very basic. If what you want is any 3 bedroom home with greater than 1200sqrft and at least 2 bathrooms then you are set.
I want a great commute, a good walkscore, and some way to compare square footage per room and lot size. So I wrote a script to pull that information for me.
Google Distance Matrix API
I don't want to spend a large chunk of my day in traffic, so my commute time is important. I have not yet found a site that will let me set my work address and then filter homes based on commute so I gotta do it myself. Every time I find a house that looks nice I google map my commute.
It turns out that google offers a REST API for that. Here is some basic python code to get you going.
address = '<home address'
work = '<work address>'
gdm_key = '<your key here>'
gdm_base_url = 'https://maps.googleapis.com/maps/api/distancematrix/json'
url = gdm_base_url + '?' + urllib.parse.urlencode({
'origins': address,
'destinations': work,
'mode': 'transit',
'units': 'imperial',
'key': gdm_key,
'arrival_time': int(arr_time)
})
response = urllib.request.urlopen(url)
data = response.read().decode('utf-8')
data = json.loads(data)
commute_time = data['rows'][0]['elements'][0]['duration']['text']
The response is something like this:
{
"status": "OK",
"origin_addresses": "<home address>",
"destination_addresses": "<work address>",
"rows": [ {
"elements": [ {
"status": "OK",
"duration": {
"value": 22,
"text": "22 minutes"
},
"distance": {
"value": 11,
"text": "11 mi"
}
}]
}]
}
Besides my work commute I am also checking time to my gym and the wife's commute.
For more details on this api check the Google distance matrix documentation.
Walk Score API
I would like to live in a neighborhood with some ammenities in walking distance. Im not asking for much but a coffeeshop a bar and a grocery store would be great. I can't get that specific but Walkscore offers a nice aproximation. Sometimes it's scores are inflated by things that I would never walk to but usually it's okay.
Walk Score offers a REST API too! Notice a trend yet?
The code is pretty similar just change the URL parameters:
address = '<home address>'
walk_key = '<your key>'
walk_base_url = 'http://api.walkscore.com/score'
w_url = walk_base_url + '?' + urllib.parse.urlencode({
'format': 'json',
'address': address,
'lat': latitude,
'lon': longitude,
'wsapikey': walk_key,
'transit': 1
})
...
What you get back looks like this:
{
"status": 1,
"walkscore": 98,
"description": "Walker's Paradise",
"updated": "2016-11-17 04:40:31.218250",
"logo_url": "https://cdn.walk.sc/images/api-logo.png",
"more_info_icon": "https://cdn.walk.sc/images/api-more-info.gif",
"more_info_link": "https://www.walkscore.com/how-it-works/",
"ws_link": "https://www.walkscore.com/score/1119-8th-Avenue-Seattle-WA-98101/lat=47.6085/lng=-122.3295/?utm_source=walkscore.com&utm_medium=ws_api&utm_campaign=ws_api",
"help_link": "https://www.walkscore.com/how-it-works/",
"snapped_lat": 47.6085,
"snapped_lon": -122.3295,
"transit" : {
"score": 100,
"description": "Rider's Paradise",
"summary": "115 nearby routes: 103 bus, 6 rail, 6 other"
}
}
One quirk in the Walk Score API is that it wants latitude and longitude. You can certainly get that from one of Google's APIs but Zillow has it too and other information I am after so thats where I source it.
Zillow GetDeepSearch-Results API
Zillow wont give you the ability to search for listings in their API (at least not as far as I have seen) but they will give you a bunch of information if you already know the address you want to look up.
Zillow returns XML so I use xml.etree.ElementTree to parse it.
street = '<your atreet>'
city_state = '<your city, state>'
zws_id = '<your zillow key here>'
z_url = zws_base_url + '?' + urllib.parse.urlencode({
'zws-id': zws_id,
'address': street,
'citystatezip': city_state
})
response = urllib.request.urlopen(z_url)
data = response.read()
root = etree.fromstring(data)
latitude = root.find("./response/results/result/address/latitude").text
longitude = root.find("./response/results/result/address/longitude").text
The response xml file is too big for this blog post. You can dig into the example here on Zillow's API documentation page.
Note the lat and lon for walk score.
I have a script, now what?
Well, I made a web app using Flask and uwsgi and I rolled it into a docker image.
FROM tiangolo/uwsgi-nginx:python3.5
COPY ./app /app
RUN pip3 install flask
You could use any server side scripting language you like and acomplish the same thing. You do still have to manually enter the addresses as you find them. I have been toying with the idea of setting up a script to check my email for new listings from Zillow, Redfin, or whoever to try to capture the new listing address and feed it into my script. If I do it I'll make another post for it.
Let me know in the comments if you have found a fantastic REST API for house hunting.