def test_sort_by_date_ascending(self): daft = Daft() daft.set_county("Dublin City") daft.set_area("Dublin 15") daft.set_listing_type(SaleType.PROPERTIES) daft.set_sort_order(SortOrder.ASCENDING) daft.set_sort_by(SortType.DATE) daft.set_min_price(150000) daft.set_max_price(175000) listings = daft.get_listings() self.assertTrue(len(listings) > 0) first = listings[0].get_posted_since().split() last = listings[-1].get_posted_since().split() first_date = time.strptime(first[0], "%d/%m/%Y") last_date = time.strptime(last[0], "%d/%m/%Y") self.assertTrue(first_date < last_date)
def test_sort_by_price(self): daft = Daft() daft.set_county("Dublin City") daft.set_area("Dublin 15") daft.set_listing_type(SaleType.PROPERTIES) daft.set_min_price(150000) daft.set_max_price(175000) daft.set_sort_by(SortType.PRICE) listings = daft.get_listings() listing = listings[0] price = listing.get_price() if "AMV" in price: price = price[6:] else: price = price[1:] print price price = price.replace(',', '') self.assertTrue(len(listings) > 0) self.assertTrue(int(price) <= 175000)
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("")
# Get the current sale agreed prices for properties in Dublin 15 that are between 200,000 and 250,000. from daftlistings import Daft, SaleType daft = Daft() daft.set_county("Dublin City") daft.set_area("Dublin 15") daft.set_listing_type(SaleType.PROPERTIES) daft.set_sale_agreed(True) daft.set_min_price(200000) daft.set_max_price(250000) listings = daft.get_listings() for listing in listings: print(listing.get_formalised_address()) print(listing.get_daft_link()) facilities = listing.get_facilities() if facilities is not None: print('Facilities: ') for facility in facilities: print(facility) features = listing.get_features() if features is not None: print('Features: ') for feature in features: print(feature)
# Find student accommodation near National College of Ireland that is between 500 and 700 per month # and provides internet facilities. from daftlistings import Daft, SortOrder, SortType, RentType, University, StudentAccommodationType offset = 0 while True: daft = Daft() daft.set_listing_type(RentType.STUDENT_ACCOMMODATION) daft.set_university(University.NCI) daft.set_student_accommodation_type( StudentAccommodationType.ROOMS_TO_SHARE) daft.set_min_price(800) daft.set_max_price(1000) daft.set_sort_by(SortType.PRICE) daft.set_sort_order(SortOrder.ASCENDING) daft.set_offset(offset) listings = daft.search() if len(listings) == 0: break for listing in listings: facilities = listing.facilities if facilities is not None: if "Internet" in facilities: for facility in facilities: print(facility) print(listing.price) print(listing.formalised_address)
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_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)
# You can sort the listings by price, distance, upcoming viewing or date using the SortType object. # The SortOrder object allows you to sort the listings descending or ascending. from daftlistings import Daft, SortOrder, SortType, RentType daft = Daft() daft.set_county("Dublin City") daft.set_listing_type(RentType.FLAT) daft.set_sort_order(SortOrder.ASCENDING) daft.set_sort_by(SortType.PRICE) daft.set_min_price(500) daft.set_max_price(1200) listings = daft.get_listings() for listing in listings: print(listing.get_formalised_address()) print(listing.get_daft_link()) print(listing.get_price()) facilities = listing.get_facilities() if facilities is not None: print('Facilities: ') for facility in facilities: print(facility) features = listing.get_features() if features is not None: print('Features: ')
from daftlistings import Daft, Location, SearchType, PropertyType daft = Daft() daft.set_location(Location.DUBLIN) daft.set_search_type(SearchType.RESIDENTIAL_SALE) daft.set_property_type(PropertyType.HOUSE) daft.set_min_price(400000) daft.set_max_price(500000) listings = daft.search() for listing in listings: print(listing.title) print(listing.price) print(listing.daft_link) print()