lbc 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lbc/__init__.py +2 -0
- lbc/client.py +85 -0
- lbc/exceptions.py +14 -0
- lbc/models/__init__.py +4 -0
- lbc/models/ad.py +32 -0
- lbc/models/attribute.py +13 -0
- lbc/models/city.py +9 -0
- lbc/models/enums.py +267 -0
- lbc/models/location.py +17 -0
- lbc/models/owner.py +9 -0
- lbc/models/proxy.py +16 -0
- lbc/models/search.py +101 -0
- lbc/session.py +39 -0
- lbc/utils.py +126 -0
- lbc-1.0.0.dist-info/METADATA +165 -0
- lbc-1.0.0.dist-info/RECORD +18 -0
- lbc-1.0.0.dist-info/WHEEL +4 -0
- lbc-1.0.0.dist-info/licenses/LICENSE +21 -0
lbc/__init__.py
ADDED
lbc/client.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
from .session import Session
|
|
2
|
+
from .models import Proxy, Search, Category, AdType, OwnerType, Sort, Region, Department, City
|
|
3
|
+
from .exceptions import DatadomeError, RequestError
|
|
4
|
+
from .utils import build_search_payload_with_args
|
|
5
|
+
|
|
6
|
+
from typing import Optional, List, Union
|
|
7
|
+
|
|
8
|
+
class Client(Session):
|
|
9
|
+
def __init__(self, proxy: Optional[Proxy] = None):
|
|
10
|
+
super().__init__(proxy=proxy)
|
|
11
|
+
|
|
12
|
+
def _fetch(self, method: str, url: str, payload: Optional[dict] = None, timeout: int = 30) -> dict:
|
|
13
|
+
"""
|
|
14
|
+
Internal method to send an HTTP request using the configured session.
|
|
15
|
+
|
|
16
|
+
Args:
|
|
17
|
+
method (staticmethod): HTTP method to use (e.g., `GET`, `POST`).
|
|
18
|
+
url (str): Full URL of the API endpoint.
|
|
19
|
+
payload (Optional[dict], optional): JSON payload to send with the request. Used for POST/PUT methods. Defaults to None.
|
|
20
|
+
timeout (int, optional): Timeout for the request, in seconds. Defaults to 30.
|
|
21
|
+
|
|
22
|
+
Raises:
|
|
23
|
+
DatadomeError: Raised when the request is blocked by Datadome protection (HTTP 403).
|
|
24
|
+
RequestError: Raised for any other non-successful HTTP response.
|
|
25
|
+
|
|
26
|
+
Returns:
|
|
27
|
+
dict: Parsed JSON response from the server.
|
|
28
|
+
"""
|
|
29
|
+
response = self.session.request(
|
|
30
|
+
method=method,
|
|
31
|
+
url=url,
|
|
32
|
+
json=payload,
|
|
33
|
+
timeout=timeout
|
|
34
|
+
)
|
|
35
|
+
if response.ok:
|
|
36
|
+
return response.json()
|
|
37
|
+
elif response.status_code == 403:
|
|
38
|
+
if self.proxy:
|
|
39
|
+
raise DatadomeError(f"Access blocked by Datadome: your proxy appears to have a poor reputation, try to change it.")
|
|
40
|
+
else:
|
|
41
|
+
raise DatadomeError(f"Access blocked by Datadome: your activity was flagged as suspicious. Please avoid sending excessive requests.")
|
|
42
|
+
else:
|
|
43
|
+
raise RequestError(f"Request failed with status code {response.status_code}.")
|
|
44
|
+
|
|
45
|
+
def search(
|
|
46
|
+
self,
|
|
47
|
+
text: Optional[str] = None,
|
|
48
|
+
category: Category = Category.TOUTES_CATEGORIES,
|
|
49
|
+
sort: Sort = Sort.RELEVANCE,
|
|
50
|
+
locations: Optional[Union[List[Union[Region, Department, City]], Union[Region, Department, City]]] = None,
|
|
51
|
+
limit: int = 35,
|
|
52
|
+
limit_alu: int = 3,
|
|
53
|
+
page: int = 1,
|
|
54
|
+
ad_type: AdType = AdType.OFFER,
|
|
55
|
+
owner_type: Optional[OwnerType] = None,
|
|
56
|
+
search_in_title_only: bool = False,
|
|
57
|
+
**kwargs
|
|
58
|
+
) -> Search:
|
|
59
|
+
"""
|
|
60
|
+
Perform a classified ads search on Leboncoin with the specified criteria.
|
|
61
|
+
|
|
62
|
+
Args:
|
|
63
|
+
text (Optional[str], optional): Search keywords. If None, returns all matching ads without filtering by keyword. Defaults to None.
|
|
64
|
+
category (Category, optional): Category to search in. Defaults to Category.TOUTES_CATEGORIES.
|
|
65
|
+
sort (Sort, optional): Sorting method for results (e.g., relevance, date, price). Defaults to Sort.RELEVANCE.
|
|
66
|
+
locations (Optional[Union[List[Union[Region, Department, City]], Union[Region, Department, City]]], optional): One or multiple locations (region, department, or city) to filter results. Defaults to None.
|
|
67
|
+
limit (int, optional): Maximum number of results to return. Defaults to 35.
|
|
68
|
+
limit_alu (int, optional): Number of ALU (Annonces Lu / similar ads) suggestions to include. Defaults to 3.
|
|
69
|
+
page (int, optional): Page number to retrieve for paginated results. Defaults to 1.
|
|
70
|
+
ad_type (AdType, optional): Type of ad (offer or request). Defaults to AdType.OFFER.
|
|
71
|
+
owner_type (Optional[OwnerType], optional): Filter by seller type (individual, professional, or all). Defaults to None.
|
|
72
|
+
search_in_title_only (bool, optional): If True, search will only be performed on ad titles. Defaults to False.
|
|
73
|
+
**kwargs: Additional advanced filters such as price range (`price=(min, max)`), surface area (`square=(min, max)`), property type, and more.
|
|
74
|
+
|
|
75
|
+
Returns:
|
|
76
|
+
Search: A `Search` object containing the parsed search results.
|
|
77
|
+
"""
|
|
78
|
+
payload = build_search_payload_with_args(
|
|
79
|
+
text=text, category=category, sort=sort, locations=locations,
|
|
80
|
+
limit=limit, limit_alu=limit_alu, page=page, ad_type=ad_type,
|
|
81
|
+
owner_type=owner_type, search_in_title_only=search_in_title_only, **kwargs
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
body = self._fetch(method="POST", url="https://api.leboncoin.fr/finder/search", payload=payload)
|
|
85
|
+
return Search.build(raw=body)
|
lbc/exceptions.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
class LBCError(Exception):
|
|
2
|
+
"""Base exception for all errors raised by the LBC client."""
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class InvalidValue(LBCError):
|
|
6
|
+
"""Raised when a provided value is invalid or improperly formatted."""
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class RequestError(LBCError):
|
|
10
|
+
"""Raised when an HTTP request fails with a non-success status code."""
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class DatadomeError(RequestError):
|
|
14
|
+
"""Raised when access is blocked by Datadome anti-bot protection."""
|
lbc/models/__init__.py
ADDED
lbc/models/ad.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from .attribute import Attribute
|
|
2
|
+
from .location import Location
|
|
3
|
+
from .owner import Owner
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from datetime import datetime
|
|
7
|
+
from typing import List
|
|
8
|
+
|
|
9
|
+
@dataclass
|
|
10
|
+
class Ad:
|
|
11
|
+
id: int
|
|
12
|
+
first_publication_date: datetime
|
|
13
|
+
expiration_date: datetime
|
|
14
|
+
index_date: datetime
|
|
15
|
+
status: str
|
|
16
|
+
category_id: str
|
|
17
|
+
category_name: str
|
|
18
|
+
subject: str
|
|
19
|
+
body: str
|
|
20
|
+
brand: str
|
|
21
|
+
ad_type: str
|
|
22
|
+
url: str
|
|
23
|
+
price: float
|
|
24
|
+
images: List[str]
|
|
25
|
+
attributes: List[Attribute]
|
|
26
|
+
location: Location
|
|
27
|
+
owner: Owner
|
|
28
|
+
has_phone: bool
|
|
29
|
+
|
|
30
|
+
@property
|
|
31
|
+
def title(self) -> str:
|
|
32
|
+
return self.subject
|
lbc/models/attribute.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from typing import Optional, List
|
|
3
|
+
|
|
4
|
+
@dataclass
|
|
5
|
+
class Attribute:
|
|
6
|
+
key: str
|
|
7
|
+
key_label: Optional[str]
|
|
8
|
+
value: str
|
|
9
|
+
value_label: str
|
|
10
|
+
values: List[str]
|
|
11
|
+
values_label: Optional[List[str]]
|
|
12
|
+
value_label_reader: Optional[str]
|
|
13
|
+
generic: bool
|
lbc/models/city.py
ADDED
lbc/models/enums.py
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
from typing import Union, Tuple
|
|
3
|
+
|
|
4
|
+
class OwnerType(Enum):
|
|
5
|
+
PRO = "pro"
|
|
6
|
+
PRIVATE = "private"
|
|
7
|
+
ALL = "all"
|
|
8
|
+
|
|
9
|
+
class AdType(Enum):
|
|
10
|
+
OFFER = "offer"
|
|
11
|
+
DEMAND = "demand"
|
|
12
|
+
|
|
13
|
+
class Sort(Enum):
|
|
14
|
+
RELEVANCE = ("relevance", None)
|
|
15
|
+
NEWEST = ("time", "desc")
|
|
16
|
+
OLDEST = ("time", "asc")
|
|
17
|
+
EXPENSIVE = ("price", "asc")
|
|
18
|
+
CHEAPEST = ("price", "desc")
|
|
19
|
+
|
|
20
|
+
class Department(Enum):
|
|
21
|
+
BAS_RHIN = ("1", "ALSACE", "67", "BAS_RHIN")
|
|
22
|
+
HAUT_RHIN = ("1", "ALSACE", "68", "HAUT_RHIN")
|
|
23
|
+
DORDOGNE = ("2", "AQUITAINE", "24", "DORDOGNE")
|
|
24
|
+
GIRONDE = ("2", "AQUITAINE", "33", "GIRONDE")
|
|
25
|
+
LANDES = ("2", "AQUITAINE", "40", "LANDES")
|
|
26
|
+
LOT_ET_GARONNE = ("2", "AQUITAINE", "47", "LOT_ET_GARONNE")
|
|
27
|
+
PYRENEES_ATLANTIQUES = ("2", "AQUITAINE", "64", "PYRENEES_ATLANTIQUES")
|
|
28
|
+
ALLIER = ("3", "AUVERGNE", "3", "ALLIER")
|
|
29
|
+
CANTAL = ("3", "AUVERGNE", "15", "CANTAL")
|
|
30
|
+
HAUTE_LOIRE = ("3", "AUVERGNE", "43", "HAUTE_LOIRE")
|
|
31
|
+
PUY_DE_DOME = ("3", "AUVERGNE", "63", "PUY_DE_DOME")
|
|
32
|
+
CALVADOS = ("4", "BASSE_NORMANDIE", "14", "CALVADOS")
|
|
33
|
+
MANCHE = ("4", "BASSE_NORMANDIE", "50", "MANCHE")
|
|
34
|
+
ORNE = ("4", "BASSE_NORMANDIE", "61", "ORNE")
|
|
35
|
+
COTE_DOR = ("5", "BOURGOGNE", "21", "COTE_DOR")
|
|
36
|
+
NIEVRE = ("5", "BOURGOGNE", "58", "NIEVRE")
|
|
37
|
+
SAONE_ET_LOIRE = ("5", "BOURGOGNE", "71", "SAONE_ET_LOIRE")
|
|
38
|
+
YONNE = ("5", "BOURGOGNE", "89", "YONNE")
|
|
39
|
+
COTES_DARMOR = ("6", "BRETAGNE", "22", "COTES_DARMOR")
|
|
40
|
+
FINISTERE = ("6", "BRETAGNE", "29", "FINISTERE")
|
|
41
|
+
ILLE_ET_VILAINE = ("6", "BRETAGNE", "35", "ILLE_ET_VILAINE")
|
|
42
|
+
MORBIHAN = ("6", "BRETAGNE", "56", "MORBIHAN")
|
|
43
|
+
CHER = ("7", "CENTRE", "18", "CHER")
|
|
44
|
+
EURE_ET_LOIR = ("7", "CENTRE", "28", "EURE_ET_LOIR")
|
|
45
|
+
INDRE = ("7", "CENTRE", "36", "INDRE")
|
|
46
|
+
INDRE_ET_LOIRE = ("7", "CENTRE", "37", "INDRE_ET_LOIRE")
|
|
47
|
+
LOIR_ET_CHER = ("7", "CENTRE", "41", "LOIR_ET_CHER")
|
|
48
|
+
LOIRET = ("7", "CENTRE", "45", "LOIRET")
|
|
49
|
+
ARDENNES = ("8", "CHAMPAGNE_ARDENNE", "8", "ARDENNES")
|
|
50
|
+
AUBE = ("8", "CHAMPAGNE_ARDENNE", "10", "AUBE")
|
|
51
|
+
MARNE = ("8", "CHAMPAGNE_ARDENNE", "51", "MARNE")
|
|
52
|
+
HAUTE_MARNE = ("8", "CHAMPAGNE_ARDENNE", "52", "HAUTE_MARNE")
|
|
53
|
+
DOUBS = ("10", "FRANCHE_COMTE", "25", "DOUBS")
|
|
54
|
+
JURA = ("10", "FRANCHE_COMTE", "39", "JURA")
|
|
55
|
+
HAUTE_SAONE = ("10", "FRANCHE_COMTE", "70", "HAUTE_SAONE")
|
|
56
|
+
TERRITOIRE_DE_BELFORT = ("10", "FRANCHE_COMTE", "90", "TERRITOIRE_DE_BELFORT")
|
|
57
|
+
EURE = ("11", "HAUTE_NORMANDIE", "27", "EURE")
|
|
58
|
+
SEINE_MARITIME = ("11", "HAUTE_NORMANDIE", "76", "SEINE_MARITIME")
|
|
59
|
+
PARIS = ("12", "ILE_DE_FRANCE", "75", "PARIS")
|
|
60
|
+
SEINE_ET_MARNE = ("12", "ILE_DE_FRANCE", "77", "SEINE_ET_MARNE")
|
|
61
|
+
YVELINES = ("12", "ILE_DE_FRANCE", "78", "YVELINES")
|
|
62
|
+
ESSONNE = ("12", "ILE_DE_FRANCE", "91", "ESSONNE")
|
|
63
|
+
HAUTS_DE_SEINE = ("12", "ILE_DE_FRANCE", "92", "HAUTS_DE_SEINE")
|
|
64
|
+
SEINE_SAINT_DENIS = ("12", "ILE_DE_FRANCE", "93", "SEINE_SAINT_DENIS")
|
|
65
|
+
VAL_DE_MARNE = ("12", "ILE_DE_FRANCE", "94", "VAL_DE_MARNE")
|
|
66
|
+
VAL_DOISE = ("12", "ILE_DE_FRANCE", "95", "VAL_DOISE")
|
|
67
|
+
AUDE = ("13", "LANGUEDOC_ROUSSILLON", "11", "AUDE")
|
|
68
|
+
GARD = ("13", "LANGUEDOC_ROUSSILLON", "30", "GARD")
|
|
69
|
+
HERAULT = ("13", "LANGUEDOC_ROUSSILLON", "34", "HERAULT")
|
|
70
|
+
LOZERE = ("13", "LANGUEDOC_ROUSSILLON", "48", "LOZERE")
|
|
71
|
+
PYRENEES_ORIENTALES = ("13", "LANGUEDOC_ROUSSILLON", "66", "PYRENEES_ORIENTALES")
|
|
72
|
+
CORREZE = ("14", "LIMOUSIN", "19", "CORREZE")
|
|
73
|
+
CREUSE = ("14", "LIMOUSIN", "23", "CREUSE")
|
|
74
|
+
HAUTE_VIENNE = ("14", "LIMOUSIN", "87", "HAUTE_VIENNE")
|
|
75
|
+
MEURTHE_ET_MOSELLE = ("15", "LORRAINE", "54", "MEURTHE_ET_MOSELLE")
|
|
76
|
+
MEUSE = ("15", "LORRAINE", "55", "MEUSE")
|
|
77
|
+
MOSELLE = ("15", "LORRAINE", "57", "MOSELLE")
|
|
78
|
+
VOSGES = ("15", "LORRAINE", "88", "VOSGES")
|
|
79
|
+
ARIEGE = ("16", "MIDI_PYRENEES", "9", "ARIEGE")
|
|
80
|
+
AVEYRON = ("16", "MIDI_PYRENEES", "12", "AVEYRON")
|
|
81
|
+
HAUTE_GARONNE = ("16", "MIDI_PYRENEES", "31", "HAUTE_GARONNE")
|
|
82
|
+
GERS = ("16", "MIDI_PYRENEES", "32", "GERS")
|
|
83
|
+
LOT = ("16", "MIDI_PYRENEES", "46", "LOT")
|
|
84
|
+
HAUTES_PYRENEES = ("16", "MIDI_PYRENEES", "65", "HAUTES_PYRENEES")
|
|
85
|
+
TARN = ("16", "MIDI_PYRENEES", "81", "TARN")
|
|
86
|
+
TARN_ET_GARONNE = ("16", "MIDI_PYRENEES", "82", "TARN_ET_GARONNE")
|
|
87
|
+
NORD = ("17", "NORD_PAS_DE_CALAIS", "59", "NORD")
|
|
88
|
+
PAS_DE_CALAIS = ("17", "NORD_PAS_DE_CALAIS", "62", "PAS_DE_CALAIS")
|
|
89
|
+
LOIRE_ATLANTIQUE = ("18", "PAYS_DE_LA_LOIRE", "44", "LOIRE_ATLANTIQUE")
|
|
90
|
+
MAINE_ET_LOIRE = ("18", "PAYS_DE_LA_LOIRE", "49", "MAINE_ET_LOIRE")
|
|
91
|
+
MAYENNE = ("18", "PAYS_DE_LA_LOIRE", "53", "MAYENNE")
|
|
92
|
+
SARTHE = ("18", "PAYS_DE_LA_LOIRE", "72", "SARTHE")
|
|
93
|
+
VENDEE = ("18", "PAYS_DE_LA_LOIRE", "85", "VENDEE")
|
|
94
|
+
AISNE = ("19", "PICARDIE", "2", "AISNE")
|
|
95
|
+
OISE = ("19", "PICARDIE", "60", "OISE")
|
|
96
|
+
SOMME = ("19", "PICARDIE", "80", "SOMME")
|
|
97
|
+
CHARENTE = ("20", "POITOU_CHARENTES", "16", "CHARENTE")
|
|
98
|
+
CHARENTE_MARITIME = ("20", "POITOU_CHARENTES", "17", "CHARENTE_MARITIME")
|
|
99
|
+
DEUX_SEVRES = ("20", "POITOU_CHARENTES", "79", "DEUX_SEVRES")
|
|
100
|
+
VIENNE = ("20", "POITOU_CHARENTES", "86", "VIENNE")
|
|
101
|
+
ALPES_DE_HAUTE_PROVENCE = ("21", "PROVENCE_ALPES_COTE_DAZUR", "4", "ALPES_DE_HAUTE_PROVENCE")
|
|
102
|
+
HAUTES_ALPES = ("21", "PROVENCE_ALPES_COTE_DAZUR", "5", "HAUTES_ALPES")
|
|
103
|
+
ALPES_MARITIMES = ("21", "PROVENCE_ALPES_COTE_DAZUR", "6", "ALPES_MARITIMES")
|
|
104
|
+
BOUCHES_DU_RHONE = ("21", "PROVENCE_ALPES_COTE_DAZUR", "13", "BOUCHES_DU_RHONE")
|
|
105
|
+
VAR = ("21", "PROVENCE_ALPES_COTE_DAZUR", "83", "VAR")
|
|
106
|
+
VAUCLUSE = ("21", "PROVENCE_ALPES_COTE_DAZUR", "84", "VAUCLUSE")
|
|
107
|
+
AIN = ("22", "RHONE_ALPES", "1", "AIN")
|
|
108
|
+
ARDECHE = ("22", "RHONE_ALPES", "7", "ARDECHE")
|
|
109
|
+
DROME = ("22", "RHONE_ALPES", "26", "DROME")
|
|
110
|
+
ISERE = ("22", "RHONE_ALPES", "38", "ISERE")
|
|
111
|
+
LOIRE = ("22", "RHONE_ALPES", "42", "LOIRE")
|
|
112
|
+
RHONE = ("22", "RHONE_ALPES", "69", "RHONE")
|
|
113
|
+
SAVOIE = ("22", "RHONE_ALPES", "73", "SAVOIE")
|
|
114
|
+
HAUTE_SAVOIE = ("22", "RHONE_ALPES", "74", "HAUTE_SAVOIE")
|
|
115
|
+
|
|
116
|
+
class Region(Enum):
|
|
117
|
+
ALSACE = ("1", "ALSACE")
|
|
118
|
+
AQUITAINE = ("2", "AQUITAINE")
|
|
119
|
+
AUVERGNE = ("3", "AUVERGNE")
|
|
120
|
+
AUVERGNE_RHONE_ALPES = ("30", "AUVERGNE_RHONE_ALPES")
|
|
121
|
+
BASSE_NORMANDIE = ("4", "BASSE_NORMANDIE")
|
|
122
|
+
BOURGOGNE = ("5", "BOURGOGNE")
|
|
123
|
+
BOURGOGNE_FRANCHE_COMTE = ("31", "BOURGOGNE_FRANCHE_COMTE")
|
|
124
|
+
BRETAGNE = ("6", "BRETAGNE")
|
|
125
|
+
CENTRE = ("7", "CENTRE")
|
|
126
|
+
CENTRE_VAL_DE_LOIRE = ("37", "CENTRE_VAL_DE_LOIRE")
|
|
127
|
+
CHAMPAGNE_ARDENNE = ("8", "CHAMPAGNE_ARDENNE")
|
|
128
|
+
CORSE = ("9", "CORSE")
|
|
129
|
+
FRANCHE_COMTE = ("10", "FRANCHE_COMTE")
|
|
130
|
+
GRAND_EST = ("33", "GRAND_EST")
|
|
131
|
+
GUADELOUPE = ("23", "GUADELOUPE")
|
|
132
|
+
GUYANE = ("25", "GUYANE")
|
|
133
|
+
HAUTE_NORMANDIE = ("11", "HAUTE_NORMANDIE")
|
|
134
|
+
HAUTS_DE_FRANCE = ("32", "HAUTS_DE_FRANCE")
|
|
135
|
+
ILE_DE_FRANCE = ("12", "ILE_DE_FRANCE")
|
|
136
|
+
LANGUEDOC_ROUSSILLON = ("13", "LANGUEDOC_ROUSSILLON")
|
|
137
|
+
LIMOUSIN = ("14", "LIMOUSIN")
|
|
138
|
+
LORRAINE = ("15", "LORRAINE")
|
|
139
|
+
MARTINIQUE = ("24", "MARTINIQUE")
|
|
140
|
+
MIDI_PYRENEES = ("16", "MIDI_PYRENEES")
|
|
141
|
+
NORD_PAS_DE_CALAIS = ("17", "NORD_PAS_DE_CALAIS")
|
|
142
|
+
NORMANDIE = ("34", "NORMANDIE")
|
|
143
|
+
NOUVELLE_AQUITAINE = ("35", "NOUVELLE_AQUITAINE")
|
|
144
|
+
OCCITANIE = ("36", "OCCITANIE")
|
|
145
|
+
PAYS_DE_LA_LOIRE = ("18", "PAYS_DE_LA_LOIRE")
|
|
146
|
+
PICARDIE = ("19", "PICARDIE")
|
|
147
|
+
POITOU_CHARENTES = ("20", "POITOU_CHARENTES")
|
|
148
|
+
PROVENCE_ALPES_COTE_DAZUR = ("21", "PROVENCE_ALPES_COTE_DAZUR")
|
|
149
|
+
RHONE_ALPES = ("22", "RHONE_ALPES")
|
|
150
|
+
REUNION = ("26", "REUNION")
|
|
151
|
+
|
|
152
|
+
class Category(Enum):
|
|
153
|
+
TOUTES_CATEGORIES = "0"
|
|
154
|
+
EMPLOI = "71"
|
|
155
|
+
EMPLOI_OFFRES_DEMPLOI = "33"
|
|
156
|
+
EMPLOI_FORMATIONS_PROFESSIONNELLES = "74"
|
|
157
|
+
VEHICULES = "1"
|
|
158
|
+
VEHICULES_VOITURES = "2"
|
|
159
|
+
VEHICULES_MOTOS = "3"
|
|
160
|
+
VEHICULES_CARAVANING = "4"
|
|
161
|
+
VEHICULES_UTILITAIRES = "5"
|
|
162
|
+
VEHICULES_CAMIONS = "300"
|
|
163
|
+
VEHICULES_NAUTISME = "7"
|
|
164
|
+
VEHICULES_VELOS = "1002"
|
|
165
|
+
VEHICULES_EQUIPEMENT_AUTO = "6"
|
|
166
|
+
VEHICULES_EQUIPEMENT_MOTO = "44"
|
|
167
|
+
VEHICULES_EQUIPEMENT_CARAVANING = "50"
|
|
168
|
+
VEHICULES_EQUIPEMENT_NAUTISME = "51"
|
|
169
|
+
VEHICULES_EQUIPEMENTS_VELOS = "1003"
|
|
170
|
+
VEHICULES_SERVICES_DE_REPARATIONS_MECANIQUES = "1004"
|
|
171
|
+
IMMOBILIER = "8"
|
|
172
|
+
IMMOBILIER_VENTES_IMMOBILIERES = "9"
|
|
173
|
+
IMMOBILIER_LOCATIONS = "10"
|
|
174
|
+
IMMOBILIER_COLOCATIONS = "11"
|
|
175
|
+
IMMOBILIER_BUREAUX_ET_COMMERCES = "13"
|
|
176
|
+
IMMOBILIER_IMMOBILIER_NEUF = "304"
|
|
177
|
+
IMMOBILIER_SERVICES_DE_DEMENAGEMENT = "1001"
|
|
178
|
+
LOCATIONS_DE_VACANCES = "66"
|
|
179
|
+
LOCATIONS_DE_VACANCES_LOCATIONS_SAISONNIERES = "12"
|
|
180
|
+
ELECTRONIQUE = "14"
|
|
181
|
+
ELECTRONIQUE_ORDINATEURS = "15"
|
|
182
|
+
ELECTRONIQUE_ACCESSOIRES_INFORMATIQUE = "83"
|
|
183
|
+
ELECTRONIQUE_TABLETTES_ET_LISEUSES = "82"
|
|
184
|
+
ELECTRONIQUE_PHOTO_AUDIO_ET_VIDEO = "16"
|
|
185
|
+
ELECTRONIQUE_TELEPHONES_ET_OBJETS_CONNECTES = "17"
|
|
186
|
+
ELECTRONIQUE_ACCESSOIRES_TELEPHONE_ET_OBJETS_CONNECTES = "81"
|
|
187
|
+
ELECTRONIQUE_CONSOLES = "43"
|
|
188
|
+
ELECTRONIQUE_JEUX_VIDEO = "84"
|
|
189
|
+
ELECTRONIQUE_ELECTROMENAGER = "1006"
|
|
190
|
+
ELECTRONIQUE_SERVICES_DE_REPARATIONS_ELECTRONIQUES = "1007"
|
|
191
|
+
MAISON_ET_JARDIN = "18"
|
|
192
|
+
MAISON_ET_JARDIN_AMEUBLEMENT = "19"
|
|
193
|
+
MAISON_ET_JARDIN_PAPETERIE_ET_FOURNITURES_SCOLAIRES = "96"
|
|
194
|
+
MAISON_ET_JARDIN_ELECTROMENAGER = "20"
|
|
195
|
+
MAISON_ET_JARDIN_ARTS_DE_LA_TABLE = "45"
|
|
196
|
+
MAISON_ET_JARDIN_DECORATION = "39"
|
|
197
|
+
MAISON_ET_JARDIN_LINGE_DE_MAISON = "46"
|
|
198
|
+
MAISON_ET_JARDIN_BRICOLAGE = "21"
|
|
199
|
+
MAISON_ET_JARDIN_JARDIN_ET_PLANTES = "52"
|
|
200
|
+
MAISON_ET_JARDIN_SERVICES_DE_JARDINERIE_ET_BRICOLAGE = "1005"
|
|
201
|
+
FAMILLE = "79"
|
|
202
|
+
FAMILLE_EQUIPEMENT_BEBE = "23"
|
|
203
|
+
FAMILLE_MOBILIER_ENFANT = "80"
|
|
204
|
+
FAMILLE_VETEMENTS_BEBE = "54"
|
|
205
|
+
FAMILLE_VETEMENTS_ENFANTS = "1011"
|
|
206
|
+
FAMILLE_VETEMENTS_MATERNITE = "1012"
|
|
207
|
+
FAMILLE_CHAUSSURES_ENFANTS = "1013"
|
|
208
|
+
FAMILLE_MONTRES_ET_BIJOUX_ENFANTS = "1014"
|
|
209
|
+
FAMILLE_ACCESSOIRES_ET_BAGAGERIE_ENFANTS = "1015"
|
|
210
|
+
FAMILLE_JEUX_ET_JOUETS = "1016"
|
|
211
|
+
FAMILLE_BABY_SITTING = "1017"
|
|
212
|
+
MODE = "72"
|
|
213
|
+
MODE_VETEMENTS = "22"
|
|
214
|
+
MODE_CHAUSSURES = "53"
|
|
215
|
+
MODE_ACCESSOIRES_ET_BAGAGERIE = "47"
|
|
216
|
+
MODE_MONTRES_ET_BIJOUX = "42"
|
|
217
|
+
LOISIRS = "24"
|
|
218
|
+
LOISIRS_ANTIQUITES = "89"
|
|
219
|
+
LOISIRS_ARTISTES_ET_MUSICIENS = "1008"
|
|
220
|
+
LOISIRS_BILLETTERIE = "1009"
|
|
221
|
+
LOISIRS_COLLECTION = "40"
|
|
222
|
+
LOISIRS_CD_MUSIQUE = "26"
|
|
223
|
+
LOISIRS_DVD_FILMS = "25"
|
|
224
|
+
LOISIRS_INSTRUMENTS_DE_MUSIQUE = "30"
|
|
225
|
+
LOISIRS_LIVRES = "27"
|
|
226
|
+
LOISIRS_MODELISME = "86"
|
|
227
|
+
LOISIRS_VINS_ET_GASTRONOMIE = "48"
|
|
228
|
+
LOISIRS_JEUX_ET_JOUETS = "41"
|
|
229
|
+
LOISIRS_LOISIRS_CREATIFS = "88"
|
|
230
|
+
LOISIRS_SPORT_ET_PLEIN_AIR = "29"
|
|
231
|
+
LOISIRS_VELOS = "55"
|
|
232
|
+
LOISIRS_EQUIPEMENTS_VELOS = "85"
|
|
233
|
+
ANIMAUX = "75"
|
|
234
|
+
ANIMAUX_ANIMAUX = "28"
|
|
235
|
+
ANIMAUX_ACCESSOIRES_ANIMAUX = "76"
|
|
236
|
+
ANIMAUX_ANIMAUX_PERDUS = "77"
|
|
237
|
+
ANIMAUX_SERVICES_AUX_ANIMAUX = "1010"
|
|
238
|
+
MATERIEL_PROFESSIONNEL = "56"
|
|
239
|
+
MATERIEL_PROFESSIONNEL_TRACTEURS = "105"
|
|
240
|
+
MATERIEL_PROFESSIONNEL_MATERIEL_AGRICOLE = "57"
|
|
241
|
+
MATERIEL_PROFESSIONNEL_BTP_CHANTIER_GROS_OEUVRE = "59"
|
|
242
|
+
MATERIEL_PROFESSIONNEL_POIDS_LOURDS = "106"
|
|
243
|
+
MATERIEL_PROFESSIONNEL_MANUTENTION_LEVAGE = "58"
|
|
244
|
+
MATERIEL_PROFESSIONNEL_EQUIPEMENTS_INDUSTRIELS = "32"
|
|
245
|
+
MATERIEL_PROFESSIONNEL_EQUIPEMENTS_POUR_RESTAURANTS_ET_HOTELS = "61"
|
|
246
|
+
MATERIEL_PROFESSIONNEL_EQUIPEMENTS_ET_FOURNITURES_DE_BUREAU = "62"
|
|
247
|
+
MATERIEL_PROFESSIONNEL_EQUIPEMENTS_POUR_COMMERCES_ET_MARCHES = "63"
|
|
248
|
+
MATERIEL_PROFESSIONNEL_MATERIEL_MEDICAL = "64"
|
|
249
|
+
SERVICES = "31"
|
|
250
|
+
SERVICES_ARTISTES_ET_MUSICIENS = "101"
|
|
251
|
+
SERVICES_BABY_SITTING = "100"
|
|
252
|
+
SERVICES_BILLETTERIE = "35"
|
|
253
|
+
SERVICES_COVOITURAGE = "65"
|
|
254
|
+
SERVICES_COURS_PARTICULIERS = "36"
|
|
255
|
+
SERVICES_ENTRAIDE_ENTRE_VOISINS = "103"
|
|
256
|
+
SERVICES_EVENEMENTS = "49"
|
|
257
|
+
SERVICES_SERVICES_A_LA_PERSONNE = "99"
|
|
258
|
+
SERVICES_SERVICES_AUX_ANIMAUX = "102"
|
|
259
|
+
SERVICES_SERVICES_DE_DEMENAGEMENT = "92"
|
|
260
|
+
SERVICES_SERVICES_DE_REPARATIONS_ELECTRONIQUES = "95"
|
|
261
|
+
SERVICES_SERVICES_DE_REPARATIONS_MECANIQUES = "93"
|
|
262
|
+
SERVICES_SERVICES_DE_JARDINERIE_ET_BRICOLAGE = "97"
|
|
263
|
+
SERVICES_SERVICES_EVENEMENTIELS = "98"
|
|
264
|
+
SERVICES_AUTRES_SERVICES = "34"
|
|
265
|
+
DONS = "1000"
|
|
266
|
+
DIVERS = "37"
|
|
267
|
+
DIVERS_AUTRES = "38"
|
lbc/models/location.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
|
|
3
|
+
@dataclass
|
|
4
|
+
class Location:
|
|
5
|
+
country_id: str
|
|
6
|
+
region_id: str
|
|
7
|
+
region_name: str
|
|
8
|
+
department_id: str
|
|
9
|
+
department_name: str
|
|
10
|
+
city_label: str
|
|
11
|
+
city: str
|
|
12
|
+
zipcode: str
|
|
13
|
+
lat: float
|
|
14
|
+
lng: float
|
|
15
|
+
source: str
|
|
16
|
+
provider: str
|
|
17
|
+
is_shape: bool
|
lbc/models/owner.py
ADDED
lbc/models/proxy.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from typing import Union, Optional
|
|
3
|
+
|
|
4
|
+
@dataclass
|
|
5
|
+
class Proxy:
|
|
6
|
+
host: str
|
|
7
|
+
port: Union[str, int]
|
|
8
|
+
username: Optional[str] = None
|
|
9
|
+
password: Optional[str] = None
|
|
10
|
+
|
|
11
|
+
@property
|
|
12
|
+
def url(self):
|
|
13
|
+
if self.username and self.password:
|
|
14
|
+
return f"http://{self.username}:{self.password}@{self.host}:{self.port}"
|
|
15
|
+
else:
|
|
16
|
+
return f"http://{self.host}:{self.port}"
|
lbc/models/search.py
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
from .ad import Ad
|
|
2
|
+
from .attribute import Attribute
|
|
3
|
+
from .location import Location
|
|
4
|
+
from .owner import Owner
|
|
5
|
+
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from typing import List
|
|
8
|
+
from datetime import datetime
|
|
9
|
+
|
|
10
|
+
@dataclass
|
|
11
|
+
class Search:
|
|
12
|
+
total: int
|
|
13
|
+
total_all: int
|
|
14
|
+
total_pro: int
|
|
15
|
+
total_private: int
|
|
16
|
+
total_active: int
|
|
17
|
+
total_inactive: int
|
|
18
|
+
total_shippable: int
|
|
19
|
+
max_pages: int
|
|
20
|
+
ads: List[Ad]
|
|
21
|
+
|
|
22
|
+
@staticmethod
|
|
23
|
+
def build(raw: dict) -> "Search":
|
|
24
|
+
ads: List[Ad] = []
|
|
25
|
+
|
|
26
|
+
for raw_ad in raw.get("ads", []):
|
|
27
|
+
attributes: List[Attribute] = []
|
|
28
|
+
for raw_attribute in raw_ad.get("attributes", []):
|
|
29
|
+
attributes.append(
|
|
30
|
+
Attribute(
|
|
31
|
+
key=raw_attribute.get("key"),
|
|
32
|
+
key_label=raw_attribute.get("key_label"),
|
|
33
|
+
value=raw_attribute.get("value"),
|
|
34
|
+
value_label=raw_attribute.get("value_label"),
|
|
35
|
+
values=raw_attribute.get("values"),
|
|
36
|
+
values_label=raw_attribute.get("values_label"),
|
|
37
|
+
value_label_reader=raw_attribute.get("value_label_reader"),
|
|
38
|
+
generic=raw_attribute.get("generic")
|
|
39
|
+
)
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
raw_location: dict = raw.get("location", {})
|
|
43
|
+
location = Location(
|
|
44
|
+
country_id=raw_location.get("country_id"),
|
|
45
|
+
region_id=raw_location.get("region_id"),
|
|
46
|
+
region_name=raw_location.get("region_name"),
|
|
47
|
+
department_id=raw_location.get("department_id"),
|
|
48
|
+
department_name=raw_location.get("department_name"),
|
|
49
|
+
city_label=raw_location.get("city_label"),
|
|
50
|
+
city=raw_location.get("city"),
|
|
51
|
+
zipcode=raw_location.get("zipcode"),
|
|
52
|
+
lat=raw_location.get("lat"),
|
|
53
|
+
lng=raw_location.get("lng"),
|
|
54
|
+
source=raw_location.get("source"),
|
|
55
|
+
provider=raw_location.get("provider"),
|
|
56
|
+
is_shape=raw_location.get("is_shape")
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
raw_owner: dict = raw.get("owner", {})
|
|
60
|
+
owner = Owner(
|
|
61
|
+
store_id=raw_owner.get("store_id"),
|
|
62
|
+
user_id=raw_owner.get("user_id"),
|
|
63
|
+
type=raw_owner.get("type"),
|
|
64
|
+
name=raw_owner.get("name"),
|
|
65
|
+
no_salesmen=raw_owner.get("no_salesmen")
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
ads.append(
|
|
69
|
+
Ad(
|
|
70
|
+
id=raw_ad.get("list_id"),
|
|
71
|
+
first_publication_date=datetime.strptime(raw_ad.get("first_publication_date"), "%Y-%m-%d %H:%M:%S") if raw_ad.get("first_publication_date") else None,
|
|
72
|
+
expiration_date=datetime.strptime(raw_ad.get("expiration_date"), "%Y-%m-%d %H:%M:%S") if raw_ad.get("expiration_date") else None,
|
|
73
|
+
index_date=datetime.strptime(raw_ad.get("index_date"), "%Y-%m-%d %H:%M:%S") if raw_ad.get("index_date") else None,
|
|
74
|
+
status=raw_ad.get("status"),
|
|
75
|
+
category_id=raw_ad.get("category_id"),
|
|
76
|
+
category_name=raw_ad.get("category_name"),
|
|
77
|
+
subject=raw_ad.get("subject"),
|
|
78
|
+
body=raw_ad.get("body"),
|
|
79
|
+
brand=raw_ad.get("brand"),
|
|
80
|
+
ad_type=raw_ad.get("ad_type"),
|
|
81
|
+
url=raw_ad.get("url"),
|
|
82
|
+
price=raw_ad.get("price_cents") / 100 if raw_ad.get("price_cents") else None,
|
|
83
|
+
images=raw_ad.get("images", {}).get("urls_large"),
|
|
84
|
+
attributes=attributes,
|
|
85
|
+
location=location,
|
|
86
|
+
owner=owner,
|
|
87
|
+
has_phone=raw_ad.get("has_phone")
|
|
88
|
+
)
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
return Search(
|
|
92
|
+
total=raw.get("total"),
|
|
93
|
+
total_all=raw.get("total_all"),
|
|
94
|
+
total_pro=raw.get("total_pro"),
|
|
95
|
+
total_private=raw.get("total_private"),
|
|
96
|
+
total_active=raw.get("total_active"),
|
|
97
|
+
total_inactive=raw.get("total_inactive"),
|
|
98
|
+
total_shippable=raw.get("total_shippable"),
|
|
99
|
+
max_pages=raw.get("max_pages"),
|
|
100
|
+
ads=ads
|
|
101
|
+
)
|
lbc/session.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
from .models import Proxy
|
|
2
|
+
|
|
3
|
+
from curl_cffi import requests
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
class Session:
|
|
7
|
+
def __init__(self, proxy: Optional[Proxy] = None):
|
|
8
|
+
self._session = self._init_session(proxy=proxy)
|
|
9
|
+
self._proxy = proxy
|
|
10
|
+
|
|
11
|
+
def _init_session(self, proxy: Optional[Proxy] = None) -> requests.Session:
|
|
12
|
+
"""
|
|
13
|
+
Initializes an HTTP session with optional proxy and browser impersonation.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
proxy (Optional[Proxy], optional): Proxy configuration to use for the session. If provided, it will be applied to both HTTP and HTTPS traffic.
|
|
17
|
+
|
|
18
|
+
Returns:
|
|
19
|
+
requests.Session: A configured session instance ready to send requests.
|
|
20
|
+
"""
|
|
21
|
+
session = requests.Session(
|
|
22
|
+
impersonate="firefox",
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
if proxy:
|
|
26
|
+
session.proxies = {
|
|
27
|
+
"http": proxy.url,
|
|
28
|
+
"https": proxy.url
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return session
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
def session(self):
|
|
35
|
+
return self._session
|
|
36
|
+
|
|
37
|
+
@property
|
|
38
|
+
def proxy(self):
|
|
39
|
+
return self._proxy
|
lbc/utils.py
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
from .models import Category, AdType, OwnerType, Sort, Region, Department, City
|
|
2
|
+
from .exceptions import InvalidValue
|
|
3
|
+
|
|
4
|
+
from typing import Optional, Union, List
|
|
5
|
+
|
|
6
|
+
def build_search_payload_with_args(
|
|
7
|
+
text: Optional[str] = None,
|
|
8
|
+
category: Category = Category.TOUTES_CATEGORIES,
|
|
9
|
+
sort: Sort = Sort.RELEVANCE,
|
|
10
|
+
locations: Optional[Union[List[Union[Region, Department, City]], Union[Region, Department, City]]] = None,
|
|
11
|
+
limit: int = 35,
|
|
12
|
+
limit_alu: int = 3,
|
|
13
|
+
page: int = 1,
|
|
14
|
+
ad_type: AdType = AdType.OFFER,
|
|
15
|
+
owner_type: Optional[OwnerType] = None,
|
|
16
|
+
search_in_title_only: bool = False,
|
|
17
|
+
**kwargs
|
|
18
|
+
) -> dict:
|
|
19
|
+
payload = {
|
|
20
|
+
"filters": {
|
|
21
|
+
"category": {
|
|
22
|
+
"id": category.value
|
|
23
|
+
},
|
|
24
|
+
"enums": {
|
|
25
|
+
"ad_type": [
|
|
26
|
+
ad_type.value
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
"keywords": {
|
|
30
|
+
"text": text
|
|
31
|
+
},
|
|
32
|
+
"location": {}
|
|
33
|
+
},
|
|
34
|
+
"limit": limit,
|
|
35
|
+
"limit_alu": limit_alu,
|
|
36
|
+
"offset": limit * (page - 1),
|
|
37
|
+
"disable_total": True,
|
|
38
|
+
"extend": True,
|
|
39
|
+
"listing_source": "direct-search" if page == 1 else "pagination"
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
# Text
|
|
43
|
+
if text:
|
|
44
|
+
payload["filters"]["keywords"] = {
|
|
45
|
+
"text": text
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
# Owner Type
|
|
49
|
+
if owner_type:
|
|
50
|
+
payload["owner_type"] = owner_type.value
|
|
51
|
+
|
|
52
|
+
# Sort
|
|
53
|
+
sort_by, sort_order = sort.value
|
|
54
|
+
payload["sort_by"] = sort_by
|
|
55
|
+
if sort_order:
|
|
56
|
+
payload["sort_order"] = sort_order
|
|
57
|
+
|
|
58
|
+
# Location
|
|
59
|
+
if locations and not isinstance(locations, list):
|
|
60
|
+
locations = [locations]
|
|
61
|
+
|
|
62
|
+
if locations:
|
|
63
|
+
payload["filters"]["location"] = {
|
|
64
|
+
"locations": []
|
|
65
|
+
}
|
|
66
|
+
for location in locations:
|
|
67
|
+
match location:
|
|
68
|
+
case Region():
|
|
69
|
+
payload["filters"]["location"]["locations"].append(
|
|
70
|
+
{
|
|
71
|
+
"locationType": "region",
|
|
72
|
+
"region_id": location.value[0]
|
|
73
|
+
}
|
|
74
|
+
)
|
|
75
|
+
case Department():
|
|
76
|
+
payload["filters"]["location"]["locations"].append(
|
|
77
|
+
{
|
|
78
|
+
"locationType": "department",
|
|
79
|
+
"region_id": location.value[0],
|
|
80
|
+
"department_id": location.value[2]
|
|
81
|
+
}
|
|
82
|
+
)
|
|
83
|
+
case City():
|
|
84
|
+
payload["filters"]["location"]["locations"].append(
|
|
85
|
+
{
|
|
86
|
+
"area": {
|
|
87
|
+
"lat": location.lat,
|
|
88
|
+
"lng": location.lng,
|
|
89
|
+
"radius": location.radius
|
|
90
|
+
},
|
|
91
|
+
"city": location.city,
|
|
92
|
+
"label": f"{location.city} (toute la ville)" if location.city else None,
|
|
93
|
+
"locationType": "city"
|
|
94
|
+
}
|
|
95
|
+
)
|
|
96
|
+
case _:
|
|
97
|
+
raise InvalidValue("The provided location is invalid. It must be an instance of Region, Department, or City.")
|
|
98
|
+
|
|
99
|
+
# Search in title only
|
|
100
|
+
if text:
|
|
101
|
+
if search_in_title_only:
|
|
102
|
+
payload["filters"]["keywords"]["type"] = "subject"
|
|
103
|
+
|
|
104
|
+
if kwargs:
|
|
105
|
+
for key, value in kwargs.items():
|
|
106
|
+
if not isinstance(value, (list, tuple)):
|
|
107
|
+
raise InvalidValue(f"The value of '{key}' must be a list or a tuple.")
|
|
108
|
+
# Range
|
|
109
|
+
if all(isinstance(x, int) for x in value):
|
|
110
|
+
if len(value) == 1:
|
|
111
|
+
raise InvalidValue(f"The value of '{key}' must be a list or tuple with at least two elements.")
|
|
112
|
+
|
|
113
|
+
if not "ranges" in payload["filters"]:
|
|
114
|
+
payload["filters"]["ranges"] = {}
|
|
115
|
+
|
|
116
|
+
payload["filters"]["ranges"][key] = {
|
|
117
|
+
"min": value[0],
|
|
118
|
+
"max": value[1]
|
|
119
|
+
}
|
|
120
|
+
# Enum
|
|
121
|
+
elif all(isinstance(x, str) for x in value):
|
|
122
|
+
payload["filters"]["enums"]["key"] = value
|
|
123
|
+
else:
|
|
124
|
+
raise InvalidValue(f"The value of '{key}' must be a list or tuple containing only integers or only strings.")
|
|
125
|
+
|
|
126
|
+
return payload
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lbc
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Unofficial client for Leboncoin API
|
|
5
|
+
Project-URL: Homepage, https://github.com/etienne-hd/lbc-py
|
|
6
|
+
Project-URL: Repository, https://github.com/etienne-hd/lbc-py
|
|
7
|
+
Project-URL: Changelog, https://github.com/etienne-hd/lbc-py/blob/main/CHANGELOG.md
|
|
8
|
+
Author-email: Etienne HODE <hode.etienne@gmail.com>
|
|
9
|
+
Maintainer-email: Etienne HODE <hode.etienne@gmail.com>
|
|
10
|
+
License: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: api,lbc,leboncoin,wrapper
|
|
13
|
+
Requires-Python: >=3.9
|
|
14
|
+
Requires-Dist: curl-cffi==0.11.3
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# lbc
|
|
18
|
+
[](https://pypi.org/project/lbc)
|
|
19
|
+

|
|
20
|
+
[](https://github.com/etienne-hd/lbc/blob/master/LICENSE)
|
|
21
|
+
|
|
22
|
+
**Unofficial client for Leboncoin API**
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
import lbc
|
|
26
|
+
|
|
27
|
+
client = lbc.Client()
|
|
28
|
+
|
|
29
|
+
location = lbc.City(
|
|
30
|
+
lat=48.85994982004764,
|
|
31
|
+
lng=2.33801967847424,
|
|
32
|
+
radius=10_000, # 10 km
|
|
33
|
+
city="Paris"
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
result = client.search(
|
|
37
|
+
text="maison",
|
|
38
|
+
locations=[location],
|
|
39
|
+
page=1,
|
|
40
|
+
limit=35,
|
|
41
|
+
sort=lbc.Sort.NEWEST,
|
|
42
|
+
ad_type=lbc.AdType.OFFER,
|
|
43
|
+
category=lbc.Category.IMMOBILIER,
|
|
44
|
+
square=[200, 400],
|
|
45
|
+
price=[300_000, 700_000]
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
for ad in result.ads:
|
|
49
|
+
print(ad.url, ad.subject, ad.price)
|
|
50
|
+
```
|
|
51
|
+
*lbc is not affiliated with, endorsed by, or in any way associated with Leboncoin or its services. Use at your own risk.*
|
|
52
|
+
|
|
53
|
+
## Installation
|
|
54
|
+
Required Python 3.9+
|
|
55
|
+
```bash
|
|
56
|
+
pip install lbc
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Usage
|
|
60
|
+
### Client
|
|
61
|
+
To create client you need to use lbc.Client class
|
|
62
|
+
```python
|
|
63
|
+
import lbc
|
|
64
|
+
|
|
65
|
+
client = lbc.Client()
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
#### Proxy
|
|
69
|
+
You can also configure the client to use a proxy by providing a `Proxy` object:
|
|
70
|
+
```python
|
|
71
|
+
proxy = lbc.Proxy(
|
|
72
|
+
host=...,
|
|
73
|
+
port=...,
|
|
74
|
+
username=...,
|
|
75
|
+
password=...
|
|
76
|
+
)
|
|
77
|
+
client = lbc.Client(proxy=proxy)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
### Search
|
|
82
|
+
|
|
83
|
+
To perform a search, use the `client.search` method.
|
|
84
|
+
|
|
85
|
+
This function accepts keyword arguments (`**kwargs`) to customize your query.
|
|
86
|
+
For example, if you're looking for houses that include both land and parking, you can specify:
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
real_estate_type=["3", "4"]
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
These values correspond to what you’d find in a typical Leboncoin URL, like:
|
|
93
|
+
|
|
94
|
+
```
|
|
95
|
+
https://www.leboncoin.fr/recherche?category=9&text=maison&...&real_estate_type=3,4
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Here's a complete example of a search query:
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
client.search(
|
|
102
|
+
text="maison",
|
|
103
|
+
locations=[location],
|
|
104
|
+
page=1,
|
|
105
|
+
limit=35,
|
|
106
|
+
limit_alu=0,
|
|
107
|
+
sort=lbc.Sort.NEWEST,
|
|
108
|
+
ad_type=lbc.AdType.OFFER,
|
|
109
|
+
category=lbc.Category.IMMOBILIER,
|
|
110
|
+
owner_type=lbc.OwnerType.ALL,
|
|
111
|
+
search_in_title_only=True,
|
|
112
|
+
square=[200, 400],
|
|
113
|
+
price=[300_000, 700_000],
|
|
114
|
+
)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Location
|
|
118
|
+
|
|
119
|
+
The `locations` parameter accepts a list of one or more location objects. You can use one of the following:
|
|
120
|
+
|
|
121
|
+
* `lbc.Region(...)`
|
|
122
|
+
* `lbc.Department(...)`
|
|
123
|
+
* `lbc.City(...)`
|
|
124
|
+
|
|
125
|
+
Each one corresponds to a different level of geographic granularity.
|
|
126
|
+
|
|
127
|
+
#### City example
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
location = lbc.City(
|
|
131
|
+
lat=48.85994982004764,
|
|
132
|
+
lng=2.33801967847424,
|
|
133
|
+
radius=10_000, # in meters
|
|
134
|
+
city="Paris"
|
|
135
|
+
)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
#### Region / Department example
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
from lbc import Region, Department
|
|
142
|
+
|
|
143
|
+
region = Region.ILE_DE_FRANCE
|
|
144
|
+
department = Department.PARIS
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### 403 Error
|
|
148
|
+
|
|
149
|
+
If you encounter a **403 Forbidden** error, it usually means your requests are being blocked by [Datadome](https://datadome.co).
|
|
150
|
+
To resolve this:
|
|
151
|
+
|
|
152
|
+
* Try reducing the request frequency (add delays between requests).
|
|
153
|
+
* If you're using a proxy, make sure it is **clean** and preferably located in **France**.
|
|
154
|
+
|
|
155
|
+
Using residential or mobile proxies can also help avoid detection.
|
|
156
|
+
|
|
157
|
+
## License
|
|
158
|
+
|
|
159
|
+
This project is licensed under the MIT License.
|
|
160
|
+
|
|
161
|
+
## Support
|
|
162
|
+
|
|
163
|
+
<a href="https://www.buymeacoffee.com/etienneh" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>
|
|
164
|
+
|
|
165
|
+
You can contact me via [Telegram](https://t.me/etienne_hd) or [Discord](https://discord.com/users/1153975318990827552) if you need help with scraping services or want to write a library.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
lbc/__init__.py,sha256=eX6byBwXr1WwoIUziH6rXJtjvbU6niBqQtYZRJyTsnk,48
|
|
2
|
+
lbc/client.py,sha256=oiay3h_4pRD4To5u5qsBko4XdsxrlueP6LMuI8-qQbk,4484
|
|
3
|
+
lbc/exceptions.py,sha256=CL0WSsVhyzSuwa6GEoPSZ2dMERGp-QaqBKth28kXbXQ,418
|
|
4
|
+
lbc/session.py,sha256=9r4-e1G5kRzg3rSp5bzrPT8rfWWNvwy4ZmgNdRigSFs,1074
|
|
5
|
+
lbc/utils.py,sha256=kITzURYaWHSjisINybRAPYsivwzNW6rLGAMweoC4Wwg,4367
|
|
6
|
+
lbc/models/__init__.py,sha256=yoHpH997lhFBFXI7-_E_Vh1-RZ9QqSot_VkSXw39jQk,95
|
|
7
|
+
lbc/models/ad.py,sha256=IPPbpgKtH_HNvlQhsVQg6zSTQqvMunM7-l4TsHyl9-E,641
|
|
8
|
+
lbc/models/attribute.py,sha256=wfWUKKQpkXOrOKklOx5rGuvG2gjtyxTncmRzvtTFlGw,290
|
|
9
|
+
lbc/models/city.py,sha256=N9xdmYiI1tLfB4xTHfuilY9x9NzmIhzRho-GpUxm194,171
|
|
10
|
+
lbc/models/enums.py,sha256=mKVC-l-l9sUW1uEnaOAQPQtXLVb0qwfCiTTbKGbbvAw,11831
|
|
11
|
+
lbc/models/location.py,sha256=xvBmU2cwA5AHV7SBiRYNOL-ooGdomjv9VD98aZTNkk4,303
|
|
12
|
+
lbc/models/owner.py,sha256=KEV8ID8O94DzTHd3MIzFHI8vetJfo8waQ-ETNBbCy8c,143
|
|
13
|
+
lbc/models/proxy.py,sha256=Ar4hAk9sdZm1gDZOaPoyXu5pNIMaY2Ezq6hWoLb1-1Y,433
|
|
14
|
+
lbc/models/search.py,sha256=i8wiVaQQB0i8fNuGSlB6fnozvhoVNBcle3Ee6i96zcQ,4196
|
|
15
|
+
lbc-1.0.0.dist-info/METADATA,sha256=0fSl97cbalmOe6FnlVUhA6yJhXi3VgSlKYe6HIkaGB8,4223
|
|
16
|
+
lbc-1.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
17
|
+
lbc-1.0.0.dist-info/licenses/LICENSE,sha256=TOjGtMeKbX_qhoSU7ROWSF0GueuzHLzU_W8tleC6jfU,1070
|
|
18
|
+
lbc-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Étienne Hodé
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|