Skip to content

Commit

Permalink
fix: comments task fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
fmelihh committed Nov 9, 2024
1 parent a16bcc9 commit 59bc4e4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
21 changes: 15 additions & 6 deletions src/recommendation_engine/app/tasks/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class CommentTask(Task):

def run(self, *args, **kwargs):
for provider in Providers:
if provider == Providers.GETIR:
continue

counter = 0
while True:
restaurants = RestaurantService.retrieve_restaurants_with_pagination(
Expand All @@ -23,17 +26,23 @@ def run(self, *args, **kwargs):
break

for restaurant in restaurants:
comment_restaurant_id = (
restaurant.restaurant_slug.split("-")[-1]
if provider == Providers.YEMEK_SEPETI
else restaurant.restaurant_id
)
comment_service = CommentService()
comment_extractor = CommentsExtractorService(
provider_type=provider, restaurant_id=restaurant.restaurant_id
provider_type=provider, restaurant_id=comment_restaurant_id
)

comment_list = comment_extractor.crawl()
comment_service.parse_all_comments(
restaurant_id=restaurant.restaurant_id,
provider=provider.value,
comments=comment_list,
)
if len(comment_list) > 0:
comment_service.parse_all_comments(
restaurant_id=restaurant.restaurant_id,
provider=provider.value,
comments=comment_list,
)

counter += 1

Expand Down
15 changes: 8 additions & 7 deletions src/recommendation_engine/app/tasks/restaurant.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ def run(self, *args, **kwargs):
)

restaurant_list = restaurant_extractor.crawl()
restaurant_service.parse_all_restaurants(
provider=provider.value,
restaurants=restaurant_list,
lat=lat,
lon=lon,
city=city["name"].upper(),
)
if len(restaurant_list) > 0:
restaurant_service.parse_all_restaurants(
provider=provider.value,
restaurants=restaurant_list,
lat=lat,
lon=lon,
city=city["name"].upper(),
)


celery_application.register_task(RestaurantTask)
Expand Down
4 changes: 2 additions & 2 deletions tests/app/domain/comments/test_yemeksepeti_comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@


def test_yemeksepeti_comments():
yemek_sepeti_comments = YemekSepetiComments(restaurant_id="nrp4")
yemek_sepeti_comments = YemekSepetiComments(restaurant_id="pt76")
results = yemek_sepeti_comments.process(process_limit=1)
assert isinstance(results, list)
assert len(results) > 0


def test_getir_comments_with_dto():
yemek_sepeti_comments = YemekSepetiComments(restaurant_id="nrp4")
yemek_sepeti_comments = YemekSepetiComments(restaurant_id="pt76")
results = yemek_sepeti_comments.process(process_limit=1)
[
CommentDto(
Expand Down

0 comments on commit 59bc4e4

Please sign in to comment.