Files
fredy/lib/provider/wohnungsboerse.js

78 lines
2.2 KiB
JavaScript
Raw Normal View History

2026-01-09 11:37:03 +01:00
/*
* Copyright (c) 2026 by Christian Kellner.
* Licensed under Apache-2.0 with Commons Clause and Attribution/Naming Clause
*/
import * as utils from '../utils.js';
import checkIfListingIsActive from '../services/listings/listingActiveTester.js';
import { extractNumber } from '../utils/extract-number.js';
/** @import { ParsedListing } from '../types/listing.js' */
/** @import { ProviderConfig } from '../types/providerConfig.js' */
2026-01-09 11:37:03 +01:00
let appliedBlackList = [];
/**
* @param {any} o
* @returns {ParsedListing}
*/
2026-01-09 11:37:03 +01:00
function normalize(o) {
const [city = '', part = ''] = (o.description || '').split('-').map((v) => v.trim());
const address = `${part}, ${city}`;
return {
2026-06-13 14:02:42 +02:00
id: o.link != null ? o.link.split('/').pop() : null,
link: o.link,
title: o.title || '',
price: extractNumber(o.price),
size: extractNumber(o.size),
rooms: extractNumber(o.rooms),
address,
image: o.image,
description: o.description,
};
2026-01-09 11:37:03 +01:00
}
/**
* @param {ParsedListing} o
* @returns {boolean}
*/
2026-01-09 11:37:03 +01:00
function applyBlacklist(o) {
const titleNotBlacklisted = !utils.isOneOf(o.title, appliedBlackList);
const descNotBlacklisted = !utils.isOneOf(o.description, appliedBlackList);
2026-06-13 14:02:42 +02:00
return o.id != null && o.title != null && o.link != null && titleNotBlacklisted && descNotBlacklisted;
2026-01-09 11:37:03 +01:00
}
/** @type {ProviderConfig} */
2026-01-09 11:37:03 +01:00
const config = {
2026-04-12 09:21:08 +02:00
requiredFieldNames: ['id', 'link', 'title', 'price', 'size', 'rooms', 'address', 'image', 'description'],
2026-01-09 11:37:03 +01:00
url: null,
sortByDateParam: null,
waitForSelector: 'body',
crawlContainer: '.search_result_container > a',
crawlFields: {
id: '*',
title: 'h3 | trim',
price: 'dl:nth-of-type(1) dd | removeNewline | trim',
rooms: 'dl:nth-of-type(2) dd | removeNewline | trim',
size: 'dl:nth-of-type(3) dd | removeNewline | trim',
description: 'div.before\\:icon-location_marker | trim',
link: '@href',
image: 'img@src',
2026-01-09 11:37:03 +01:00
},
normalize: normalize,
filter: applyBlacklist,
activeTester: checkIfListingIsActive,
2026-01-09 11:37:03 +01:00
};
export const init = (sourceConfig, blacklistTerms) => {
config.url = sourceConfig.url;
appliedBlackList = blacklistTerms || [];
};
export const metaInformation = {
name: 'Wohnungsboerse',
baseUrl: 'https://www.wohnungsboerse.net',
id: 'wohnungsboerse',
};
export { config };