Example #1
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)
Example #2
0
    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)
Example #3
0
    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
    daft.set_offset(offset)
print("[*] %d new listing(s) found." % len(listings))
Example #4
0
    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)
Example #5
0
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)