Skip to content

Instantly share code, notes, and snippets.

@nickpeihl
Last active July 21, 2017 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickpeihl/688b3ab9de7eeadfeefc6a871e14dc79 to your computer and use it in GitHub Desktop.
Save nickpeihl/688b3ab9de7eeadfeefc6a871e14dc79 to your computer and use it in GitHub Desktop.
Homeaway Listings to GeoJSON

homeaway listings

Create a GeoJSON file of HomeAway listings in a bounding box.

Usage

  1. Request access to the HomeAway Developer API.
  2. Create a new client on the My Clients page.
  3. Set the HOMEAWAY_CLIENT_ID and HOMEAWAY_CLIENT_SECRET environment variables in your operating system to your client values.
  4. Install Node.js.
  5. Download and extract zip file or git clone this repo.
  6. From the command line cd into the directory and run npm install.
  7. Optionally, change the lowerLeftLatitude, lowerLeftLongitude, upperRightLatitude, upperRightLongitude variables in the index.js file. It is set to the San Juan County, WA by default.
  8. Run node index.js to create or update the homeaway-listings.json file.
  9. View the homeaway-listings.json file in http://geojson.io.
var request = require('request')
var turf = require('@turf/helpers')
var fs = require('fs')
var credentials = new Buffer(`${process.env.HOMEAWAY_CLIENT_ID}:${process.env.HOMEAWAY_CLIENT_SECRET}`).toString('base64')
var data = []
var token
request.post('https://ws.homeaway.com/oauth/token', {
headers: {
Authorization: 'Basic ' + credentials
}
}, function (err, res, body) {
if (err) throw err
token = JSON.parse(body).access_token
var opts = {
json: true,
qs: {
lowerLeftLatitude: 48.385442,
lowerLeftLongitude: -123.296814,
upperRightLatitude: 48.828566,
upperRightLongitude: -122.733765,
pageSize: 30
},
headers: {
Authorization: 'Bearer ' + token
}
}
getData('https://ws.homeaway.com/public/search', opts, function (err, data) {
if (err) throw err
else {
fs.writeFileSync('homeaway-listings.json', JSON.stringify(data, null, 2))
}
})
})
function getData (url, opts, cb) {
if (typeof opts === 'function') {
cb = opts
opts = {}
}
request.get(url, opts, function (err, res, body) {
if (err) cb(err)
if (res.statusCode !== 200) {
cb('Server responded with: ', res.statusCode, res.statusMessage)
} else {
data = data.concat(body.entries.filter(function (entry) {
return entry.location.country === 'US'
}).map(convertToGeojson))
body.page <= body.pageCount && body.nextPage
? getData(body.nextPage, {
json: true,
headers: {
Authorization: 'Bearer ' + token
}
}, cb)
: cb(null, turf.featureCollection(data))
}
})
}
function convertToGeojson (entry) {
var point = turf.point([entry.location.lng, entry.location.lat], entry)
return point
}
{
"name": "homeway-listings",
"version": "1.0.0",
"dependencies": {
"@turf/helpers": "^4.3.0",
"request": "^2.81.0"
},
"main": "index.js",
"bin": "./index.js",
"license": "Apache-2.0"
}
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment