daftlistings

repository·master·Indexed 41 days ago

https://github.com/anthonybloomer/daftlistings

A Python library for programmatic interaction with Daft.ie to access property listings across Ireland. It provides the Daft class for searching and filtering listings by location, price, and property type, as well as a MapVisualization class for creating interactive maps from search results.

Tokens
1.3K
Snippets
8
Records
8
Agent score
2%

What's inside daftlistings

  1. Configure search criteria with Daft

    master

    You can refine your search by calling configuration methods on the Daft instance before executing .search().

    Supported configuration methods include:

    • set_location(location): Sets the search area (can take a Location enum or a string).
    • set_search_type(search_type): Sets the type of listing (e.g., SearchType.RESIDENTIAL_RENT, SearchType.RESIDENTIAL_SALE, SearchType.STUDENT_ACCOMMODATION, SearchType.COMMERCIAL_SALE).
    • set_property_type(property_type): Sets the property category (e.g., PropertyType.APARTMENT, PropertyType.HOUSE).
    • set_min_price(price): Sets the minimum price.
    • set_max_price(price): Sets the maximum price.
    • set_sort_type(sort_type): Sets the sorting order (e.g., SortType.PRICE_ASC).
    • set_facility(facility): Adds a required facility (e.g., Facility.PARKING, Facility.ALARM).
    from daftlistings import Daft, Location, SearchType, PropertyType
    
    daft = Daft()
    daft.set_location(Location.DUBLIN)
    daft.set_search_type(SearchType.RESIDENTIAL_RENT)
    daft.set_property_type(PropertyType.APARTMENT)
    
    listings = daft.search()
  2. Basic usage of the Daft class

    master

    To perform a basic search, instantiate the Daft class and call the .search() method. By default, .search() iterates over all available pages of results and returns a list of Listing objects.

    from daftlistings import Daft
    
    daft = Daft()
    listings = daft.search()
    
    for listing in listings:
        print(listing.title)
        print(listing.price)
        print(listing.daft_link)
  3. Visualize listings on a map

    master

    You can use the MapVisualization class to create an interactive map from your search results. This typically involves converting the listings to a dictionary format, loading them into a Pandas DataFrame, and then passing the DataFrame to the visualizer.

    import pandas as pd
    from daftlistings import Daft, Location, SearchType, PropertyType, SortType, MapVisualization
    
    daft = Daft()
    daft.set_location(Location.DUBLIN)
    daft.set_search_type(SearchType.RESIDENTIAL_RENT)
    daft.set_sort_type(SortType.PRICE_ASC)
    daft.set_max_price(1500)
    
    listings = daft.search()
    
    # Convert listings to a list of dicts for DataFrame creation
    properties = [listing.as_dict_for_mapping() for listing in listings]
    df = pd.DataFrame(properties)
    
    # Create and save map
    dublin_map = MapVisualization(df)
    dublin_map.add_markers()
    dublin_map.add_colorbar()
    dublin_map.save("ireland_rent.html")
  4. Calculate distance to coordinates

    master

    Each Listing object provides a .distance_to(coords) method. This allows you to sort or filter listings based on their proximity to a specific latitude/longitude pair.

    # Example: sorting listings by nearness to Dublin Castle
    dublin_castle_coords = [53.3429, -6.2674]
    listings.sort(key=lambda x: x.distance_to(dublin_castle_coords))
    
    for listing in listings:
        print(f'{listing.distance_to(dublin_castle_coords):.3}km')