alessandroamella / ezaffitto

0 stars 0 forks source link

Aggiungi casa.it #80

Open alessandroamella opened 9 months ago

alessandroamella commented 9 months ago

URL:

curl 'https://www.casa.it/portal-srp/api/v1/search' \
  -H 'authority: www.casa.it' \
  -H 'accept: application/json' \
  -H 'accept-language: en-GB,en;q=0.9,it-IT;q=0.8,it;q=0.7,en-US;q=0.6' \
  -H 'content-type: application/json' \
  -H 'cookie: pa_privacy=%22optin%22; pdfcc=1; utag_main__sn=1; utag_main_ses_id=1701261055705%3Bexp-session; utag_main__pn=1%3Bexp-session; _pprv=eyJjb25zZW50Ijp7IjAiOnsibW9kZSI6Im9wdC1pbiJ9LCIxIjp7Im1vZGUiOiJvcHQtaW4ifSwiMiI6eyJtb2RlIjoib3B0LWluIn0sIjMiOnsibW9kZSI6Im9wdC1pbiJ9LCI0Ijp7Im1vZGUiOiJvcHQtaW4ifSwiNSI6eyJtb2RlIjoib3B0LWluIn0sIjYiOnsibW9kZSI6Im9wdC1pbiJ9LCI3Ijp7Im1vZGUiOiJvcHQtaW4ifX0sInB1cnBvc2VzIjpudWxsLCJfdCI6Im01ODV1NWZ5fGxwanF3bzN5In0%3D; didomi_token=eyJ1c2VyX2lkIjoiMThjMWIwZjktNzA2Ni02ZjMzLThiMzAtNTFmN2QxYjRiNTYwIiwiY3JlYXRlZCI6IjIwMjMtMTEtMjlUMTI6MzA6NTUuODUzWiIsInVwZGF0ZWQiOiIyMDIzLTExLTI5VDEyOjMxOjAyLjI3NFoiLCJ2ZW5kb3JzIjp7ImRpc2FibGVkIjpbImdvb2dsZSIsImM6Z29vZ2xlYW5hLTRUWG5KaWdSIl19LCJwdXJwb3NlcyI6eyJkaXNhYmxlZCI6WyJnZW9sb2NhdGlvbl9kYXRhIl19LCJ2ZXJzaW9uIjoyLCJhYyI6IkFBQUEuQUFBQSJ9; euconsent-v2=CP2APYAP2APYAAHABBENAcEgAAAAAAAAABCYAAAAAADDoAMAARBqLQAYAAiDUSgAwABEGopABgACINRCADAAEQagkAGAAIg1AAAA.YAAAAAAAAAAA; utag_main__se=2%3Bexp-session; utag_main__ss=0%3Bexp-session; utag_main__st=1701262862499%3Bexp-session; utag_main__prevTrackView=portal>listing>resultList>viewResults%3Bexp-1701264662503; g_state={"i_p":1701268265375,"i_l":1}; datadome=dxnpNf5pBI_OsGFp_EYJC2TInsbBqiBp47vi8PygmbGlHoEguGWnZE2ZbEl334uSMBTyisi25tHkkeJY9CBucyP7nZJSUctjjTdTUBwvfBMIcQuiN62Q0M2BD8Zh2xAW' \
  -H 'origin: https://www.casa.it' \
  -H 'referer: https://www.casa.it/affitto/stanze/bologna/' \
  -H 'sec-ch-ua: "Google Chrome";v="119", "Chromium";v="119", "Not?A_Brand";v="24"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "Linux"' \
  -H 'sec-fetch-dest: empty' \
  -H 'sec-fetch-mode: cors' \
  -H 'sec-fetch-site: same-origin' \
  -H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36' \
  --data-raw '{"apireq":{"site":"it_casa","page":1,"size":20,"sort":["inserted|desc"],"fgroup":"all","query":[{"where":[{"seo":{"l9":{"adm":"bologna"}}}],"filters":{"transaction.type":"affitti","category":"stanze","property_type_group":"stanze","sort":"date_desc"},"modifiers":{"with_surroundings":false,"with_filters":false,"with_georeach":true,"with_breadcrumb":true,"with_poi":false,"autoexpand_location_polygon":true},"seo":["v2.feature","v2.seller","v2.metroline"]}]},"queryFilters":{"page":1,"sortType":"date_desc","tr":"affitti","category":"stanze","propertyTypeGroup":"stanze"},"domain":"casa.it","locale":"it","uri":"/affitto/stanze/bologna?sortType=date_desc","publisherHP":false}' \
  --compressed

Funzione per mappare by Bing:

// La funzione prende in input un array di oggetti JSON e restituisce un nuovo array di oggetti JSON con la struttura richiesta
function mapObjects(list) {
  // Creo un nuovo array vuoto
  let result = [];
  // Itero su ogni elemento dell'array di input
  for (let item of list) {
    // Creo un nuovo oggetto JSON con le proprietà richieste
    let mappedItem = {
      "isRental": item.channel === "affitto",
      "isForRent": item.category === "stanze",
      "rentalType": item.propertyType === "stanza" ? "singleRoom" : "other",
      "monthlyPrice": Number(item.features.price.value),
      "securityDepositMonths": null, // Non deducibile dal testo
      "zone": item.geoInfos.district_name,
      "sexRestrictions": "everyone", // Non specificato
      "occupationalRestrictions": "everyone", // Non specificato
      "lgbtFriendly": false, // Non specificato
      "furnished": null, // Non specificato
      "availabilityStartDate": null, // Non specificato
      "availabilityEndDate": null, // Non specificato
      "contractDurationMonths": null, // Non specificato
      "hasBalcony": null, // Non specificato
      "hasParking": item.features.parkingOffer.available,
      "address": item.geoInfos.street + ", " + item.geoInfos.city,
      "floorNumber": Number(item.features.level.split("°")[0]),
      "rooms": Number(item.features.rooms),
      "bathrooms": Number(item.features.bathrooms),
      "areaSqMeters": Number(item.features.mq),
      "priceIncludesTaxes": null, // Non specificato
      "smokingAllowed": null, // Non specificato
      "hasAirConditioning": null, // Non specificato
      "hasHeating": null, // Non specificato
      "hasElevator": null // Non specificato
    };
    // Aggiungo il nuovo oggetto all'array di risultato
    result.push(mappedItem);
  }
  // Restituisco l'array di risultato
  return result;
}