mirror of
https://github.com/orangecoding/fredy.git
synced 2026-06-16 12:31:07 +00:00
Add provider for Regionalimmobilien24 (#197)
This commit is contained in:
committed by
GitHub
parent
7589f20a18
commit
4d37e890ab
49
lib/provider/regionalimmobilien24.js
Executable file
49
lib/provider/regionalimmobilien24.js
Executable file
@@ -0,0 +1,49 @@
|
|||||||
|
import { isOneOf, buildHash } from '../utils.js';
|
||||||
|
import checkIfListingIsActive from '../services/listings/listingActiveTester.js';
|
||||||
|
let appliedBlackList = [];
|
||||||
|
|
||||||
|
function normalize(o) {
|
||||||
|
const id = buildHash(o.id, o.price);
|
||||||
|
const address = o.address?.replace(/^adresse /i, '') ?? null;
|
||||||
|
const title = o.title || 'No title available';
|
||||||
|
const link = o.link != null ? decodeURIComponent(o.link) : config.url;
|
||||||
|
|
||||||
|
var urlReg = new RegExp(/url\((.*?)\)/gim);
|
||||||
|
const image = o.image != null ? urlReg.exec(o.image)[1] : null;
|
||||||
|
return Object.assign(o, { id, address, title, link, image });
|
||||||
|
}
|
||||||
|
function applyBlacklist(o) {
|
||||||
|
const titleNotBlacklisted = !isOneOf(o.title, appliedBlackList);
|
||||||
|
const descNotBlacklisted = !isOneOf(o.description, appliedBlackList);
|
||||||
|
return titleNotBlacklisted && descNotBlacklisted;
|
||||||
|
}
|
||||||
|
const config = {
|
||||||
|
url: null,
|
||||||
|
crawlContainer: '.listentry-content',
|
||||||
|
sortByDateParam: null, // sort by date is standard
|
||||||
|
waitForSelector: 'body',
|
||||||
|
crawlFields: {
|
||||||
|
id: '.listentry-iconbar-share@data-sid | trim',
|
||||||
|
title: 'h2 | trim',
|
||||||
|
price: '.listentry-details-price .listentry-details-v | trim',
|
||||||
|
size: '.listentry-details-size .listentry-details-v | trim',
|
||||||
|
address: '.listentry-adress | trim',
|
||||||
|
image: '.listentry-img@style',
|
||||||
|
link: '.shariff@data-url',
|
||||||
|
description: '.listentry-extras | trim',
|
||||||
|
},
|
||||||
|
normalize: normalize,
|
||||||
|
filter: applyBlacklist,
|
||||||
|
activeTester: checkIfListingIsActive,
|
||||||
|
};
|
||||||
|
export const init = (sourceConfig, blacklist) => {
|
||||||
|
config.enabled = sourceConfig.enabled;
|
||||||
|
config.url = sourceConfig.url;
|
||||||
|
appliedBlackList = blacklist || [];
|
||||||
|
};
|
||||||
|
export const metaInformation = {
|
||||||
|
name: 'Regionalimmobilien24',
|
||||||
|
baseUrl: 'https://www.regionalimmobilien24.de/',
|
||||||
|
id: 'regionalimmobilien24',
|
||||||
|
};
|
||||||
|
export { config };
|
||||||
43
test/provider/regionalimmobilien24.test.js
Normal file
43
test/provider/regionalimmobilien24.test.js
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import * as similarityCache from '../../lib/services/similarity-check/similarityCache.js';
|
||||||
|
import { get } from '../mocks/mockNotification.js';
|
||||||
|
import { mockFredy, providerConfig } from '../utils.js';
|
||||||
|
import { expect } from 'chai';
|
||||||
|
import * as provider from '../../lib/provider/regionalimmobilien24.js';
|
||||||
|
|
||||||
|
describe('#regionalimmobilien24 testsuite()', () => {
|
||||||
|
after(() => {
|
||||||
|
similarityCache.stopCacheCleanup();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should test regionalimmobilien24 provider', async () => {
|
||||||
|
const Fredy = await mockFredy();
|
||||||
|
provider.init(providerConfig.regionalimmobilien24, []);
|
||||||
|
|
||||||
|
const fredy = new Fredy(
|
||||||
|
provider.config,
|
||||||
|
null,
|
||||||
|
provider.metaInformation.id,
|
||||||
|
'regionalimmobilien24',
|
||||||
|
similarityCache,
|
||||||
|
);
|
||||||
|
const listing = await fredy.execute();
|
||||||
|
|
||||||
|
expect(listing).to.be.a('array');
|
||||||
|
const notificationObj = get();
|
||||||
|
expect(notificationObj).to.be.a('object');
|
||||||
|
expect(notificationObj.serviceName).to.equal('regionalimmobilien24');
|
||||||
|
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.size).that.does.include('m²');
|
||||||
|
expect(notify.title).to.be.not.empty;
|
||||||
|
expect(notify.address).to.be.not.empty;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -32,6 +32,10 @@
|
|||||||
"url": "https://www.neubaukompass.de/neubau-immobilien/duesseldorf-region/eigentumswohnung/",
|
"url": "https://www.neubaukompass.de/neubau-immobilien/duesseldorf-region/eigentumswohnung/",
|
||||||
"enabled": true
|
"enabled": true
|
||||||
},
|
},
|
||||||
|
"regionalimmobilien24": {
|
||||||
|
"url": "https://www.regionalimmobilien24.de/rostock/rostock/kaufen/haus/-/-/-/?rd=5",
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
"sparkasse": {
|
"sparkasse": {
|
||||||
"url": "https://immobilien.sparkasse.de/immobilien/treffer?marketingType=buy&objectType=flat&perimeter=10&usageType=residential&zipCityEstateId=62782__Hamburg",
|
"url": "https://immobilien.sparkasse.de/immobilien/treffer?marketingType=buy&objectType=flat&perimeter=10&usageType=residential&zipCityEstateId=62782__Hamburg",
|
||||||
"enabled": true
|
"enabled": true
|
||||||
|
|||||||
Reference in New Issue
Block a user