|
| 1 | +import { load } from 'cheerio'; |
| 2 | + |
| 3 | +import type { Data, DataItem, Route } from '@/types'; |
| 4 | +import { getSubPath } from '@/utils/common-utils'; |
| 5 | +import ofetch from '@/utils/ofetch'; |
| 6 | + |
| 7 | +const FEED_TITLE = 'Immobilien - BWSG' as const; |
| 8 | +const FEED_LANGUAGE = 'de' as const; |
| 9 | +const FEED_LOGO = 'https://www.bwsg.at/wp-content/uploads/2024/06/favicon-bwsg.png'; |
| 10 | +const SITE_URL = 'https://www.bwsg.at' as const; |
| 11 | +const BASE_URL = `${SITE_URL}/immobilien/immobilie-suchen/`; |
| 12 | + |
| 13 | +export const route: Route = { |
| 14 | + name: 'Angebote', |
| 15 | + example: '/bwsg/_vermarktungsart=miete&_objektart=wohnung&_zimmer=2,3&_wohnflaeche=45,70&_plz=1210,1220', |
| 16 | + path: '*', |
| 17 | + maintainers: ['sk22'], |
| 18 | + categories: ['other'], |
| 19 | + description: ` |
| 20 | +Copy the query parameters for your https://www.bwsg.at/immobilien/immobilie-suchen |
| 21 | +search, omitting the leading \`?\` |
| 22 | +
|
| 23 | +::: tip |
| 24 | +Since there's no parameter available that sorts by "last added" (and there's no |
| 25 | +obvious pattern to the default ordering), and since this RSS feed only fetches |
| 26 | +the first page of results, you probably want to specify enough search |
| 27 | +parameters to make sure you only get one page of results – because else, your |
| 28 | +RSS feed might not get all items. |
| 29 | +:::`, |
| 30 | + |
| 31 | + async handler(ctx) { |
| 32 | + let params = getSubPath(ctx).slice(1); |
| 33 | + if (params.startsWith('&')) { |
| 34 | + params = params.slice(1); |
| 35 | + } |
| 36 | + |
| 37 | + const link = `${BASE_URL}?${params}`; |
| 38 | + const response = await ofetch(link); |
| 39 | + const $ = load(response); |
| 40 | + |
| 41 | + const items = $('[data-objektnummer] > a') |
| 42 | + .toArray() |
| 43 | + .map((el) => { |
| 44 | + const $el = $(el); |
| 45 | + const link = el.attribs.href; |
| 46 | + const image = $el.find('.res_immobiliensuche__immobilien__item__thumb > img').attr('src'); |
| 47 | + const title = $el.find('.res_immobiliensuche__immobilien__item__content__title').text().trim(); |
| 48 | + const location = $el.find('.res_immobiliensuche__immobilien__item__content__meta__location').text().trim(); |
| 49 | + const price = $el.find('.res_immobiliensuche__immobilien__item__content__meta__preis').text().trim(); |
| 50 | + const metadata = $el.find('.res_immobiliensuche__immobilien__item__content__meta__row_1').text().trim(); |
| 51 | + |
| 52 | + return { |
| 53 | + title: `${location}, ${title}`, |
| 54 | + description: (price ? `${price} | ` : '') + metadata, |
| 55 | + link, |
| 56 | + image, |
| 57 | + // no pubDate :( |
| 58 | + } satisfies DataItem; |
| 59 | + }); |
| 60 | + |
| 61 | + return { |
| 62 | + title: FEED_TITLE, |
| 63 | + language: FEED_LANGUAGE, |
| 64 | + logo: FEED_LOGO, |
| 65 | + allowEmpty: true, |
| 66 | + item: items, |
| 67 | + link, |
| 68 | + } satisfies Data; |
| 69 | + }, |
| 70 | +}; |
0 commit comments