Skip to content

Commit

Permalink
feat: yemeksepeti comments were developed.
Browse files Browse the repository at this point in the history
  • Loading branch information
fmelihh committed May 12, 2024
1 parent 0673a56 commit 846d459
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions src/recommendation_engine/app/domain/menu/values/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions tests/app/domain/comments/yemeksepeti.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 846d459

Please sign in to comment.