diff --git a/README.md b/README.md index 940ecb1..3877ff8 100755 --- a/README.md +++ b/README.md @@ -43,7 +43,9 @@ Adding new notification adapter is easy however. See [Contribution](https://gith Configure the providers like described below. To disable a provider just remove its entry from the configuration or set it to `false`. -#### Ebay Kleinanzeigen, Immoscout, Immowelt, Immonet and Kalaydo +#### Immoscout, Immonet and more + +These are the current provider that are already implemented within _Fredy_ ```json "kleinanzeigen": { @@ -66,6 +68,10 @@ Configure the providers like described below. To disable a provider just remove "url": "http://www.kalaydo.de/...", "enabled": true }, +"einsAImmobilien": { + "url": "https://www.1a-immobilienmarkt.de/...", + "enabled": true +} ``` Go to the respective provider page and create your custom search queries by diff --git a/conf/config.example b/conf/config.example index 1910792..0e86c9d 100755 --- a/conf/config.example +++ b/conf/config.example @@ -32,6 +32,10 @@ "kalaydo": { "url": "https://www.kalaydo.de/...", "enabled": true + }, + "einsAImmobilien":{ + "url": "https://www.1a-immobilienmarkt.de/...", + "enabled": true } }, "blacklist": [ diff --git a/conf/config.test.json b/conf/config.test.json index 37e1a77..f283397 100755 --- a/conf/config.test.json +++ b/conf/config.test.json @@ -32,6 +32,10 @@ "kalaydo": { "url": "https://www.kalaydo.de/immobilien/eigentumswohnung-kaufen/o/duesseldorf/4/", "enabled": true + }, + "einsAImmobilien":{ + "url": "https://www.1a-immobilienmarkt.de/suchen/duesseldorf/wohnung-kaufen.html?search=yes&cfid=98b39c7e-b403-4764-8f3c-57bf590923d0&data_hash=fcfa4ee1e6cfaf791051a6f342eec1f8&sort_type=newest", + "enabled": true } }, "blacklist": [ diff --git a/index.js b/index.js index b9f3d8f..15bd726 100755 --- a/index.js +++ b/index.js @@ -1,8 +1,7 @@ -require('rootpath')(); const fs = require('fs'); const path = './lib/provider'; const sources = fs.readdirSync(path); -const config = require('conf/config.json'); +const config = require('./conf/config.json'); const stats = require('./lib/services/stats'); setInterval( diff --git a/lib/provider/einsAImmobilien.js b/lib/provider/einsAImmobilien.js new file mode 100755 index 0000000..4d05978 --- /dev/null +++ b/lib/provider/einsAImmobilien.js @@ -0,0 +1,37 @@ +const config = require('../../conf/config.json'); +const Fredy = require('../fredy'); +const utils = require('../utils'); + +function normalize(o) { + const size = `${o.size.replace(' Wohnfläche ', '').trim()} / ${o.rooms.trim()}`; + const link = `https://www.1a-immobilienmarkt.de/expose/13691814${o.id}.html` + + return Object.assign(o, { size, link }); +} + +function applyBlacklist(o) { + const titleNotBlacklisted = !utils.isOneOf(o.title, config.blacklist); + const descNotBlacklisted = !utils.isOneOf(o.description, config.blacklist); + + return titleNotBlacklisted && descNotBlacklisted; +} + +const einsAImmobilien = { + name: 'einsAImmobilien', + enabled: config.sources.einsAImmobilien.enabled, + url: config.sources.einsAImmobilien.url, + crawlContainer: '.tabelle', + crawlFields: { + id: '.inner_object_data input[name="marker_objekt_id"]@value | int', + price: '.tabelle .inner_object_data .single_data_price | removeNewline | trim', + size: '.tabelle .inner_object_data .data_boxes div:nth-child(1)', + rooms: '.tabelle .inner_object_data .data_boxes div:nth-child(2)', + title: '.tabelle .inner_object_data .tabelle_inhalt_titel_black | removeNewline | trim', + description: '.tabelle .inner_object_data .objekt_beschreibung | removeNewline | trim' + }, + paginate: '.pagination_blocks div:last a@href', + normalize: normalize, + filter: applyBlacklist +}; + +module.exports = new Fredy(einsAImmobilien); \ No newline at end of file diff --git a/package.json b/package.json index a126201..4413202 100755 --- a/package.json +++ b/package.json @@ -32,7 +32,6 @@ "lowdb": "^1.0.0", "mocha": "^4.1.0", "request-x-ray": "^0.1.4", - "rootpath": "^0.1.2", "slack": "^10.0.0", "x-ray": "^2.3.2" }, diff --git a/test/einsAImmobilien.test.js b/test/einsAImmobilien.test.js new file mode 100644 index 0000000..a8fd1c1 --- /dev/null +++ b/test/einsAImmobilien.test.js @@ -0,0 +1,49 @@ +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('#einsAImmobilien testsuite()', () => { + + const einsAImmobilien = proxyquire('../lib/provider/einsAImmobilien', { + '../../conf/config.json': mockConfig, + '../lib/fredy': proxyquire('../lib/fredy', { + './services/store': mockStore, + './notification/notify': mockNotification + }) + }); + + it('should test einsAImmobilien provider', async () => { + return await new Promise(resolve => { + einsAImmobilien.run(mockStats).then(() => { + const immonetDbContent = einsAImmobilien._getStore()._db; + + expect(immonetDbContent.einsAImmobilien).to.be.a('array'); + + // const notificationObj = mockNotification.get(); + // expect(notificationObj).to.be.a('object'); + // expect(notificationObj.serviceName).to.equal('einsAImmobilien'); + // + // /** check the actual structure **/ + // expect(notificationObj.payload.id).to.be.a('number'); + // expect(notificationObj.payload.price).to.be.a('string'); + // expect(notificationObj.payload.size).to.be.a('string'); + // expect(notificationObj.payload.title).to.be.a('string'); + // expect(notificationObj.payload.link).to.be.a('string'); + // expect(notificationObj.payload.address).to.be.a('string'); + // + // /** check the values if possible **/ + // expect(notificationObj.payload.id).to.equal(immonetDbContent.immonet[immonetDbContent.immonet.length - 1]); + // expect(notificationObj.payload.price).that.does.include('€'); + // expect(notificationObj.payload.size).that.does.include('m²'); + // expect(notificationObj.payload.title).to.be.not.empty; + // expect(notificationObj.payload.link).that.does.include('https://www.immonet.de'); + // expect(notificationObj.payload.address).to.be.not.empty; + + resolve(); + }); + }); + }); +});