{"size": 1675, "ext": "js", "max_stars_repo_path": "lib/provider/immoswp.js", "max_stars_repo_name": "tmbo/fredy", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lib/provider/immoswp.js", "max_issues_repo_name": "tmbo/fredy", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lib/provider/immoswp.js", "max_forks_repo_name": "tmbo/fredy", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 31.6037735849, "max_line_length": 86, "alphanum_fraction": 0.6841791045}
const utils = require('../utils');

let appliedBlackList = [];

function normalize(o) {
  const id = o.id.substring(o.id.indexOf('-') + 1, o.id.length);
  const size = o.size || 'N/A m²';
  const price = (o.price || '--- €').replace('Preis auf Anfrage', '--- €');
  const address = o.address || 'No address available';
  const title = o.title || 'No title available';
  const link = `https://immo.swp.de/immobilien/${id}`;
  const description = o.description;
  return Object.assign(o, { id, address, price, size, title, link, description });
}

function applyBlacklist(o) {
  const titleNotBlacklisted = !utils.isOneOf(o.title, appliedBlackList);
  const descNotBlacklisted = !utils.isOneOf(o.description, appliedBlackList);

  return titleNotBlacklisted && descNotBlacklisted;
}

const config = {
  url: null,
  crawlContainer: '.js-serp-item',
  sortByDateParam: 's=most_recently_updated_first',
  crawlFields: {
    id: '@id',
    price: 'div.item__spec.item-spec-price | trim',
    size: 'div.item__spec.item-spec-area | trim',
    title: 'a.js-item-title-link@title',
    address: 'div.item__locality | removeNewline | trim',
    description: 'div.item__main-info-points.clearfix p small | removeNewline | trim',
  },
  paginate: 'li.page-item.pagination__item a.page-link@href',
  normalize: normalize,
  filter: applyBlacklist,
};

exports.init = (sourceConfig, blacklist) => {
  config.enabled = sourceConfig.enabled;
  config.url = sourceConfig.url;
  appliedBlackList = blacklist || [];
};

exports.metaInformation = {
  name: 'Immo Südwest Presse',
  baseUrl: 'https://immo.swp.de/',
  id: __filename.slice(__dirname.length + 1, -3),
};

exports.config = config;
