From 2f5cc31ae371d7b6070278d34670fbcae52464e9 Mon Sep 17 00:00:00 2001 From: Jochen Schalanda Date: Wed, 26 Jan 2022 14:41:44 +0100 Subject: [PATCH] =?UTF-8?q?Add=20support=20for=20Immo=20S=C3=BCdwest=20Pre?= =?UTF-8?q?sse=20(immo.swp.de)=20(#45)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/provider/immoswp.js | 52 +++++++++++++++++++++++++++++++++ test/provider/immoswp.test.js | 51 ++++++++++++++++++++++++++++++++ test/provider/testProvider.json | 4 +++ 3 files changed, 107 insertions(+) create mode 100755 lib/provider/immoswp.js create mode 100644 test/provider/immoswp.test.js diff --git a/lib/provider/immoswp.js b/lib/provider/immoswp.js new file mode 100755 index 0000000..898a0a8 --- /dev/null +++ b/lib/provider/immoswp.js @@ -0,0 +1,52 @@ +const utils = require('../utils'); + +let appliedBlackList = []; + +function normalize(o) { + const id = o.id.substring(o.id.indexOf('-') + 1, o.id.length); + const size = o.size || 'N/A m²'; + const price = (o.price || '--- €').replace('Preis auf Anfrage', '--- €'); + const address = o.address || 'No address available'; + const title = o.title || 'No title available'; + const link = `https://immo.swp.de/immobilien/${id}`; + const description = o.description; + return Object.assign(o, { id, address, price, size, title, link, description }); +} + +function applyBlacklist(o) { + const titleNotBlacklisted = !utils.isOneOf(o.title, appliedBlackList); + const descNotBlacklisted = !utils.isOneOf(o.description, appliedBlackList); + + return titleNotBlacklisted && descNotBlacklisted; +} + +const config = { + url: null, + crawlContainer: '.js-serp-item', + sortByDateParam: 's=most_recently_updated_first', + crawlFields: { + id: '@id', + price: 'div.item__spec.item-spec-price | trim', + size: 'div.item__spec.item-spec-area | trim', + title: 'a.js-item-title-link@title', + address: 'div.item__locality | removeNewline | trim', + description: 'div.item__main-info-points.clearfix p small | removeNewline | trim', + }, + paginate: 'li.page-item.pagination__item a.page-link@href', + normalize: normalize, + filter: applyBlacklist, +}; + +exports.init = (sourceConfig, blacklist) => { + config.enabled = sourceConfig.enabled; + config.url = sourceConfig.url; + appliedBlackList = blacklist || []; +}; + +exports.metaInformation = { + name: 'Immo Südwest Presse', + baseUrl: 'https://immo.swp.de/', + id: __filename.slice(__dirname.length + 1, -3), +}; + +exports.config = config; diff --git a/test/provider/immoswp.test.js b/test/provider/immoswp.test.js new file mode 100644 index 0000000..468d46d --- /dev/null +++ b/test/provider/immoswp.test.js @@ -0,0 +1,51 @@ +const similarityCache = require('../../lib/services/similarity-check/similarityCache'); +const mockNotification = require('../mocks/mockNotification'); +const providerConfig = require('./testProvider.json'); +const mockStore = require('../mocks/mockStore'); +const proxyquire = require('proxyquire').noCallThru(); +const expect = require('chai').expect; +const provider = require('../../lib/provider/immoswp'); + +describe('#immoswp testsuite()', () => { + after(() => { + similarityCache.stopCacheCleanup(); + }); + + provider.init(providerConfig.immoswp, [], []); + const Fredy = proxyquire('../../lib/FredyRuntime', { + './services/storage/listingsStorage': { + ...mockStore, + }, + './notification/notify': mockNotification, + }); + + it('should test immoswp provider', async () => { + return await new Promise((resolve) => { + const fredy = new Fredy(provider.config, null, provider.metaInformation.id, 'test1', similarityCache); + fredy.execute().then((listing) => { + expect(listing).to.be.a('array'); + + const notificationObj = mockNotification.get(); + expect(notificationObj).to.be.a('object'); + expect(notificationObj.serviceName).to.equal('immoswp'); + + notificationObj.payload.forEach((notify) => { + /** check the actual structure **/ + expect(notify.id).to.be.a('string'); + expect(notify.price).to.be.a('string'); + expect(notify.size).to.be.a('string'); + expect(notify.title).to.be.a('string'); + expect(notify.link).to.be.a('string'); + expect(notify.address).to.be.a('string'); + + /** check the values if possible **/ + expect(notify.price).that.does.include('€'); + expect(notify.title).to.be.not.empty; + expect(notify.link).that.does.include('https://immo.swp.de'); + expect(notify.address).to.be.not.empty; + }); + resolve(); + }); + }); + }); +}); diff --git a/test/provider/testProvider.json b/test/provider/testProvider.json index 372a75b..202830d 100644 --- a/test/provider/testProvider.json +++ b/test/provider/testProvider.json @@ -16,6 +16,10 @@ "url": "https://www.immobilienscout24.de/Suche/de/nordrhein-westfalen/duesseldorf/wohnung-mieten?enteredFrom=one_step_search", "enabled": true }, + "immoswp": { + "url": "https://immo.swp.de/suchergebnisse?l=M%C3%BCnchen&r=0km&_multiselect_r=0km&ut=private&t=apartment%3Arental&a=de.muenchen&pf=&pt=&rf=0&rt=0&sf=50&st=&yf=&yt=&ff=&ft=&s=most_recently_updated_first&pa=&o=&ad=&u=", + "enabled": true + }, "kalaydo": { "url": "https://www.kalaydo.de/immobilien/eigentumswohnung-kaufen/o/duesseldorf/4/?attr_gt_estate_size_living_area=90.0&attr_gt_no_of_rooms=3.5&maxPrice=420000.00&radius=5&resultsPerPage=50&sorting=-date", "enabled": true