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_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_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_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_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_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_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_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 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_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)
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_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() listing = listings[0] price = listing.price price = price.split() price = price[len(price) - 1] price = price[1:] price = price.replace(',', '') self.assertTrue(len(listings) > 0) self.assertTrue(int(price) <= 175000)
def test_properties_sale_agreed_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) daft.set_sale_agreed(True) listings = daft.search() self.assertTrue(len(listings) > 0) listing = listings[0] price = listing.price price = price[1:] price = price.replace(',', '') self.assertTrue(200000 <= int(price) <= 250000) self.assertTrue('Dublin 15' in listing.formalised_address)
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() self.assertTrue(len(listings) > 0) listing = listings[0] price = listing.price price = price[1:] price = price.replace(',', '') if 'week' or 'month' in price: price = price.split() price = price[0] self.assertTrue(1000 <= int(price) <= 2000)
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
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.search() self.assertTrue(len(listings) > 0) first = listings[0].posted_since.split() last = listings[-1].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)
# 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, SortOrder, SortType, RentType, MapVisualization import pandas as pd daft = Daft() daft.set_county("Dublin City") daft.set_listing_type(RentType.ANY) daft.set_sort_order(SortOrder.ASCENDING) daft.set_sort_by(SortType.PRICE) # must sort by price in asending order, MapVisualization class will take care of the weekly/monthly value mess daft.set_max_price(2400) daft.set_min_beds(2) daft.set_max_beds(2) listings = daft.search() properties = [] print( "Translating {} listing object into json, it will take a few minutes".format( str(len(listings)) ) ) print("Igonre the error message") for listing in listings: try: if listing.search_type != "rental": continue properties.append(listing.as_dict_for_mapping()) except: continue df = pd.DataFrame(properties)
f.close() except: print( "[W] Unable to read cache file. Don't worry if you start from scretch." ) # search listings on daft print("[*] Reading Daft.") listings = [] offset = 0 daft = Daft() try: daft.set_county(config["rent_county"]) daft.set_area(config["rent_area"]) daft.set_listing_type(RentType.ANY) daft.set_max_price(config["rent_max_price"]) daft.set_min_beds(config["rent_min_bedroom"]) daft.set_max_beds(config["rent_max_bedroom"]) except: print("[E] Configuration is broken.") sys.exit(-1) while True: l = daft.search() if len(l) == 0: break for listing in l: if listing.daft_link in cached: continue listings.append(listing) cached[listing.daft_link] = '' offset += 20
# Get the current properties for rent in Dublin that are between 1000 and 1500 per month. from daftlistings import Daft, RentType daft = Daft() daft.set_county("Dublin City") daft.set_listing_type(RentType.APARTMENTS) daft.set_min_price(1000) daft.set_max_price(1500) listings = daft.get_listings() for listing in listings: print(listing.get_formalised_address()) print(listing.get_daft_link()) print(listing.get_price()) print(listing.get_contact_number()) print(listing.get_views()) 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)
# 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)
# Prepare a cursor object using cursor() method cursor = db.cursor() # Configure Daft.ie research today = date.today() area_array = [ "Galway City Centre", "Galway City Suburbs", "Galway Commuter Towns" ] for x in area_array: daft = Daft() daft.set_area(x) daft.set_county("Galway City") daft.set_listing_type(SaleType.HOUSES) daft.set_min_beds(3) daft.set_max_price(300000) print("## Searching in " + x) # Launch the research listings = daft.search() # List data in the database for listing in listings: try: beds = listing.bedrooms address = listing.formalised_address link = listing.daft_link price = listing.price value = (today, x, beds, address, link, price)
import pandas as pd from daftlistings import Daft, RentType daft = Daft() daft.set_county("Dublin City") daft.set_listing_type(RentType.APARTMENTS) daft.set_min_price(1000) daft.set_max_price(1650) listings = daft.search(fetch_all=False) properties = [] for listing in listings: properties.append(listing.as_dict()) df = pd.DataFrame(properties) df.to_excel(excel_writer="file.xls")
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)
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("")
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)