Skip to content

Instantly share code, notes, and snippets.

@TalhaAwan
Last active August 3, 2017 18:14
Show Gist options
  • Save TalhaAwan/dcc241864df2ef82ed625577a7f2c185 to your computer and use it in GitHub Desktop.
Save TalhaAwan/dcc241864df2ef82ed625577a7f2c185 to your computer and use it in GitHub Desktop.
Node js script to process RETS (Real Estate Transaction Standard) properties.
var rets = require('rets-client');
var async = require('async');
var moment = require('moment');
var clientSettings = {
loginUrl: 'http://maxebrdi.rets.paragonrels.com/rets/fnisrets.aspx/MAXEBRDI/login?rets-version=rets/1.7.2',
username: "XXXXXXXXXXX",
password: "XXXXXXXXXXX",
version: 'RETS/1.7.2',
userAgent: 'RETS node-client/4.x',
method: 'GET'
};
function processRetsProperties(batchSize, query) {
rets.getAutoLogoutClient(clientSettings, function (client) {
// find no of records to process
return client.search.query("PROPERTY", "RE_1", query, {limit:1, offset: 0})
.then(function (data) {
propertyCount = data.count;
if(!propertyCount){
console.log("no records found");
}
else{
console.log(propertyCount + " properties found. Processing...")
var offset = 0;
async.whilst( // loop through to fetch the properties till propertyCount
function() { return offset < propertyCount },
function(callback) {
rets.getAutoLogoutClient(clientSettings, function (client) {
return client.search.query("PROPERTY", "RE_1", query, {limit: batchSize, offset: offset})
.then(function (data) {
var newPropsCount = data.results.length;
console.log();
offset += newPropsCount;
console.log(newPropsCount + " new properties found. ", offset + " total properties processed");
callback(null, offset);
})
}).catch(function (err) {
callback(err)
});
},
function (err, n) {
if(err){
console.log(err)
}
else{
console.log("*** all batch properties processed! ***")
}
}
);
}
});
}).catch(function (err) {
console.log(err)
});
}
processRetsProperties(100, "(L_Status=1_0,1_1,1_2,1_3,1_6,1_7),(LM_Char10_11=BAY,BERKELEY,OAKLAND),(L_UpdateDate="+moment().format('YYYY-MM-DD')+"+)");
237 properties found. Processing...
100 new properties found. 100 total properties processed
100 new properties found. 200 total properties processed
38 new properties found. 238 total properties processed
*** all batch properties processed! ***
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment