Esempio n. 1
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)
Esempio n. 2
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.get_listings()
        except:
            raised_exception = True

        self.assertTrue(raised_exception)
Esempio n. 3
0
 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)
Esempio n. 4
0
 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)
Esempio n. 5
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.get_listings()
        self.assertTrue(len(listings) > 0)
Esempio n. 6
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.get_listings()
     self.assertTrue(len(listings) == 0)
Esempio n. 7
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)
Esempio n. 8
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.get_listings()
     self.assertTrue(len(listings) > 0)
     listing = listings[0]
     self.assertTrue(listing.get_num_bedrooms() == 3)
Esempio n. 9
0
def scrape_area(area):
    """
    Scrapes Daft for a certain area, and finds the latest listings based on certain filtering criteria
    :param area:
    :return: A list of results.
    """

    d = Daft()
    offset = 0
    pages = True

    while pages:

        daft_houses = d.get_listings(county=settings.COUNTY,
                                     area=area,
                                     offset=offset,
                                     listing_type=settings.dwelling_type,
                                     sale_type=settings.rent_or_sale,
                                     max_price=settings.MAX_PRICE,
                                     min_price=settings.MIN_PRICE)

        results = []

        if not daft_houses:
            pages = False

        for listing in daft_houses:
            foo = session.query(Daft_Listing).filter_by(
                link=listing.get_daft_link()).first()
            # Don't store the listing if it already exists.
            if foo is None:

                # Create the listing object.
                foo = Daft_Listing(link=listing.get_daft_link(),
                                   created=listing.get_posted_since(),
                                   building_type=listing.get_dwelling_type(),
                                   address=listing.get_formalised_address(),
                                   price=listing.get_price(),
                                   bedrooms=listing.get_num_bedrooms(),
                                   bathrooms=listing.get_num_bathrooms(),
                                   area=listing.get_town())

                # Save the listing so we don't grab it again.
                session.add(foo)
                session.commit()

                price = listing.get_price()
                if price is not None:
                    price = price.encode('utf-8')
                    results.append([
                        listing.get_formalised_address(), price,
                        listing.get_num_bedrooms(),
                        listing.get_daft_link()
                    ])

            offset += 10
        return results
Esempio n. 10
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)
Esempio n. 11
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.get_listings()

        self.assertTrue(len(listings) > 0)

        listing = listings[0]
        price = listing.get_price()
        price = price[1:]
        price = price.replace(',', '')

        self.assertTrue(int(price) >= 150000)
Esempio n. 12
0
    def test_contact_avertiser(self):
        daft = Daft()
        daft.set_county("Meath")
        daft.set_listing_type(RentType.FLAT)
        listings = daft.get_listings()
        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)
Esempio n. 13
0
 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.get_listings()
     self.assertTrue(len(listings) > 0)
     listing = listings[0]
     price = listing.get_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)
Esempio n. 14
0
    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)
Esempio n. 15
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.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)
# 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)
Esempio n. 17
0
class DaftTests(unittest.TestCase):
    def setUp(self):
        self.daft = Daft()

    def test_properties(self):
        listings = self.daft.get_listings(county='Dublin City',
                                          area='Dublin 15',
                                          listing_type=SaleType.PROPERTIES)

        self.assertTrue(len(listings) > 0)

    def test_properties_sale_agreed(self):
        listings = self.daft.get_listings(county='Dublin City',
                                          area='Dublin 15',
                                          listing_type=SaleType.PROPERTIES,
                                          sale_agreed=True)

        self.assertTrue(len(listings) > 0)

    def test_properties_sale_agreed_with_price(self):
        listings = self.daft.get_listings(county='Dublin City',
                                          area='Dublin 15',
                                          listing_type=SaleType.PROPERTIES,
                                          sale_agreed=True,
                                          min_price=200000,
                                          max_price=250000)

        self.assertTrue(len(listings) > 0)
        listing = listings[0]
        price = listing.get_price()
        price = price[1:]
        price = price.replace(',', '')
        self.assertTrue(200000 <= int(price) <= 250000)
        self.assertTrue('Dublin 15' in listing.get_formalised_address())

    def test_properties_sale_agreed_with_invalid_prices(self):
        raised_exception = False
        try:
            listings = self.daft.get_listings(county='Dublin City',
                                              area='Dublin 15',
                                              listing_type=SaleType.PROPERTIES,
                                              sale_agreed=True,
                                              min_price="twooo",
                                              max_price="")
        except:
            raised_exception = True

        self.assertTrue(raised_exception)

    def test_properties_with_price(self):
        listings = self.daft.get_listings(county='Dublin City',
                                          area='Dublin 15',
                                          listing_type=SaleType.PROPERTIES,
                                          min_price=200000,
                                          max_price=250000)

        self.assertTrue(len(listings) > 0)
        listing = listings[0]
        price = listing.get_price()
        price = price[1:]
        price = price.replace(',', '')
        self.assertTrue(200000 <= int(price) <= 250000)
        self.assertTrue('Dublin 15' in listing.get_formalised_address())

    def test_apartments_to_let(self):
        listings = self.daft.get_listings(county='Dublin City',
                                          area='Dublin 15',
                                          listing_type=RentType.APARTMENTS,
                                          sale_type='rent')

        self.assertTrue(len(listings) > 0)

    def test_apartments_to_let_with_price(self):
        listings = self.daft.get_listings(county='Dublin City',
                                          area='Dublin 15',
                                          listing_type=RentType.APARTMENTS,
                                          min_price=1000,
                                          max_price=2000,
                                          sale_type='rent')

        self.assertTrue(len(listings) > 0)
        listing = listings[0]
        price = listing.get_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)
        self.assertTrue('Dublin 15' in listing.get_formalised_address())

    def test_commercial_properties(self):
        listings = self.daft.get_listings(
            county='Dublin',
            listing_type=SaleType.COMMERCIAL,
        )
        self.assertTrue(len(listings) > 0)

    def test_area_commercial_properties(self):
        listings = self.daft.get_listings(county='Dublin',
                                          listing_type=SaleType.COMMERCIAL,
                                          area='Dublin 15')

        self.assertTrue(len(listings) > 0)
        listing = listings[0]
        self.assertTrue('Dublin 15' in listing.get_formalised_address())

    def test_commercial_property_types(self):
        listings = self.daft.get_listings(
            county='Dublin',
            listing_type=SaleType.COMMERCIAL,
            commercial_property_type=CommercialType.OFFICE)
        self.assertTrue(len(listings) > 0)

        listings = self.daft.get_listings(
            county='Dublin',
            listing_type=SaleType.COMMERCIAL,
            commercial_property_type=CommercialType.DEV_LAND)
        self.assertTrue(len(listings) > 0)

    def test_commercial_properties_with_price(self):
        listings = self.daft.get_listings(
            county='Dublin',
            listing_type=SaleType.COMMERCIAL,
            commercial_property_type=CommercialType.OFFICE,
            min_price=150000)
        listing = listings[0]
        price = listing.get_price()
        price = price[1:]
        price = price.replace(',', '')

        self.assertTrue(int(price) >= 150000)

    def test_sort_by_price(self):
        listings = self.daft.get_listings(county='Dublin City',
                                          area='Dublin 15',
                                          listing_type=SaleType.PROPERTIES,
                                          sort_order=SortOrder.ASCENDING,
                                          sort_by=SortType.PRICE,
                                          min_price=150000,
                                          max_price=175000)

        listing = listings[0]
        price = listing.get_price()
        price = price[1:]
        price = price.replace(',', '')
        self.assertTrue(len(listings) > 0)
        self.assertTrue(int(price) <= 175000)

    def test_sort_by_date_descending(self):

        listings = self.daft.get_listings(county='Dublin City',
                                          area='Dublin 15',
                                          listing_type=SaleType.PROPERTIES,
                                          sort_order=SortOrder.DESCENDING,
                                          sort_by=SortType.DATE,
                                          min_price=150000,
                                          max_price=175000)

        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_date_ascending(self):
        listings = self.daft.get_listings(county='Dublin City',
                                          area='Dublin 15',
                                          listing_type=SaleType.PROPERTIES,
                                          sort_order=SortOrder.ASCENDING,
                                          sort_by=SortType.DATE,
                                          min_price=150000,
                                          max_price=175000)

        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)
Esempio n. 18
0
class DaftTests(unittest.TestCase):
    def setUp(self):
        self.daft = Daft()

    def test_properties(self):
        listings = self.daft.get_listings(county='Dublin City',
                                          area='Dublin 15',
                                          listing_type='properties')

        self.assertFalse(not listings)

    def test_properties_sale_agreed(self):
        listings = self.daft.get_listings(county='Dublin City',
                                          area='Dublin 15',
                                          listing_type='properties',
                                          sale_agreed=True)

        self.assertFalse(not listings)

    def test_properties_sale_agreed_with_price(self):
        listings = self.daft.get_listings(county='Dublin City',
                                          area='Dublin 15',
                                          listing_type='properties',
                                          sale_agreed=True,
                                          min_price=200000,
                                          max_price=250000)

        self.assertFalse(not listings)

    def test_properties_with_price(self):
        listings = self.daft.get_listings(county='Dublin City',
                                          area='Dublin 15',
                                          listing_type='properties',
                                          min_price=200000,
                                          max_price=250000)

        self.assertFalse(not listings)

    def test_apartments_to_let(self):
        listings = self.daft.get_listings(county='Dublin City',
                                          area='Dublin 15',
                                          listing_type='apartments',
                                          sale_type='rent')

        self.assertFalse(not listings)

    def test_apartments_to_let_with_price(self):
        listings = self.daft.get_listings(county='Dublin City',
                                          area='Dublin 15',
                                          listing_type='apartments',
                                          min_price=1000,
                                          max_price=2000,
                                          sale_type='rent')

        self.assertFalse(not listings)

    def test_properties_num_of_beds(self):
        listings = self.daft.get_listings(county='Dublin',
                                          listing_type='properties',
                                          min_price=200000,
                                          max_price=250000,
                                          min_beds=5,
                                          max_beds=5)

        first = listings[0]
        self.assertEqual(first.get_num_bedrooms(), '5 Beds')
Esempio n. 19
0
 def test_properties_without_county(self):
     try:
         daft = Daft()
         listing = daft.get_listings()
     except Exception:
         self.assertTrue(True)