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_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_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_properties(self): daft = Daft() daft.set_county("Dublin City") daft.set_area("Dublin 15") daft.set_listing_type(SaleType.PROPERTIES) listings = daft.get_listings() self.assertTrue(len(listings) > 0)
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_area_commercial_properties(self): daft = Daft() daft.set_county("Dublin City") daft.set_area("Dublin 15") daft.set_listing_type(SaleType.COMMERCIAL) listings = daft.get_listings() 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_apartments_to_let(self): daft = Daft() daft.set_county("Dublin City") daft.set_area("Dublin 15") daft.set_listing_type(RentType.APARTMENTS) listings = daft.get_listings() self.assertTrue(len(listings) > 0)
def test_open_viewing(self): daft = Daft() daft.set_open_viewing(True) daft.set_listing_type(RentType.APARTMENTS) listings = daft.search(fetch_all=False) self.assertTrue(len(listings) > 0) for listing in listings: self.assertTrue(len(listing.upcoming_viewings) > 0)
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_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 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_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_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_listing_type_exception(self): daft = Daft() daft.set_county("Meath") has_raised_exception = False try: daft.set_listing_type("flat") except Exception: has_raised_exception = True self.assertTrue(has_raised_exception)
def test_open_viewing(self): daft = Daft() daft.set_county("Dublin") daft.set_open_viewing(True) daft.set_min_price(1000) daft.set_max_price(1500) daft.set_listing_type(RentType.APARTMENTS) listings = daft.get_listings() self.assertTrue(len(listings) > 0) for listing in daft.get_listings(): self.assertTrue(len(listing.get_upcoming_viewings()) > 0)
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_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 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.get_listings() self.assertTrue(len(listings) > 0) listing = listings[0] price = listing.get_price() price = price[1:] price = price.replace(',', '') self.assertTrue(200000 <= int(price) <= 250000)
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_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_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 initialize_daft_api_client(): daft_client = Daft() daft_client.set_county(config.COUNTY) daft_client.set_listing_type(config.LISTING_TYPE) daft_client.set_min_price(config.MIN_PRICE) daft_client.set_max_price(config.MAX_PRICE) daft_client.set_with_photos(config.WITH_PHOTOS) daft_client.set_added_since(config.ADDED_SINCE) daft_client.set_area(config.AREAS) daft_client.set_sort_order(config.SORT_ORDER) daft_client.set_sort_by(config.SORT_BY) daft_client.set_furnished(config.FURNISHED) daft_client.set_min_beds(config.MIN_BEDS) daft_client.set_min_lease(config.MIN_LEASE) return daft_client
def test_contact_advertiser(self): daft = Daft() daft.set_county("Meath") daft.set_listing_type(RentType.FLAT) listings = daft.search(fetch_all=False) if len(listings) > 0: first_listing = listings[0] has_sent = first_listing.contact_advertiser( name="Jane Doe", contact_number="019202222", email="*****@*****.**", message= "Hi, I seen your listing on daft.ie and I would like to schedule a viewing.", ) self.assertTrue(has_sent)
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)