diff --git a/README.md b/README.md index f3ab81f..a909e8d 100755 --- a/README.md +++ b/README.md @@ -95,6 +95,10 @@ These are the current provider that are already implemented within _Fredy_ "neubauKompass": { "url": "https://www.neubaukompass.de/...", "enabled": true +}, +"wgGesucht": { + "url": "https://www.wg-gesucht.de/...", + "enabled": true } ``` @@ -124,7 +128,7 @@ whole words) are removed. #### District blacklist ```json -"blacklistedDistrics": [ +"blacklistedDistricts": [ "Altstadt" ] ``` diff --git a/conf/config.example b/conf/config.example index a81bcd4..cdc4db5 100755 --- a/conf/config.example +++ b/conf/config.example @@ -44,6 +44,10 @@ },"neubauKompass": { "url": "https://www.neubaukompass.de/...", "enabled": true + }, + "wgGesucht": { + "url": "https://www.wg-gesucht.de/...", + "enabled": true } }, "blacklist": [ diff --git a/conf/config.test.json b/conf/config.test.json index cf88e2c..437b4c8 100755 --- a/conf/config.test.json +++ b/conf/config.test.json @@ -45,12 +45,13 @@ "neubauKompass": { "url": "https://www.neubaukompass.de/neubau-immobilien/duesseldorf-region/eigentumswohnung/", "enabled": true + }, + "wgGesucht": { + "url": "https://www.wg-gesucht.de/wg-zimmer-in-Duesseldorf.30.0.1.0.html?offer_filter=1&noDeact=1&city_id=30&category=0&rent_type=0&rMax=5000", + "enabled": true } }, "blacklist": [ - "swap", - "tausch", - "wg", "Vermietete", "Vermietet", "vermietete", diff --git a/lib/provider/wgGesucht.js b/lib/provider/wgGesucht.js new file mode 100755 index 0000000..7f8689b --- /dev/null +++ b/lib/provider/wgGesucht.js @@ -0,0 +1,33 @@ +const config = require('../../conf/config.json'); +const Fredy = require('../fredy'); +const utils = require('../utils'); + +function normalize(o) { + return o; +} + +function applyBlacklist(o) { + const titleNotBlacklisted = !utils.isOneOf(o.title, config.blacklist); + const descNotBlacklisted = !utils.isOneOf(o.description, config.blacklist); + + return titleNotBlacklisted && descNotBlacklisted; +} + +const wgGesucht = { + name: 'wgGesucht', + enabled: config.sources.wgGesucht.enabled, + url: config.sources.wgGesucht.url, + crawlContainer: '#main_column .panel:not(.display-none):not(.noprint)', + crawlFields: { + id: '@data-id', + details: '.detail-size-price-wrapper .detailansicht |removeNewline |trim', + title: '.headline .detailansicht |removeNewline |trim', + description: '.list-details-panel-inner p |removeNewline |trim', + link: '.headline .detailansicht@href' + }, + paginate: '.pagination-sm:first a:last@href', + normalize: normalize, + filter: applyBlacklist +}; + +module.exports = new Fredy(wgGesucht); diff --git a/test/wgGesucht.test.js b/test/wgGesucht.test.js new file mode 100644 index 0000000..499c707 --- /dev/null +++ b/test/wgGesucht.test.js @@ -0,0 +1,41 @@ +const mockNotification = require('./mocks/mockNotification'); +const mockConfig = require('../conf/config.test'); +const mockStore = require('./mocks/mockStore'); +const mockStats = require('./mocks/mockStats'); +const proxyquire = require('proxyquire').noCallThru(); +const expect = require('chai').expect; + +describe.only('#wgGesucht testsuite()', () => { + + const wgGesucht = proxyquire('../lib/provider/wgGesucht', { + '../../conf/config.json': mockConfig, + '../lib/fredy': proxyquire('../lib/fredy', { + './services/store': mockStore, + './notification/notify': mockNotification + }) + }); + + it.only('should test wgGesucht provider', async () => { + return await new Promise(resolve => { + wgGesucht.run(mockStats).then(() => { + const wgGesuchtDbContent = wgGesucht._getStore()._db; + expect(wgGesuchtDbContent.wgGesucht).to.be.a('array'); + const notificationObj = mockNotification.get(); + expect(notificationObj.serviceName).to.equal('wgGesucht'); + notificationObj.payload.forEach((notify, idx) => { + expect(notify).to.be.a('object'); + + /** check the actual structure **/ + + expect(notify.id).to.be.a('string'); + expect(notify.title).to.be.a('string'); + expect(notify.details).to.be.a('string'); + expect(notify.description).to.be.a('string'); + expect(notify.link).to.be.a('string'); + + }); + resolve(); + }); + }); + }); +});