mirror of
https://github.com/etienne-hd/lbc.git
synced 2026-04-21 22:42:41 +02:00
get_ad & get_user functions, extended user info (badges, feedback, pro), and new usage examples
This commit is contained in:
22
examples/get_ad.py
Normal file
22
examples/get_ad.py
Normal file
@@ -0,0 +1,22 @@
|
||||
"""Get detailed information about an ad on Leboncoin using its ID."""
|
||||
|
||||
import lbc
|
||||
|
||||
def main() -> None:
|
||||
# Initialize the Leboncoin API client
|
||||
client = lbc.Client()
|
||||
|
||||
# Fetch an ad by its Leboncoin ID (replace with a real one for testing)
|
||||
ad = client.get_ad("0123456789")
|
||||
|
||||
# Print basic information about the ad
|
||||
print("Title:", ad.subject)
|
||||
print("Price:", ad.price)
|
||||
print("Favorites:", ad.favorites)
|
||||
print("First published on:", ad.first_publication_date)
|
||||
|
||||
# Print information about the user who posted the ad
|
||||
print("User info:", ad.user)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
20
examples/get_user.py
Normal file
20
examples/get_user.py
Normal file
@@ -0,0 +1,20 @@
|
||||
"""Get detailed information about a Leboncoin user using their user ID."""
|
||||
|
||||
import lbc
|
||||
|
||||
def main() -> None:
|
||||
# Initialize the Leboncoin API client
|
||||
client = lbc.Client()
|
||||
|
||||
# Fetch a user by their Leboncoin user ID
|
||||
# Replace the ID with a real one for testing
|
||||
user = client.get_user("01234567-89ab-cdef-0123-456789abcdef")
|
||||
|
||||
# Print raw user attributes
|
||||
print("User ID:", user.id)
|
||||
print("Name:", user.name)
|
||||
print("Pro status:", user.is_pro)
|
||||
print("Ads count:", user.total_ads)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
38
examples/search_with_args.py
Normal file
38
examples/search_with_args.py
Normal file
@@ -0,0 +1,38 @@
|
||||
"""Search for ads on Leboncoin by location and filters (example: real estate in Paris)."""
|
||||
|
||||
import lbc
|
||||
|
||||
def main() -> None:
|
||||
# Initialize the Leboncoin API client
|
||||
client = lbc.Client()
|
||||
|
||||
# Define the search location: Paris with a 10 km radius
|
||||
location = lbc.City(
|
||||
lat=48.85994982004764,
|
||||
lng=2.33801967847424,
|
||||
radius=10_000, # 10 km
|
||||
city="Paris"
|
||||
)
|
||||
|
||||
# Perform a search with various filters
|
||||
result = client.search(
|
||||
text="maison", # Search for houses
|
||||
locations=[location], # Only in Paris
|
||||
page=1,
|
||||
limit=35, # Max results per page
|
||||
limit_alu=0, # No auto-suggestions
|
||||
sort=lbc.Sort.NEWEST, # Sort by newest ads
|
||||
ad_type=lbc.AdType.OFFER, # Only offers, not searches
|
||||
category=lbc.Category.IMMOBILIER, # Real estate category
|
||||
owner_type=lbc.OwnerType.ALL, # All types of sellers
|
||||
search_in_title_only=True, # Only search in titles
|
||||
square=(200, 400), # Surface between 200 and 400 m²
|
||||
price=[300_000, 700_000] # Price range in euros
|
||||
)
|
||||
|
||||
# Display summary of each ad
|
||||
for ad in result.ads:
|
||||
print(f"{ad.id} | {ad.url} | {ad.subject} | {ad.price}€ | Seller: {ad.user}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
43
examples/search_with_args_pro.py
Normal file
43
examples/search_with_args_pro.py
Normal file
@@ -0,0 +1,43 @@
|
||||
"""Search for professional ads on Leboncoin (example: real estate in Paris)."""
|
||||
|
||||
import lbc
|
||||
|
||||
def main() -> None:
|
||||
# Initialize the Leboncoin API client
|
||||
client = lbc.Client()
|
||||
|
||||
# Define search location: Paris with a 10 km radius
|
||||
location = lbc.City(
|
||||
lat=48.85994982004764,
|
||||
lng=2.33801967847424,
|
||||
radius=10_000, # 10 km
|
||||
city="Paris"
|
||||
)
|
||||
|
||||
# Perform a search with specific filters
|
||||
result = client.search(
|
||||
text="maison", # Search for houses
|
||||
locations=[location], # Only in Paris
|
||||
page=1,
|
||||
limit=35, # Max results per page
|
||||
limit_alu=0, # No auto-suggestions
|
||||
sort=lbc.Sort.NEWEST, # Sort by newest ads
|
||||
ad_type=lbc.AdType.OFFER, # Only offers, not searches
|
||||
category=lbc.Category.IMMOBILIER, # Real estate category
|
||||
owner_type=lbc.OwnerType.ALL, # All types of sellers
|
||||
search_in_title_only=True, # Only search in titles
|
||||
square=(200, 400), # Surface between 200 and 400 m²
|
||||
price=[300_000, 700_000] # Price range in euros
|
||||
)
|
||||
|
||||
# Display only professional ads with their legal/professional data
|
||||
for ad in result.ads:
|
||||
if ad.user.is_pro and ad.user.pro:
|
||||
print(
|
||||
f"Store: {ad.user.pro.online_store_name} | "
|
||||
f"SIRET: {ad.user.pro.siret} | "
|
||||
f"Website: {ad.user.pro.website_url or 'N/A'}"
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
21
examples/search_with_url.py
Normal file
21
examples/search_with_url.py
Normal file
@@ -0,0 +1,21 @@
|
||||
"""Search for ads on Leboncoin using a full search URL."""
|
||||
|
||||
import lbc
|
||||
|
||||
def main() -> None:
|
||||
# Initialize the Leboncoin API client
|
||||
client = lbc.Client()
|
||||
|
||||
# Perform a search using a prebuilt Leboncoin URL
|
||||
result = client.search(
|
||||
url="https://www.leboncoin.fr/recherche?category=10&text=maison&locations=Paris__48.86023250788424_2.339006433295173_9256_30000",
|
||||
page=1,
|
||||
limit=35
|
||||
)
|
||||
|
||||
# Print basic info about each ad
|
||||
for ad in result.ads:
|
||||
print(f"{ad.id} | {ad.url} | {ad.subject} | {ad.price}€ | Seller: {ad.user}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user