diff --git a/src/recommendation_engine/app/tasks/comments.py b/src/recommendation_engine/app/tasks/comments.py index 7612656..933c23c 100644 --- a/src/recommendation_engine/app/tasks/comments.py +++ b/src/recommendation_engine/app/tasks/comments.py @@ -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( @@ -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 diff --git a/src/recommendation_engine/app/tasks/restaurant.py b/src/recommendation_engine/app/tasks/restaurant.py index 5203c34..29fa1f7 100644 --- a/src/recommendation_engine/app/tasks/restaurant.py +++ b/src/recommendation_engine/app/tasks/restaurant.py @@ -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) diff --git a/tests/app/domain/comments/test_yemeksepeti_comments.py b/tests/app/domain/comments/test_yemeksepeti_comments.py index 3059dde..712cffa 100644 --- a/tests/app/domain/comments/test_yemeksepeti_comments.py +++ b/tests/app/domain/comments/test_yemeksepeti_comments.py @@ -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(