Skip to content
This repository has been archived by the owner on Jun 19, 2023. It is now read-only.

Commit

Permalink
impr yandex
Browse files Browse the repository at this point in the history
  • Loading branch information
norbornen committed Oct 30, 2018
1 parent 9d1d357 commit 78d654e
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules/*
config/*
db/*
yarn.lock
yarn-error.log
.vscode/*
2 changes: 2 additions & 0 deletions lib/ax.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const axios = require('axios');
const qs = require('qs');

module.exports.create = (headers) => {
const ax = axios.create();
Expand All @@ -7,5 +8,6 @@ module.exports.create = (headers) => {
if (headers) {
Object.entries(headers).forEach(([k, v]) => ax.defaults.headers.common[k] = v);
}
ax.defaults.paramsSerializer = (params) => qs.stringify(params, {arrayFormat: 'repeat'});
return ax;
};
4 changes: 2 additions & 2 deletions lib/provider/avito.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ module.exports.getOffers = async () => {
let points = path(['data', 'coords'], rawListRes) || {};
points = Object.entries(points).map(([k, v]) => Object.assign({id: k, lng: v.lon}, v))
.filter(({id}) => db.data.indexOf(id) === -1);

let offers = await queue.addAll(points.map((x) => () => {
return ax.get(urlGetItems, {params: x});
}));
offers = offers.map((x) => path(['data', 'items'], x) || []);
offers = Object.assign({}, ...offers);
offers = Object.entries(offers).map(([k, v]) => Object.assign({id: k}, v))
.filter((x) => pathOr(0, ['ext', 'rooms'], x) >= 2
.filter((x) => pathOr(0, ['ext', 'rooms'], x) >= 2
&& db.data.indexOf(x.id) === -1
&& geoFilter(path(['ext', 'address'], x))
)
Expand Down
2 changes: 1 addition & 1 deletion lib/provider/thelocals.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports.getOffers = async () => {
const rawListRes = (await ax.post(urlGetIdx, query));
const points = path(['data', 'ads'], rawListRes) || [];

const offers = points.filter((x) => pathOr(0, ['rooms'], x) >= 2
const offers = points.filter((x) => pathOr(0, ['rooms'], x) >= 2
&& db.data.indexOf(x.id) === -1
&& geoFilter(x.address)
)
Expand Down
31 changes: 10 additions & 21 deletions lib/provider/yandex.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,26 @@
const config = require('config');
const PQueue = require('p-queue');
const { path } = require('ramda');
const Ax = require('../ax');
const Db = require('../db');
const { Offer } = require('./offer');
const geoFilter = require('../geo_filter');

const queue = new PQueue({concurrency: 1});
const ax = Ax.create({'content-type': 'application/json'});

module.exports.getOffers = async () => {
const db = await Db.create('yandex');

const urlGetIdx = 'https://realty.yandex.ru/gate/map/offers-points-with-counter/';
const urlGetItems = 'https://realty.yandex.ru/gate/map/offers-gen2/';
const urlGetIdx = 'https://realty.yandex.ru/gate/react-page/get/';
const query = config.get('yandex.query');
const listQuery = config.get('yandex.listQuery');

const rawListRes = (await ax.get(urlGetIdx, {params: Object.assign({}, query, listQuery)}));
let points = path(['data', 'response', 'points'], rawListRes) || [];
points = points.filter(({id}) => db.data.indexOf(id) === -1);

let offers = await queue.addAll(points.map((x) => () => {
const lat = x.lat; const lon = x.lon; const pageSize = 100;
return ax.get(urlGetItems, {params: Object.assign({lat, lon, pageSize}, query)});
}));
offers = offers.map((x) => path(['data', 'response', 'items', 'entities'], x) || []);
offers = [].concat(...offers);
offers = offers.filter((x) => x.roomsTotal >= 2
&& db.data.indexOf(x.offerId) === -1
&& geoFilter(path(['location', 'geocoderAddress'], x))
)
.map((x) => new YandexOffer(x));

const rawListRes = await ax.get(urlGetIdx, {params: query});

const points = path(['data', 'response', 'search', 'offers', 'entities'], rawListRes) || [];
const offers = points.filter((x) => x.roomsTotal >= 2
&& db.data.indexOf(x.offerId) === -1
&& geoFilter(path(['location', 'geocoderAddress'], x))
)
.map((x) => new YandexOffer(x));

console.log(`[yandex] idx: ${points.length}, offers: ${offers.length}`);
if (offers.length > 0) {
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "cyanic",
"version": "1.0.5",
"version": "1.0.6",
"main": "index.js",
"license": "MIT",
"scripts": {
"dev": "rm -rf db && NODE_ENV=development ./index.js",
"lint": "./node_modules/.bin/eslint --ext .js ."
},
"dependencies": {
Expand All @@ -13,6 +14,7 @@
"p-queue": "^3.0.0",
"p-retry": "^2.0.0",
"p-settle": "^2.1.0",
"qs": "^6.5.2",
"ramda": "^0.25.0",
"telegraf": "^3.24.1"
},
Expand Down

0 comments on commit 78d654e

Please sign in to comment.