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

Commit

Permalink
impr cian
Browse files Browse the repository at this point in the history
  • Loading branch information
norbornen committed Oct 30, 2018
1 parent 305d922 commit 9d1d357
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env node
'use strict';

const pSettle = require('p-settle');
const pRetry = require('p-retry');
Expand Down
37 changes: 15 additions & 22 deletions lib/provider/cian.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

const config = require('config');
const { path } = require('ramda');
const Ax = require('../ax');
Expand All @@ -10,29 +12,20 @@ const ax = Ax.create();
module.exports.getOffers = async () => {
const db = await Db.create('cian');

const urlGetIdx = 'https://api.cian.ru/search-offers/v1/get-infinite-search-result-desktop/';
const urlGetItems = 'https://api.cian.ru/search-offers/v1/get-offers-by-ids-desktop/';
const urlGetIdx = 'https://api.cian.ru/search-offers/v2/search-offers-desktop/';
const jsonQuery = config.get('cian.jsonQuery');
const queryString = config.get('cian.queryString');

const rawIdx = [].concat(
...(await Promise.all([
ax.post(urlGetIdx, {jsonQuery, queryString}),
ax.post(urlGetIdx, Object.assign({pageNumber: 2}, {jsonQuery, queryString}))
]))
.map(({data}) => data.infiniteSearchResult || [])
);
const cianOfferIds = rawIdx.map(({itemId}) => itemId);

let offers = (await ax.post(urlGetItems, {cianOfferIds, jsonQuery})).data.offersSerialized || [];
offers = offers.filter((x) => x.roomsCount >= 2
&& x.childrenAllowed !== false
&& db.data.indexOf(x.cianId) === -1
&& geoFilter(path(['geo', 'userInput'], x))
)
.map((x) => new CianOffer(x));

console.log(`[cian] idx: ${cianOfferIds.length}, offers: ${offers.length}`);

const rawListRes = (await ax.post(urlGetIdx, {jsonQuery}));

const points = path(['data', 'data', 'offersSerialized'], rawListRes) || [];
const offers = points.filter((x) => x.roomsCount >= 2
&& x.childrenAllowed !== false
&& db.data.indexOf(x.cianId) === -1
&& geoFilter(path(['geo', 'userInput'], x))
)
.map((x) => new CianOffer(x));

console.log(`[cian] idx: ${points.length}, offers: ${offers.length}`);
if (offers.length > 0) {
db.data = db.data.concat(offers.map(({cianId}) => cianId));
await db.save();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cyanic",
"version": "1.0.4",
"version": "1.0.5",
"main": "index.js",
"license": "MIT",
"scripts": {
Expand Down

0 comments on commit 9d1d357

Please sign in to comment.