Compare commits
3 Commits
email-dens
...
scraper-ap
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce857ddce9 | ||
|
|
148b2ea863 | ||
|
|
d436d4a37b |
@@ -45,6 +45,9 @@ const 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";
|
||||
|
||||
const USE_SCRAPER_API = process.env.USE_SCRAPER_API || 1; //Default to use
|
||||
const SCRAPER_API_KEY = process.env.SCRAPER_API_KEY || "";
|
||||
|
||||
module.exports = {
|
||||
APP_PORT,
|
||||
APP_URL,
|
||||
@@ -59,5 +62,7 @@ module.exports = {
|
||||
STAGING,
|
||||
CHECK_UP_DAYS,
|
||||
PROSTOR_LOGIN,
|
||||
USER_AGENT
|
||||
USER_AGENT,
|
||||
USE_SCRAPER_API,
|
||||
SCRAPER_API_KEY
|
||||
};
|
||||
|
||||
@@ -156,11 +156,33 @@ const findSearchRequestsForRealEstate = async realEstate => {
|
||||
};
|
||||
} else {
|
||||
// If real estate dont have defined number of rooms ex. null
|
||||
//It returns all search requests except for ones that dont want incpomlete ads
|
||||
//It returns requests that didn't choose number of rooms - also null
|
||||
//Or ones that picked some values but also picked to includeIncomplete ads (or default)
|
||||
numberOfRoomsQuery = {
|
||||
includeIncompleteAds: {
|
||||
[Op.ne]: false
|
||||
}
|
||||
[Op.or]: [
|
||||
{
|
||||
[Op.and]: [
|
||||
{
|
||||
numberOfRoomsMin: {
|
||||
[Op.is]: null
|
||||
}
|
||||
},
|
||||
{
|
||||
numberOfRoomsMax: {
|
||||
[Op.is]: null
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
includeIncompleteAds: {
|
||||
[Op.or]: {
|
||||
[Op.eq]: true,
|
||||
[Op.is]: null
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -190,9 +212,30 @@ const findSearchRequestsForRealEstate = async realEstate => {
|
||||
};
|
||||
} else {
|
||||
numberOfFloorsQuery = {
|
||||
includeIncompleteAds: {
|
||||
[Op.ne]: false
|
||||
}
|
||||
[Op.or]: [
|
||||
{
|
||||
[Op.and]: [
|
||||
{
|
||||
numberOfFloorsMin: {
|
||||
[Op.is]: null
|
||||
}
|
||||
},
|
||||
{
|
||||
numberOfFloorsMax: {
|
||||
[Op.is]: null
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
includeIncompleteAds: {
|
||||
[Op.or]: {
|
||||
[Op.eq]: true,
|
||||
[Op.is]: null
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -221,9 +264,30 @@ const findSearchRequestsForRealEstate = async realEstate => {
|
||||
};
|
||||
} else {
|
||||
floorQuery = {
|
||||
includeIncompleteAds: {
|
||||
[Op.ne]: false
|
||||
}
|
||||
[Op.or]: [
|
||||
{
|
||||
[Op.and]: [
|
||||
{
|
||||
floorMin: {
|
||||
[Op.is]: null
|
||||
}
|
||||
},
|
||||
{
|
||||
floorMax: {
|
||||
[Op.is]: null
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
includeIncompleteAds: {
|
||||
[Op.or]: {
|
||||
[Op.eq]: true,
|
||||
[Op.is]: null
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -232,7 +296,7 @@ const findSearchRequestsForRealEstate = async realEstate => {
|
||||
//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 = 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 all req except ones that dont want incomplete ads
|
||||
//If real estate characteristic = null, dont know if true or false, find req that dont care or want char and want incomplete ads
|
||||
let balconyQuery = {};
|
||||
if (realEstateTypeObject.hasBalconyProp && balcony !== true) {
|
||||
if (balcony === false) {
|
||||
@@ -243,9 +307,30 @@ const findSearchRequestsForRealEstate = async realEstate => {
|
||||
};
|
||||
} else if (balcony === null) {
|
||||
balconyQuery = {
|
||||
includeIncompleteAds: {
|
||||
[Op.ne]: false
|
||||
}
|
||||
[Op.or]: [
|
||||
{
|
||||
balcony: {
|
||||
[Op.ne]: true
|
||||
}
|
||||
},
|
||||
{
|
||||
[Op.and]: [
|
||||
{
|
||||
balcony: {
|
||||
[Op.eq]: true
|
||||
}
|
||||
},
|
||||
{
|
||||
includeIncompleteAds: {
|
||||
[Op.or]: {
|
||||
[Op.eq]: true,
|
||||
[Op.is]: null
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -259,9 +344,30 @@ const findSearchRequestsForRealEstate = async realEstate => {
|
||||
};
|
||||
} else if (newBuilding === null) {
|
||||
newBuildingQuery = {
|
||||
includeIncompleteAds: {
|
||||
[Op.ne]: false
|
||||
}
|
||||
[Op.or]: [
|
||||
{
|
||||
newBuilding: {
|
||||
[Op.ne]: true
|
||||
}
|
||||
},
|
||||
{
|
||||
[Op.and]: [
|
||||
{
|
||||
newBuilding: {
|
||||
[Op.eq]: true
|
||||
}
|
||||
},
|
||||
{
|
||||
includeIncompleteAds: {
|
||||
[Op.or]: {
|
||||
[Op.eq]: true,
|
||||
[Op.is]: null
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -275,13 +381,33 @@ const findSearchRequestsForRealEstate = async realEstate => {
|
||||
};
|
||||
} else if (elevator === null) {
|
||||
elevatorQuery = {
|
||||
includeIncompleteAds: {
|
||||
[Op.ne]: false
|
||||
}
|
||||
[Op.or]: [
|
||||
{
|
||||
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
|
||||
const query = {
|
||||
adType,
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
const nodeFetch = require("node-fetch");
|
||||
const { USER_AGENT } = require("../config/appConfig");
|
||||
const {
|
||||
USER_AGENT,
|
||||
USE_SCRAPER_API,
|
||||
SCRAPER_API_KEY
|
||||
} = require("../config/appConfig");
|
||||
|
||||
const fetch = async (url, options = {}) => {
|
||||
const newOptions = Object.assign({}, options);
|
||||
@@ -7,7 +11,11 @@ const fetch = async (url, options = {}) => {
|
||||
newOptions["headers"] = {};
|
||||
}
|
||||
newOptions["headers"]["User-Agent"] = USER_AGENT;
|
||||
return nodeFetch(url, newOptions);
|
||||
const urlAdaptedForScraping = USE_SCRAPER_API
|
||||
? `http://api.scraperapi.com/?api_key=${SCRAPER_API_KEY}&url=${url}`
|
||||
: url;
|
||||
|
||||
return nodeFetch(urlAdaptedForScraping, newOptions);
|
||||
};
|
||||
|
||||
module.exports = fetch;
|
||||
|
||||
@@ -22,6 +22,10 @@ GA_ID=Google Analytics ID
|
||||
#=============== GOOGLE MAPS =============#
|
||||
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_KEY_ID=(your-key-here)
|
||||
AWS_SECRET_ACCESS_KEY=(your-key-here)
|
||||
|
||||
Reference in New Issue
Block a user