-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
86 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
3 changes: 3 additions & 0 deletions
3
src/recommendation_engine/app/features/comments/services/comments.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class CommentService: | ||
def parse_all_comments(self, comments): | ||
pass |
27 changes: 27 additions & 0 deletions
27
src/recommendation_engine/app/features/comments/services/extraction.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from addict import Dict | ||
from typing import List | ||
|
||
from ..domain.values.comment import CommentValue | ||
from ..domain.entity.getir import GetirComments | ||
from ....shared_kernel.extractor import Extractor | ||
from ..domain.entity.yemek_sepeti import YemekSepetiComments | ||
from ....shared_kernel.domain_providers import Providers | ||
|
||
|
||
class CommentsExtractorService(Extractor): | ||
def __init__(self, provider_type: Providers, **kwargs): | ||
self.kwargs = Dict(**kwargs) | ||
self.provider = self.initialize_provider(provider_type) | ||
|
||
def initialize_provider( | ||
self, provider_type: Providers | ||
) -> GetirComments | YemekSepetiComments: | ||
if provider_type == Providers.YEMEK_SEPETI: | ||
return YemekSepetiComments(restaurant_id=self.kwargs.restaurant_id) | ||
elif provider_type == Providers.GETIR: | ||
return GetirComments(restaurant_id=self.kwargs.restaurant_id) | ||
else: | ||
ValueError("Provider is not defined.") | ||
|
||
def crawl(self) -> List[CommentValue]: | ||
return self.provider.process() |
2 changes: 2 additions & 0 deletions
2
src/recommendation_engine/app/features/menu/services/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from .menu import MenuService | ||
from .extraction import MenuExtractorService |
31 changes: 31 additions & 0 deletions
31
src/recommendation_engine/app/features/menu/services/extraction.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from addict import Dict | ||
from typing import List | ||
|
||
from ..domain.values import GeoValue | ||
from ..domain.values.menu import MenuValue | ||
from ..domain.entity.getir import GetirMenu | ||
from ....shared_kernel.extractor import Extractor | ||
from ..domain.entity.yemeksepeti import YemeksepetiMenu | ||
from ....shared_kernel.domain_providers import Providers | ||
|
||
|
||
class MenuExtractorService(Extractor): | ||
def __init__(self, provider_type: Providers, **kwargs): | ||
self.kwargs = Dict(**kwargs) | ||
self.provider = self.initialize_provider(provider_type) | ||
|
||
def initialize_provider( | ||
self, provider_type: Providers | ||
) -> YemeksepetiMenu | GetirMenu: | ||
if provider_type == Providers.YEMEK_SEPETI: | ||
geo_value = GeoValue(lat=self.kwargs.lat, lon=self.kwargs.lon) | ||
return YemeksepetiMenu( | ||
geo_value=geo_value, restaurant_id=self.kwargs.restaurant_id | ||
) | ||
elif provider_type == Providers.GETIR: | ||
return GetirMenu(restaurant_slug=self.kwargs.restaurant_slug) | ||
else: | ||
ValueError("Provider is not defined.") | ||
|
||
def crawl(self) -> List[MenuValue]: | ||
return self.provider.process() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class MenuService: | ||
def parse_all_menus(self, menus): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
from celery.app.task import Task | ||
|
||
|
||
from ..shared_kernel.scheduler.celery_app import celery_application | ||
from ..features.menu.services import MenuExtractorService, MenuService | ||
|
||
|
||
class MenuTask(Task): | ||
__name__ = "MenuTask" | ||
|
||
def run(self, *args, **kwargs): | ||
pass | ||
menu_service = MenuService() | ||
menu_extractor = MenuExtractorService(**kwargs) | ||
|
||
restaurant_list = menu_extractor.crawl() | ||
menu_service.parse_all_menus(restaurant_list) | ||
|
||
|
||
celery_application.register_task(MenuTask) |