-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathoptions.py
200 lines (146 loc) · 4.11 KB
/
options.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
import sys
from dataclasses import dataclass
from enum import Enum
from typing import List
class Option():
def get_params(self):
return {}
@dataclass
class PriceOption(Option):
min: int = 0
max: int = sys.maxsize
PARAM_KEY = "rentalPrice"
def get_params(self):
return {
f"{self.PARAM_KEY}_from": self.min,
f"{self.PARAM_KEY}_to": self.max,
}
class SalePriceOption(PriceOption):
PARAM_KEY = "salePrice"
@dataclass
class BedOption(Option):
min: int = 0
max: int = sys.maxsize
PARAM_KEY = "numBeds"
def get_params(self):
return {
f"{BedOption.PARAM_KEY}_from": self.min,
f"{BedOption.PARAM_KEY}_to": self.max,
}
@dataclass
class LeaseLengthOption(Option):
min: int = 0
max: int = sys.maxsize
PARAM_KEY = "leaseLength"
def get_params(self):
return {
f"{LeaseLengthOption.PARAM_KEY}_from": self.min,
f"{LeaseLengthOption.PARAM_KEY}_to": self.max,
}
class PropertyType(Enum):
ALL = "EMPTY"
HOUSE = "houses"
APARTMENT = "apartments"
STUDIO_APARTMENT = "studio-apartments"
DETACHED_HOUSE = "detached-houses"
SEMI_DETACHED_HOUSE = "semi-detached-houses"
TERRACED_HOUSE = "terraced-houses"
END_OF_TERRACE_HOUSE = "end-of-terrace-houses"
TOWNHOUSE = "townhouses"
DUPLEX = "duplexes"
BUNGALOW = "bungalows"
SITE = "sites"
@dataclass
class PropertyTypesOption(Option):
property_types: List[PropertyType]
def get_params(self):
if PropertyType.ALL in self.property_types:
# If we want "all", don't submit any params
return {}
return {
"propertyType": [propType.value for propType in self.property_types]
}
class Facility(Enum):
NONE = "EMPTY"
ALARM = "alarm"
CABLE_TELEVISION = "cable-television"
DISHWASHER = "dishwasher"
GARDEN_PATIO_BALCONY = "garden-patio-balcony"
CENTRAL_HEATING = "central-heating"
INTERNET = "internet"
MICROWAVE = "microwave"
PARKING = "parking"
PETS_ALLOWED = "pets-allowed"
SMOKING = "smoking"
SERVICED_PROPERTY = "serviced-property"
DRYER = "dryer"
WASHING_MACHINE = "washing-machine"
WHEELCHAIR_ACCESS = "wheelchair-access"
@dataclass
class FacilitiesOption(Option):
facilities: List[Facility]
def get_params(self):
if self.facilities == [Facility.NONE]:
# If facility list specifies none, don't return params
return {}
return {
"facilities": [facil.value for facil in self.facilities]
}
class MediaType(Enum):
ALL = "EMPTY"
VIDEO = "video"
VIRTUAL_TOUR = "virtual-tour"
@dataclass
class MediaTypesOption(Option):
media_types: List[MediaType]
def get_params(self):
if MediaType.ALL in self.media_types:
# If we want "all", don't submit any params
return {}
return {
"mediaTypes": [propType.value for propType in self.media_types]
}
@dataclass
class KeywordsOption(Option):
terms = List[str]
def get_params(self):
return {
"terms": self.terms
}
class AdState(Enum):
AVAILABLE = "published"
AGREED = "sale-agreed"
@dataclass
class AdStateOption(Option):
ad_state: AdState
def get_params(self):
return {
"adState": self.ad_state.value
}
class Sort(Enum):
BEST_MATCH = "EMPTY"
MOST_RECENT = "publishDateDesc"
PRICE_ASCENDING = "priceAsc"
PRICE_DESCENDING = "priceDesc"
@dataclass
class SortOption(Option):
sort: Sort
def get_params(self):
if self.sort == Sort.BEST_MATCH:
return {}
return {
"sort": self.sort.value
}
class Furnishing(Enum):
ALL_FURNISHINGS = "EMPTY"
FURNISHED = "furnished"
UNFURNISHED = "unfurnished"
@dataclass
class FurnishingOption(Option):
furnishing: Furnishing
def get_params(self):
if self.furnishing == Furnishing.ALL_FURNISHINGS:
return {}
return {
"furnishing": self.furnishing.value
}