Compare commits
5
Commits
9335b782c2
..
dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c797cac291 | ||
|
|
6510a001f2 | ||
|
|
a802613778 | ||
|
|
ec9659d51e | ||
|
|
ee2b18bdb5 |
@@ -1,57 +0,0 @@
|
|||||||
from pydantic import BaseModel
|
|
||||||
import json
|
|
||||||
|
|
||||||
|
|
||||||
class RegionNames(BaseModel):
|
|
||||||
fullName: str
|
|
||||||
shortName: str
|
|
||||||
displayName: str
|
|
||||||
primaryDisplayName: str
|
|
||||||
secondaryDisplayName: str
|
|
||||||
lastSearchName: str
|
|
||||||
|
|
||||||
|
|
||||||
class EssId(BaseModel):
|
|
||||||
sourceName: str
|
|
||||||
sourceId: int
|
|
||||||
|
|
||||||
|
|
||||||
class Country(BaseModel):
|
|
||||||
name: str
|
|
||||||
isoCode2: str
|
|
||||||
isoCode3: str
|
|
||||||
|
|
||||||
|
|
||||||
class HierarchyInfo(BaseModel):
|
|
||||||
country: Country
|
|
||||||
|
|
||||||
|
|
||||||
class Coordinates(BaseModel):
|
|
||||||
lat: float
|
|
||||||
long: float
|
|
||||||
|
|
||||||
|
|
||||||
class GaiaRegionResult(BaseModel):
|
|
||||||
index: int
|
|
||||||
gaiaId: int
|
|
||||||
type: str
|
|
||||||
regionNames: RegionNames
|
|
||||||
essId: EssId
|
|
||||||
coordinates: Coordinates
|
|
||||||
hierarchyInfo: HierarchyInfo
|
|
||||||
|
|
||||||
|
|
||||||
class SearchResults(BaseModel):
|
|
||||||
q: str
|
|
||||||
rid: str
|
|
||||||
rc: str
|
|
||||||
sr: list[GaiaRegionResult]
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
with open('locations_v3_search_example.json', 'r', encoding='utf-8') as json_file:
|
|
||||||
data = json.load(json_file)
|
|
||||||
results = SearchResults(**data)
|
|
||||||
print('\n'.join(
|
|
||||||
[result.regionNames.fullName for result in results.sr if result.type in ('CITY', 'NEIGHBORHOOD')])
|
|
||||||
)
|
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
from pydantic import BaseModel, Field
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
class RegionNames(BaseModel):
|
||||||
|
full_name: str = Field(alias='fullName')
|
||||||
|
short_name: str = Field(alias='shortName')
|
||||||
|
display_name: str = Field(alias='displayName')
|
||||||
|
primary_display_name: str = Field(alias='primaryDisplayName')
|
||||||
|
secondary_display_name: str = Field(alias='secondaryDisplayName')
|
||||||
|
last_search_name: str = Field(alias='lastSearchName')
|
||||||
|
|
||||||
|
|
||||||
|
class EssId(BaseModel):
|
||||||
|
source_name: str = Field(alias='sourceName')
|
||||||
|
source_id: int = Field(alias='sourceId')
|
||||||
|
|
||||||
|
|
||||||
|
class Country(BaseModel):
|
||||||
|
name: str
|
||||||
|
iso_code2: str = Field(alias='isoCode2')
|
||||||
|
iso_code3: str = Field(alias='isoCode3')
|
||||||
|
|
||||||
|
|
||||||
|
class HierarchyInfo(BaseModel):
|
||||||
|
country: Country
|
||||||
|
|
||||||
|
|
||||||
|
class Coordinates(BaseModel):
|
||||||
|
latitude: float = Field(alias='lat')
|
||||||
|
longitude: float = Field(alias='long')
|
||||||
|
|
||||||
|
|
||||||
|
class GaiaRegionResult(BaseModel):
|
||||||
|
index: int
|
||||||
|
gaia_id: int = Field(alias='gaiaId')
|
||||||
|
type: str
|
||||||
|
region_names: RegionNames = Field(alias='regionNames')
|
||||||
|
ess_id: EssId = Field(alias='essId')
|
||||||
|
coordinates: Coordinates
|
||||||
|
hierarchy_info: HierarchyInfo = Field(alias='hierarchyInfo')
|
||||||
|
|
||||||
|
|
||||||
|
class SearchResults(BaseModel):
|
||||||
|
query: str = Field(alias='q')
|
||||||
|
request_id: str = Field(alias='rid')
|
||||||
|
request_status: str = Field(alias='rc')
|
||||||
|
search_results: list[GaiaRegionResult] = Field(alias='sr')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
with open('locations_v3_search_example.json', 'r', encoding='utf-8') as json_file:
|
||||||
|
data = json.load(json_file)
|
||||||
|
results = SearchResults(**data)
|
||||||
|
print('\n'.join(
|
||||||
|
[result.region_names.full_name for result in results.search_results if result.type in ('CITY', 'NEIGHBORHOOD')])
|
||||||
|
)
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
from typing import Optional
|
||||||
|
from pydantic import BaseModel, Field
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
class PropertyReviewsSummary(BaseModel):
|
||||||
|
score: float
|
||||||
|
total: int
|
||||||
|
|
||||||
|
|
||||||
|
class DisplayPrice(BaseModel):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class LodgingEnrichedMessage(BaseModel):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class FormattedMoney(BaseModel):
|
||||||
|
formatted: str
|
||||||
|
accessibility_label: str = Field(alias='accessibilityLabel')
|
||||||
|
|
||||||
|
|
||||||
|
class DisplayPrice(BaseModel):
|
||||||
|
price: FormattedMoney
|
||||||
|
role: str
|
||||||
|
|
||||||
|
|
||||||
|
class PriceDisplayMessage(BaseModel):
|
||||||
|
line_items: list[DisplayPrice | LodgingEnrichedMessage] = Field(alias='lineItems')
|
||||||
|
|
||||||
|
|
||||||
|
class PropertyPriceOption(BaseModel):
|
||||||
|
formatted_display_price: str = Field(alias='formattedDisplayPrice')
|
||||||
|
|
||||||
|
|
||||||
|
class PropertyPrice(BaseModel):
|
||||||
|
options: list[PropertyPriceOption]
|
||||||
|
display_messages: list[PriceDisplayMessage] = Field(alias='displayMessages')
|
||||||
|
|
||||||
|
|
||||||
|
class Coordinates(BaseModel):
|
||||||
|
latitude: float
|
||||||
|
longitude: float
|
||||||
|
|
||||||
|
|
||||||
|
class MapMarker(BaseModel):
|
||||||
|
coordinates: Coordinates = Field(alias='latLong')
|
||||||
|
|
||||||
|
|
||||||
|
class DistanceFromDestination(BaseModel):
|
||||||
|
unit: str
|
||||||
|
value: float
|
||||||
|
|
||||||
|
|
||||||
|
class DestinationInfo(BaseModel):
|
||||||
|
distance_from_destination: DistanceFromDestination = Field(alias='distanceFromDestination')
|
||||||
|
|
||||||
|
|
||||||
|
class Image(BaseModel):
|
||||||
|
url: str
|
||||||
|
|
||||||
|
|
||||||
|
class PropertyImage(BaseModel):
|
||||||
|
image: Image
|
||||||
|
|
||||||
|
|
||||||
|
class Property(BaseModel):
|
||||||
|
id: int
|
||||||
|
name: str
|
||||||
|
property_image: PropertyImage = Field(alias='propertyImage')
|
||||||
|
destination_info: DestinationInfo = Field(alias='destinationInfo')
|
||||||
|
map_marker: MapMarker = Field(alias='mapMarker')
|
||||||
|
price: PropertyPrice
|
||||||
|
reviews: PropertyReviewsSummary
|
||||||
|
|
||||||
|
@property
|
||||||
|
def property_price_per_night(self) -> str:
|
||||||
|
try:
|
||||||
|
price_per_night = [j_price for j_price in self.price.display_messages[0].line_items
|
||||||
|
if j_price.role == 'LEAD'
|
||||||
|
][0].price.accessibility_label
|
||||||
|
except IndexError:
|
||||||
|
price_per_night = 'Index Error'
|
||||||
|
return price_per_night
|
||||||
|
|
||||||
|
@property
|
||||||
|
def reviews_score(self) -> float:
|
||||||
|
return self.reviews.score
|
||||||
|
|
||||||
|
@property
|
||||||
|
def reviews_amount(self) -> int:
|
||||||
|
return self.reviews.total
|
||||||
|
|
||||||
|
|
||||||
|
class PropertySearch(BaseModel):
|
||||||
|
properties: list[Property]
|
||||||
|
|
||||||
|
|
||||||
|
class Data(BaseModel):
|
||||||
|
property_search: PropertySearch = Field(alias='propertySearch')
|
||||||
|
|
||||||
|
|
||||||
|
class ApiResponse(BaseModel):
|
||||||
|
data: Data
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
with open('properties_v2_list_example.json', 'r', encoding='utf-8') as json_file:
|
||||||
|
data = json.load(json_file)
|
||||||
|
results = ApiResponse(**data)
|
||||||
|
# print('\n\n***\n\n'.join(str(i) for i in results.data.property_search.properties))
|
||||||
|
for i_property in results.data.property_search.properties:
|
||||||
|
property_price_per_night = i_property.property_price_per_night
|
||||||
|
property_rating_str = f'The score is {i_property.reviews_score} based on {i_property.reviews_amount} reviews'
|
||||||
|
print(
|
||||||
|
f'''
|
||||||
|
Property: {i_property.name} (id: {i_property.id})
|
||||||
|
{property_price_per_night} per night
|
||||||
|
{property_rating_str}
|
||||||
|
'''
|
||||||
|
)
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,4 @@
|
|||||||
|
psycopg2
|
||||||
|
requests
|
||||||
|
pydantic
|
||||||
|
pytelegrambotapi
|
||||||
Reference in New Issue
Block a user