def test_search_multiple_areas(self, mock_post): url = "https://search-gateway.dsch.ie/v1/listings" payload = { "section": "residential-to-rent", "geoFilter": { "storedShapeIds": ["2040", "2144", "2068"], "geoSearchType": "STORED_SHAPES" }, "paging": { "from": "0", "pagesize": "50" }, } headers = { "Content-Type": "application/json", "brand": "daft", "platform": "web", } daft = Daft() daft.set_search_type(SearchType.RESIDENTIAL_RENT) daft.set_location( [Location.ASHTOWN_DUBLIN, Location.IFSC_DUBLIN, "Blanchardstown"]) daft.search() mock_post.assert_called_with(url, headers=headers, json=payload)
def test_new_homes(self): daft = Daft() daft.set_search_type(SearchType.NEW_HOMES) daft.set_location(Location.DUBLIN) listings = daft.search(max_pages=1) self.assertTrue(len(listings) > 0) self.assertGreater(daft.total_results, 0)
def test_apartments_to_rent(self): daft = Daft() daft.set_search_type(SearchType.RESIDENTIAL_RENT) daft.set_property_type(PropertyType.APARTMENT) daft.set_location(Location.DUBLIN) listings = daft.search(max_pages=1) self.assertTrue(len(listings) > 0) self.assertGreater(daft.total_results, 0)
def test_studios_to_rent(self): daft = Daft() daft.set_search_type(SearchType.RESIDENTIAL_RENT) daft.set_property_type(PropertyType.STUDIO_APARTMENT) daft.set_location(Location.DUBLIN) listings = daft.search(max_pages=1) self.assertTrue(len(listings) > 0) self.assertTrue(listings[0].bedrooms == "1 bed") self.assertGreater(daft.total_results, 0)
def test_distance(self): daft = Daft() daft.set_location("Dublin City") daft.set_search_type(SearchType.RESIDENTIAL_RENT) daft.set_min_price(1) daft.set_max_price(100000) listings = daft.search(max_pages=1) first = listings[0] for l in listings[1:]: if (l.latitude, l.longitude) != (first.latitude, first.longitude): second = l break coord = [53.3429, -6.2674] self.assertGreater(first.distance_to(coord), 0) self.assertGreater(first.distance_to(second), 0)
async def get_daft_search_result(location=None, min_price=None, max_price=None): if(location is None): location = "Dublin City" if(min_price is None): min_price = 1000 if(max_price is None): max_price = 1800 daft = Daft() daft.set_location("Dublin City") daft.set_search_type(SearchType.RESIDENTIAL_RENT) daft.set_min_price(min_price) daft.set_max_price(max_price) daft.set_sort_type(SortType.PUBLISH_DATE_DESC) listings = daft.search() result_items = [] for listing in listings: searchItem = schemas.SearchResultItem( url=listing.daft_link, title=listing.title, monthly_price=listing.monthly_price, latitude=listing.latitude, longitude=listing.longitude, bedrooms=listing.bedrooms, bathrooms=listing.bathrooms, publish_date=listing.publish_date, category=listing.category, featured_level=listing.featured_level, sections=listing.sections, source_code=listing.shortcode, ) result_items.append(searchItem) result = schemas.SearchResultList( result_list=result_items, results_count=daft._total_results, search_rules=daft._make_payload() ) return result
from daftlistings import Daft, Location, SearchType, SuitableFor daft = Daft() daft.set_location(Location.DUBLIN) daft.set_search_type(SearchType.SHARING) daft.set_owner_occupied(True) daft.set_min_tenants(1) daft.set_max_tenants(1) daft.set_suitability(SuitableFor.MALE) daft.set_min_price(1000) daft.set_max_price(1000) listings = daft.search() for listing in listings: print(listing.title) print(listing.daft_link) print("")
from daftlistings import Daft, Location, SearchType daft = Daft() daft.set_location([Location.ASHTOWN_DUBLIN, Location.IFSC_DUBLIN]) daft.set_search_type(SearchType.RESIDENTIAL_RENT) listings = daft.search() for listing in listings: print(listing.title) print(listing.price) print(listing.daft_link) print()
def test_search_properties_for_sale(self, mock_post): url = "https://search-gateway.dsch.ie/v1/listings" payload = { "section": "residential-for-sale", "andFilters": [{ "name": "facilities", "values": [ "wired-for-cable-television", "alarm", "wheelchair-access", "gas-fired-central-heating", ], }], "ranges": [ { "name": "salePrice", "from": "250000", "to": "300000" }, { "name": "numBeds", "from": "3", "to": "3" }, { "name": "ber", "from": "0", "to": "0" }, { "name": "floorSize", "from": "1000", "to": "1000" }, { "name": "firstPublishDate", "from": "now-14d/d", "to": "" }, ], "geoFilter": { "storedShapeIds": ["3"], "geoSearchType": "STORED_SHAPES" }, "sort": "priceAsc", "paging": { "from": "0", "pagesize": "50" }, } headers = { "Content-Type": "application/json", "brand": "daft", "platform": "web", } daft = Daft() daft.set_search_type(SearchType.RESIDENTIAL_SALE) daft.set_location(Location.KILDARE) daft.set_location("Kildare") daft.set_sort_type(SortType.PRICE_ASC) daft.set_max_price(300000) daft.set_min_price(250000) daft.set_min_beds(3) daft.set_max_beds(3) daft.set_min_ber(Ber.A1) daft.set_max_ber(Ber.A1) daft.set_max_floor_size(1000) daft.set_min_floor_size(1000) daft.set_added_since(AddedSince.DAYS_14) daft.set_facility(Facility.WIRED_FOR_CABLE_TELEVISION) daft.set_facility(Facility.ALARM) daft.set_facility(Facility.WHEELCHAIR_ACCESS) daft.set_facility(Facility.CENTRAL_HEATING_GAS) daft.search() mock_post.assert_called_with(url, headers=headers, json=payload)
def test_any_to_rent(self): daft = Daft() daft.set_search_type(SearchType.RESIDENTIAL_RENT) daft.set_location(Location.DUBLIN) listings = daft.search(max_pages=1) self.assertTrue(len(listings) > 0)
def test_invalid_location_value_throws_type_error(self): with self.assertRaises(TypeError): daft = Daft() daft.set_search_type(SearchType.RESIDENTIAL_RENT) daft.set_location(1)
def test_search_properties_for_rent(self, mock_post): url = "https://search-gateway.dsch.ie/v1/listings" payload = { "section": "residential-to-rent", "andFilters": [{ "name": "facilities", "values": ["alarm", "parking", "cable-television"], }], "ranges": [ { "name": "rentalPrice", "from": "2000", "to": "2500" }, { "name": "numBeds", "from": "1", "to": "2" }, { "name": "ber", "from": "0", "to": "0" }, { "name": "floorSize", "from": "1000", "to": "1000" }, { "name": "firstPublishDate", "from": "now-14d/d", "to": "" }, ], "geoFilter": { "storedShapeIds": ["3"], "geoSearchType": "STORED_SHAPES" }, "sort": "priceDesc", "paging": { "from": "0", "pagesize": "50" }, } headers = { "Content-Type": "application/json", "brand": "daft", "platform": "web", } daft = Daft() daft.set_search_type(SearchType.RESIDENTIAL_RENT) daft.set_location(Location.KILDARE) daft.set_location("Kildare") daft.set_sort_type(SortType.PRICE_DESC) daft.set_max_price(2500) daft.set_min_price(2000) daft.set_min_beds(1) daft.set_max_beds(2) daft.set_min_ber(Ber.A1) daft.set_max_ber(Ber.A1) daft.set_max_floor_size(1000) daft.set_min_floor_size(1000) daft.set_added_since(AddedSince.DAYS_14) daft.set_facility(Facility.ALARM) daft.set_facility(Facility.PARKING) daft.set_facility(Facility.CABLE_TELEVISION) daft.search() mock_post.assert_called_with(url, headers=headers, json=payload)
from daftlistings import Daft, SearchType, SortType, Location daft = Daft() daft.set_search_type(SearchType.NEW_HOMES) daft.set_location(Location.GALWAY_CITY) daft.set_sort_type(SortType.PRICE_ASC) listings = daft.search() for listing in listings: print(listing.title) print(listing.price) print(listing.daft_link) print()
# Search properties according to criteria then sort by nearness to Dublin Castle from daftlistings import Daft, SearchType daft = Daft() daft.set_location("Dublin City") daft.set_search_type(SearchType.RESIDENTIAL_RENT) daft.set_min_price(1000) daft.set_max_price(1500) listings = daft.search(max_pages=1) dublin_castle_coords = [53.3429, -6.2674] listings.sort(key=lambda x: x.distance_to(dublin_castle_coords)) for listing in listings: print(f'{listing.title}') print(f'{listing.daft_link}') print(f'{listing.price}') print(f'{listing.distance_to(dublin_castle_coords):.3}km') print('')
from daftlistings import Daft, Location, SearchType daft = Daft() daft.set_location(Location.DUNDALK_INSTITUTE_OF_TECHNOLOGY_LOUTH) daft.set_search_type(SearchType.STUDENT_ACCOMMODATION) listings = daft.search() for listing in listings: print(listing.title) print(listing.price) print(listing.daft_link) print()