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_open_viewing(self): daft = Daft() daft.set_open_viewing(True) daft.set_listing_type(RentType.APARTMENTS) listings = daft.search() self.assertTrue(len(listings) > 0) for listing in daft.search(): self.assertTrue(len(listing.upcoming_viewings) > 0)
def test_apartments_to_let(self): daft = Daft() daft.set_offset(20) daft.set_listing_type(RentType.APARTMENTS) listings = daft.search(fetch_all=False) search_count = daft.search_count self.assertGreater(search_count, 0) self.assertGreater(len(listings), 0) apartment = listings[0] print(apartment.daft_link) self.assertIsNotNone(apartment.commercial_area_size) self.assertIsNotNone(apartment.contact_number) self.assertIsNotNone(apartment.daft_link) self.assertIsNotNone(apartment.date_insert_update) self.assertIsNotNone(apartment.facilities) self.assertIsNotNone(apartment.formalised_address) self.assertIsNotNone(apartment.id) self.assertIsNotNone(apartment.bathrooms) self.assertIsNotNone(apartment.bedrooms) self.assertIsNotNone(apartment.overviews) self.assertIsNotNone(apartment.price) self.assertIsNotNone(apartment.search_type) self.assertIsNotNone(apartment.shortcode) self.assertIsNotNone(apartment.views) self.assertIsNotNone(apartment.features) self.assertIsNotNone(apartment.advertiser_name) self.assertIsNotNone(apartment.date_insert_update) self.assertIsNotNone(apartment.hires_images)
def test_apartments_to_let(self): daft = Daft() daft.set_listing_type(RentType.APARTMENTS) daft.set_area_type(AreaType.ENROUTE) daft.set_public_transport_route(TransportRoute.BUS_LINE_15) daft.set_gender(Gender.MALE) listings = daft.search() self.assertTrue(len(listings) > 0) apartment = listings[0] self.assertIsNotNone(apartment.address_line_1) self.assertIsNotNone(apartment.agent_id) self.assertIsNotNone(apartment.commercial_area_size) self.assertIsNotNone(apartment.contact_number) self.assertIsNotNone(apartment.county) self.assertIsNotNone(apartment.daft_link) self.assertIsNotNone(apartment.date_insert_update) self.assertIsNotNone(apartment.dwelling_type) self.assertIsNotNone(apartment.facilities) self.assertIsNotNone(apartment.formalised_address) self.assertIsNotNone(apartment.id) self.assertIsNotNone(apartment.bathrooms) self.assertIsNotNone(apartment.bedrooms) self.assertIsNotNone(apartment.overviews) self.assertIsNotNone(apartment.price) self.assertIsNotNone(apartment.search_type) self.assertIsNotNone(apartment.shortcode) self.assertIsNotNone(apartment.views)
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 search_apts(): ''' Search Apts using the config file settings Returns ------- list (listings) ''' with open('config/search_config.json') as search_config_file: search_config = json.load(search_config_file) daft = Daft() daft.set_county(search_config['county']) daft.set_listing_type(RentType.APARTMENTS) daft.set_min_price(search_config['price']['min']) daft.set_max_price(search_config['price']['max']) listings = daft.search() # filter out seen results listings_seen = results.get_listings_seen_set() new_listings = [ listing for listing in listings if listing.daft_link not in listings_seen ] results.update_listings_seen(*listings) print(f"Found {len(new_listings)} new listings") return new_listings
def test_properties_sale_agreed_with_invalid_prices(self): daft = Daft() raised_exception = False daft.set_county("Dublin City") daft.set_area("Dublin 15") daft.set_listing_type(SaleType.PROPERTIES) daft.set_sale_agreed(True) try: daft.set_min_price("Two") daft.set_max_price("") daft.search() except: raised_exception = True self.assertTrue(raised_exception)
def test_properties(self): daft = Daft() daft.set_county("Dublin City") daft.set_area("Dublin 15") daft.set_added_since(14) daft.set_listing_type(SaleType.PROPERTIES) daft.set_property_type([PropertyType.HOUSE]) listings = daft.search(fetch_all=False) self.assertTrue(len(listings) > 0) first = listings[1] self.assertIsNotNone(first.agent_id) self.assertIsNotNone(first.commercial_area_size) self.assertIsNotNone(first.contact_number) self.assertIsNotNone(first.daft_link) self.assertIsNotNone(first.date_insert_update) self.assertIsNotNone(first.facilities) self.assertIsNotNone(first.formalised_address) self.assertIsNotNone(first.id) self.assertIsNotNone(first.bathrooms) self.assertIsNotNone(first.bedrooms) self.assertIsNotNone(first.overviews) self.assertIsNotNone(first.price) self.assertIsNotNone(first.search_type) self.assertIsNotNone(first.shortcode) self.assertIsNotNone(first.views) self.assertIsNotNone(first.features) self.assertIsNotNone(first.advertiser_name) self.assertIsNotNone(first.date_insert_update) self.assertIsNotNone(first.hires_images) self.assertIsNotNone(first.images)
def test_commercial_properties(self): daft = Daft() daft.set_county("Dublin") daft.set_listing_type(SaleType.COMMERCIAL) daft.set_commercial_min_size(100) daft.set_commercial_max_size(200) listings = daft.search() self.assertTrue(len(listings) > 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 userSearchCriteria(county, rent_type, min_amount, max_amount): daft = Daft() daft.set_county(county) daft.set_listing_type(RentType[rent_type]) daft.set_min_price(min_amount) daft.set_max_price(max_amount) print('running search ...') return daft.search()
def test_search_basic(self, mock_post): url = "https://search-gateway.dsch.ie/v1/listings" payload = { "paging": { "from": "0", "pagesize": "50" }, } headers = { "Content-Type": "application/json", "brand": "daft", "platform": "web", } daft = Daft() daft.search() mock_post.assert_called_with(url, headers=headers, json=payload)
def test_properties_with_negative_max(self): daft = Daft() daft.set_county("Dublin City") daft.set_area("Dublin 15") daft.set_max_price(-1000) daft.set_listing_type(SaleType.PROPERTIES) listings = daft.search() self.assertTrue(len(listings) == 0)
def test_student_accommodation(self): daft = Daft() daft.set_listing_type(RentType.STUDENT_ACCOMMODATION) daft.set_university(University.NCI) daft.set_student_accommodation_type( StudentAccommodationType.ROOMS_TO_SHARE) listings = daft.search(fetch_all=False) self.assertGreater(len(listings), 0)
def test_properties_sale_agreed(self): daft = Daft() daft.set_county("Dublin City") daft.set_area("Dublin 15") daft.set_listing_type(SaleType.PROPERTIES) daft.set_sale_agreed(True) listings = daft.search() self.assertTrue(len(listings) > 0)
def test_commercial_property_types(self): daft = Daft() daft.set_county("Dublin City") daft.set_listing_type(SaleType.COMMERCIAL) daft.set_commercial_property_type(CommercialType.OFFICE) listings = daft.search() self.assertTrue(len(listings) > 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_properties_with_max_beds(self): daft = Daft() daft.set_county('Dublin') daft.set_min_beds(3) daft.set_max_beds(3) listings = daft.search() self.assertTrue(len(listings) > 0) listing = listings[0] self.assertTrue(listing.bedrooms == 3)
def test_room_to_share(self): daft = Daft() daft.set_county('Dublin') daft.set_area('Castleknock') daft.set_listing_type(RentType.ROOMS_TO_SHARE) daft.set_furnished(True) daft.set_min_price(500) daft.set_max_price(1000) daft.set_room_type(RoomType.DOUBLE) listings = daft.search() self.assertTrue(len(listings) > 0)
def test_distance(self): daft = Daft() daft.set_county("Dublin City") daft.set_listing_type(RentType.APARTMENTS) daft.set_min_price(1) daft.set_max_price(100000) listings = daft.search(fetch_all=False) first, second = listings[0], listings[1] coord = [53.3429, -6.2674] self.assertGreater(first.distance_to(coord), 0) self.assertGreater(first.distance_to(second), 0)
def test_shared_listings(self, mock_post): url = "https://search-gateway.dsch.ie/v1/listings" payload = { "section": "sharing", "filters": [ { "name": "suitableFor", "values": ["male"] }, { "name": "ownerOccupied", "values": [True] }, ], "ranges": [{ "name": "numTenants", "from": "1", "to": "1" }], "paging": { "from": "0", "pagesize": "50" }, } headers = { "Content-Type": "application/json", "brand": "daft", "platform": "web", } daft = Daft() daft.set_search_type(SearchType.SHARING) daft.set_suitability(SuitableFor.MALE) daft.set_min_tenants(1) daft.set_max_tenants(1) daft.set_owner_occupied(True) daft.search() mock_post.assert_called_with(url, headers=headers, json=payload)
def test_student_accommodation(self): daft = Daft() daft.set_listing_type(RentType.STUDENT_ACCOMMODATION) daft.set_university(University.TCD) daft.set_student_accommodation_type( StudentAccommodationType.APARTMENTS) daft.set_min_price(800) daft.set_max_price(1500) daft.set_sort_by(SortType.PRICE) daft.set_sort_order(SortOrder.ASCENDING) listings = daft.search() self.assertTrue(len(listings) > 0)
def test_properties_with_price(self): daft = Daft() daft.set_county("Dublin City") daft.set_area("Dublin 15") daft.set_listing_type(SaleType.PROPERTIES) daft.set_min_price(200000) daft.set_max_price(250000) listings = daft.search(fetch_all=False) self.assertTrue(len(listings) > 0) listing = listings[0] price = listing.price self.assertTrue(200000 <= int(price) <= 250000)
def test_apartments_to_let_with_price(self): daft = Daft() daft.set_county("Dublin City") daft.set_area("Dublin 15") daft.set_listing_type(RentType.APARTMENTS) daft.set_min_price(1000) daft.set_max_price(2000) listings = daft.search(fetch_all=False) self.assertTrue(len(listings) > 0) listing = listings[0] price = listing.price self.assertTrue(1000 <= int(price) <= 2000)
def test_room_to_share(self): daft = Daft() daft.set_county("Dublin") daft.set_listing_type(RentType.ROOMS_TO_SHARE) daft.set_with_photos(True) daft.set_ensuite_only(True) daft.set_furnished(True) daft.set_num_occupants(2) daft.set_min_price(500) daft.set_max_price(1000) daft.set_room_type(RoomType.DOUBLE) listings = daft.search(fetch_all=False) self.assertTrue(len(listings) > 0)
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.search(fetch_all=False) listing = listings[0] price = listing.price self.assertTrue(len(listings) > 0) self.assertTrue(int(price) <= 175000)
def get_listings(): print('%s: Getting daft listings for %s' % (time.strftime("%Y/%m/%d-%H:%M:%S"), RENT_TYPE)) daft = Daft() # daft.set_county("Dublin City") daft.set_county(LOCATION) daft.set_listing_type(RENT_TYPE_MAP[RENT_TYPE]) # daft.set_min_price(0) # daft.set_max_price(900) # daft.set_address("Donnybrook") # daft.set_address("Ballsbridge") # daft.set_university(University.UCD) offset = 0 all_listings = [] listings = daft.search() all_listings.extend(listings) # while True: # daft.set_offset(offset) # listings = daft.search() # all_listings.extend(listings) # if not listings: # break # offset += 20 print(len(all_listings)) # except GeocoderQuotaExceeded: # geolocator = Nominatim(user_agent="specify_your_app_name_here") # ucd_location = geolocator.geocode("O'Brien Centre for Science, Dublin") # i = 0 # for listing in all_listings: # address = listing.formalised_address # print(i) # listing.location = fix_address(address) # if listing.location: # listing.latitude = listing.location.latitude # listing.longitude = listing.location.longitude # listing.distance_to_ucd = get_distance(ucd_location, listing.location) # else: # listing.latitude = None # listing.longitude = None # listing.distance_to_ucd = None # i += 1 return all_listings
def test_commercial_properties_with_price(self): daft = Daft() daft.set_county("Dublin") daft.set_listing_type(SaleType.COMMERCIAL) daft.set_commercial_property_type(CommercialType.OFFICE) daft.set_min_price(150000) listings = daft.search(fetch_all=False) self.assertTrue(len(listings) > 0) listing = listings[0] price = listing.price self.assertTrue(int(price) >= 150000)
def test_apartments_to_let(self): daft = Daft() daft.set_county("Dublin") daft.set_couples_accepted(True) daft.set_with_photos(True) daft.set_ensuite_only(True) daft.set_area_type(AreaType.TRANSPORT_ROUTE) daft.set_public_transport_route(TransportRoute.DART) daft.set_listing_type(RentType.APARTMENTS) daft.set_added_since(7) daft.set_gender(Gender.EITHER) listings = daft.search() self.assertTrue(len(listings) > 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)