Skip to content

Commit

Permalink
feat: service developments
Browse files Browse the repository at this point in the history
  • Loading branch information
fmelihh committed Jul 18, 2024
1 parent 4fed0ce commit 7c8d4db
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 2 deletions.
13 changes: 12 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ sqlalchemy-clickhouse = "^0.1.5.post0"
alembic = "^1.13.2"
clickhouse-sqlalchemy = "^0.3.2"
python-dotenv = "^1.0.1"
addict = "^2.4.0"


[build-system]
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class CommentService:
def parse_all_comments(self, comments):
pass
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()
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 src/recommendation_engine/app/features/menu/services/extraction.py
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()
3 changes: 3 additions & 0 deletions src/recommendation_engine/app/features/menu/services/menu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class MenuService:
def parse_all_menus(self, menus):
pass
8 changes: 7 additions & 1 deletion src/recommendation_engine/app/tasks/menu.py
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)

0 comments on commit 7c8d4db

Please sign in to comment.