Compare commits

..

4 Commits

Author SHA1 Message Date
Naida Vatric
d7fcb2a278 Merge branch 'master' after user-agent change into email-density 2020-02-21 14:26:33 +01:00
Naida Vatric
6bad24d735 New query for search req search. 2020-02-21 14:25:10 +01:00
Naida Vatric
7302edceec Changed queries logic again. 2020-02-18 15:04:26 +01:00
Naida Vatric
bd33a6b80e Logs for query check. 2020-02-17 23:24:55 +01:00
4 changed files with 24 additions and 167 deletions

View File

@@ -45,9 +45,6 @@ const USER_AGENT =
process.env.USER_AGENT || process.env.USER_AGENT ||
"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"; "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36";
const USE_SCRAPER_API = process.env.USE_SCRAPER_API || 1; //Default to use
const SCRAPER_API_KEY = process.env.SCRAPER_API_KEY || "";
module.exports = { module.exports = {
APP_PORT, APP_PORT,
APP_URL, APP_URL,
@@ -62,7 +59,5 @@ module.exports = {
STAGING, STAGING,
CHECK_UP_DAYS, CHECK_UP_DAYS,
PROSTOR_LOGIN, PROSTOR_LOGIN,
USER_AGENT, USER_AGENT
USE_SCRAPER_API,
SCRAPER_API_KEY
}; };

View File

@@ -156,33 +156,11 @@ const findSearchRequestsForRealEstate = async realEstate => {
}; };
} else { } else {
// If real estate dont have defined number of rooms ex. null // If real estate dont have defined number of rooms ex. null
//It returns requests that didn't choose number of rooms - also null //It returns all search requests except for ones that dont want incpomlete ads
//Or ones that picked some values but also picked to includeIncomplete ads (or default)
numberOfRoomsQuery = { numberOfRoomsQuery = {
[Op.or]: [ includeIncompleteAds: {
{ [Op.ne]: false
[Op.and]: [ }
{
numberOfRoomsMin: {
[Op.is]: null
}
},
{
numberOfRoomsMax: {
[Op.is]: null
}
}
]
},
{
includeIncompleteAds: {
[Op.or]: {
[Op.eq]: true,
[Op.is]: null
}
}
}
]
}; };
} }
} }
@@ -212,30 +190,9 @@ const findSearchRequestsForRealEstate = async realEstate => {
}; };
} else { } else {
numberOfFloorsQuery = { numberOfFloorsQuery = {
[Op.or]: [ includeIncompleteAds: {
{ [Op.ne]: false
[Op.and]: [ }
{
numberOfFloorsMin: {
[Op.is]: null
}
},
{
numberOfFloorsMax: {
[Op.is]: null
}
}
]
},
{
includeIncompleteAds: {
[Op.or]: {
[Op.eq]: true,
[Op.is]: null
}
}
}
]
}; };
} }
} }
@@ -264,30 +221,9 @@ const findSearchRequestsForRealEstate = async realEstate => {
}; };
} else { } else {
floorQuery = { floorQuery = {
[Op.or]: [ includeIncompleteAds: {
{ [Op.ne]: false
[Op.and]: [ }
{
floorMin: {
[Op.is]: null
}
},
{
floorMax: {
[Op.is]: null
}
}
]
},
{
includeIncompleteAds: {
[Op.or]: {
[Op.eq]: true,
[Op.is]: null
}
}
}
]
}; };
} }
} }
@@ -296,7 +232,7 @@ const findSearchRequestsForRealEstate = async realEstate => {
//If user dont check checkbox for ex. elevator it does not mean he only wants no elevator //If user dont check checkbox for ex. elevator it does not mean he only wants no elevator
//If real estate characteristic =true find all req, one that wants charachertistic or dont care - dont need query //If real estate characteristic =true find all req, one that wants charachertistic or dont care - dont need query
//If real estate characteristic = false, find all req exept for ones that wants characteristic to be true //If real estate characteristic = false, find all req exept for ones that wants characteristic to be true
//If real estate characteristic = null, dont know if true or false, find req that dont care or want char and want incomplete ads //If real estate characteristic = null, dont know if true or false, find all req except ones that dont want incomplete ads
let balconyQuery = {}; let balconyQuery = {};
if (realEstateTypeObject.hasBalconyProp && balcony !== true) { if (realEstateTypeObject.hasBalconyProp && balcony !== true) {
if (balcony === false) { if (balcony === false) {
@@ -307,30 +243,9 @@ const findSearchRequestsForRealEstate = async realEstate => {
}; };
} else if (balcony === null) { } else if (balcony === null) {
balconyQuery = { balconyQuery = {
[Op.or]: [ includeIncompleteAds: {
{ [Op.ne]: false
balcony: { }
[Op.ne]: true
}
},
{
[Op.and]: [
{
balcony: {
[Op.eq]: true
}
},
{
includeIncompleteAds: {
[Op.or]: {
[Op.eq]: true,
[Op.is]: null
}
}
}
]
}
]
}; };
} }
} }
@@ -344,30 +259,9 @@ const findSearchRequestsForRealEstate = async realEstate => {
}; };
} else if (newBuilding === null) { } else if (newBuilding === null) {
newBuildingQuery = { newBuildingQuery = {
[Op.or]: [ includeIncompleteAds: {
{ [Op.ne]: false
newBuilding: { }
[Op.ne]: true
}
},
{
[Op.and]: [
{
newBuilding: {
[Op.eq]: true
}
},
{
includeIncompleteAds: {
[Op.or]: {
[Op.eq]: true,
[Op.is]: null
}
}
}
]
}
]
}; };
} }
} }
@@ -381,33 +275,13 @@ const findSearchRequestsForRealEstate = async realEstate => {
}; };
} else if (elevator === null) { } else if (elevator === null) {
elevatorQuery = { elevatorQuery = {
[Op.or]: [ includeIncompleteAds: {
{ [Op.ne]: false
elevator: { }
[Op.ne]: true
}
},
{
[Op.and]: [
{
elevator: {
[Op.eq]: true
}
},
{
includeIncompleteAds: {
[Op.or]: {
[Op.eq]: true,
[Op.is]: null
}
}
}
]
}
]
}; };
} }
} }
//General query consists of each individual query //General query consists of each individual query
const query = { const query = {
adType, adType,

View File

@@ -1,9 +1,5 @@
const nodeFetch = require("node-fetch"); const nodeFetch = require("node-fetch");
const { const { USER_AGENT } = require("../config/appConfig");
USER_AGENT,
USE_SCRAPER_API,
SCRAPER_API_KEY
} = require("../config/appConfig");
const fetch = async (url, options = {}) => { const fetch = async (url, options = {}) => {
const newOptions = Object.assign({}, options); const newOptions = Object.assign({}, options);
@@ -11,11 +7,7 @@ const fetch = async (url, options = {}) => {
newOptions["headers"] = {}; newOptions["headers"] = {};
} }
newOptions["headers"]["User-Agent"] = USER_AGENT; newOptions["headers"]["User-Agent"] = USER_AGENT;
const urlAdaptedForScraping = USE_SCRAPER_API return nodeFetch(url, newOptions);
? `http://api.scraperapi.com/?api_key=${SCRAPER_API_KEY}&url=${url}`
: url;
return nodeFetch(urlAdaptedForScraping, newOptions);
}; };
module.exports = fetch; module.exports = fetch;

View File

@@ -22,10 +22,6 @@ GA_ID=Google Analytics ID
#=============== GOOGLE MAPS =============# #=============== GOOGLE MAPS =============#
API_MAP_KEY=(your-key-here) API_MAP_KEY=(your-key-here)
#=============== SCRAPER API SUPORT =============#
USE_SCRAPER_API= To turn it on (1) or off (0)
SCRAPER_API_KEY= Key for Scraper api
#=============== AWS SDK EMAIL SETTINGS =======# #=============== AWS SDK EMAIL SETTINGS =======#
AWS_KEY_ID=(your-key-here) AWS_KEY_ID=(your-key-here)
AWS_SECRET_ACCESS_KEY=(your-key-here) AWS_SECRET_ACCESS_KEY=(your-key-here)