Skip to content

Commit

Permalink
updated details fro advert
Browse files Browse the repository at this point in the history
  • Loading branch information
Yariki committed Mar 14, 2024
1 parent 8057537 commit df25f02
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dimria/dimria_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
from pydantic.tools import parse_obj_as

from dimria.models.SearchResponse import SearchResponse
from dimria.models.searchresponse import SearchResponse
from dimria.models.AdvertDetails import AdvertDetails

API_KEY = os.getenv("DIMRIA_API_KEY")
Expand Down
15 changes: 15 additions & 0 deletions dimria/handle_details.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

def build_ptoho_url(file):
split = file.split(".")
file = split[0] + "xl." + split[1]
return f'https://cdn.riastatic.com/photos/{file}'

def parse_photos(photos):
result = []
for photoId in photos:
photo = photos[photoId]
result.append(build_ptoho_url(photo["file"]))
return result

def build_main_advert_url(url):
return f'https://dom.ria.com/uk/{url}'
9 changes: 8 additions & 1 deletion dimria/models/AdvertDetailsResponse.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@

class AdvertDetailsResponse:

def __init__(self, advert_id, city_name, description, price, currency,floor, rooms_count) -> None:
def __init__(self, advert_id, city_name, description, price, currency,floor, rooms_count, main_photo, lat, lon, building_name, url, photos = []) -> None:
self.advert_id = advert_id
self.city_name = city_name
self.description = description
self.price = price
self.currency = currency
self.floor = floor
self.rooms_count = rooms_count
self.main_photo = main_photo
self.lat = lat
self.lon = lon
self.building_name = building_name
self.url = url
self.photos = photos,



class AdvertDetailsResponseEncoder (JSONEncoder):
Expand Down
19 changes: 16 additions & 3 deletions function_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from dimria.cosmos_db import process_advert

from dimria.dimria_requests import search_adverts, get_advert_details
from dimria.handle_details import build_ptoho_url, parse_photos, build_main_advert_url
from dimria.models.AdvertDetails import AdvertDetails
from dimria.models.AdvertsList import AdvertsList
from dimria.models.AdvertDetailsResponse import AdvertDetailsResponse, AdvertDetailsResponseEncoder
Expand All @@ -18,7 +19,7 @@

################################################################################################

#@app.route(route="search_adverts", auth_level=func.AuthLevel.ANONYMOUS)
# @app.route(route="search_adverts", auth_level=func.AuthLevel.ANONYMOUS)
@app.schedule(schedule="0 */30 * * * *", arg_name="mytimer", run_on_startup=True, use_monitor=False)
def timer_search_adverts(mytimer: func.TimerRequest) -> None: # req: func.HttpRequest func.HttpResponse: # # mytimer: func.TimerRequest

Expand Down Expand Up @@ -116,7 +117,13 @@ def get_advert_details(req: func.HttpRequest) -> func.HttpResponse:
rooms_count = resultRequest['rooms_count']
currency_type_uk = resultRequest['currency_type_uk']
description = resultRequest['description_uk']
floor=resultRequest['floor_info']
floor=resultRequest['floor']
photos = parse_photos(resultRequest['photos'])
main_photo = build_ptoho_url(resultRequest['main_photo'])
lat = resultRequest['latitude']
lon = resultRequest['longitude']
building_name = resultRequest['user_newbuild_name']
url = build_main_advert_url(resultRequest['beautiful_url'])

resultResponse: AdvertDetailsResponse = AdvertDetailsResponse(
advert_id=advert_id,
Expand All @@ -125,7 +132,13 @@ def get_advert_details(req: func.HttpRequest) -> func.HttpResponse:
rooms_count=rooms_count,
currency=currency_type_uk,
description=description,
floor=floor
floor=floor,
main_photo=main_photo,
lat = lat,
lon = lon,
building_name = building_name,
url = url,
photos=photos
)

data = json.dumps(resultResponse, cls=AdvertDetailsResponseEncoder)
Expand Down

0 comments on commit df25f02

Please sign in to comment.