diff --git a/src/recommendation_engine/app/domain/comments/entity/yemek_sepeti.py b/src/recommendation_engine/app/domain/comments/entity/yemek_sepeti.py index ec48f41..79ea379 100644 --- a/src/recommendation_engine/app/domain/comments/entity/yemek_sepeti.py +++ b/src/recommendation_engine/app/domain/comments/entity/yemek_sepeti.py @@ -8,7 +8,7 @@ from ..values.yemeksepeti import YemeksepetiCommentValue -class YemekSepeti(BaseEntity, Processor): +class YemekSepetiComments(BaseEntity, Processor): HEADERS = { "accept": "application/json, text/plain, */*", "accept-language": "en-US,en;q=0.9", @@ -40,16 +40,16 @@ def __init__(self, restaurant_id: str): {{ "global_entity_id": "YS_TR", "limit": 30, - "created_at": "desc" - "has_dish": True - "nextPageKey": {next_page_key} + "created_at": "desc", + "has_dish": True, + "nextPageKey": "{next_page_key}" }} """, ) self.comment_stack = EntityValueStack() def _iterate_over_comments(self) -> Generator[dict, None, None]: - next_page_key = None + next_page_key = "" while True: request_template = ( self.filter_and_search_payload.retrieve_formatted_request( @@ -96,4 +96,12 @@ def transform_unstructured_data(record_value: dict) -> YemeksepetiCommentValue: def process( self, process_limit: int | None = None ) -> list[YemeksepetiCommentValue]: - pass + for comment_list in self._iterate_over_comments(): + for comment in comment_list: + comment = self.transform_unstructured_data(comment) + self.comment_stack.add_value(comment) + + if process_limit is not None and len(self.comment_stack) >= process_limit: + break + + return self.comment_stack.retrieve_values() diff --git a/src/recommendation_engine/app/domain/comments/values/yemeksepeti/comment.py b/src/recommendation_engine/app/domain/comments/values/yemeksepeti/comment.py index e5fa5a4..07d9180 100644 --- a/src/recommendation_engine/app/domain/comments/values/yemeksepeti/comment.py +++ b/src/recommendation_engine/app/domain/comments/values/yemeksepeti/comment.py @@ -30,7 +30,7 @@ def validate_created_at(self) -> datetime.datetime | None: if not isinstance(self.created_at, str): raise ValueError("Invalid created_at type expected.") - pendulum_date = pendulum.from_format(self.created_at, "YYYY-MM-DDTHH:mm:ss") + pendulum_date = pendulum.from_format(self.created_at.replace("Z", ""), "YYYY-MM-DDTHH:mm:ss") return datetime.datetime( year=pendulum_date.year, month=pendulum_date.month, @@ -44,7 +44,7 @@ def validate_updated_at(self) -> datetime.datetime | None: if not isinstance(self.updated_at, str): raise ValueError("Invalid created_at type expected.") - pendulum_date = pendulum.from_format(self.updated_at, "YYYY-MM-DDTHH:mm:ss") + pendulum_date = pendulum.from_format(self.updated_at.replace("Z", ""), "YYYY-MM-DDTHH:mm:ss") return datetime.datetime( year=pendulum_date.year, month=pendulum_date.month, @@ -122,10 +122,10 @@ def validate_replies(self) -> list[YemeksepetiReplies] | None: replies_list = [] for reply in self.replies: created_at = pendulum.from_format( - reply["created_at"], "YYYY-MM-DDTHH:mm:ss" + reply["createdAt"].replace("Z", ""), "YYYY-MM-DDTHH:mm:ss" ) updated_at = pendulum.from_format( - reply["updated_at"], "YYYY-MM-DDTHH:mm:ss" + reply["updatedAt"].replace("Z", ""), "YYYY-MM-DDTHH:mm:ss" ) created_at = datetime.datetime( year=created_at.year, diff --git a/src/recommendation_engine/app/domain/menu/values/__init__.py b/src/recommendation_engine/app/domain/menu/values/__init__.py index 5632575..dd972b6 100644 --- a/src/recommendation_engine/app/domain/menu/values/__init__.py +++ b/src/recommendation_engine/app/domain/menu/values/__init__.py @@ -1,4 +1,2 @@ from .price import Price -from .menu import MenuValue -from .menu_stack import MenuStack -from .request_value import RequestValue +from .menu import MenuValue \ No newline at end of file diff --git a/src/recommendation_engine/app/domain/restaurants/values/__init__.py b/src/recommendation_engine/app/domain/restaurants/values/__init__.py index 0bcdfdc..01eddfb 100644 --- a/src/recommendation_engine/app/domain/restaurants/values/__init__.py +++ b/src/recommendation_engine/app/domain/restaurants/values/__init__.py @@ -1,7 +1,5 @@ from .geo import GeoValue -from .request import RequestValue from .restaurant import RestaurantValue -from .restaurant_stack import RestaurantStack from .delivery_time import DeliveryTime from .price import Price from .rating_count import RatingCount diff --git a/tests/app/domain/comments/yemeksepeti.py b/tests/app/domain/comments/yemeksepeti.py new file mode 100644 index 0000000..5c5bceb --- /dev/null +++ b/tests/app/domain/comments/yemeksepeti.py @@ -0,0 +1,10 @@ +from src.recommendation_engine.app.domain.comments.entity.yemek_sepeti import ( + YemekSepetiComments, +) + + +def test_yemeksepeti_comments(): + yemek_sepeti_comments = YemekSepetiComments(restaurant_id="nrp4") + results = yemek_sepeti_comments.process() + assert isinstance(results, list) + assert len(results) > 0