Skip to content

Commit

Permalink
feat: restaurant extractor service has been completed.
Browse files Browse the repository at this point in the history
  • Loading branch information
fmelihh committed Jul 18, 2024
1 parent 2f19e2e commit 4fed0ce
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
from typing import List

from ..domain.values import GeoValue
from ....shared_kernel.extractor import Extractor
from ..domain.entity.getir import GetirRestaurants
from ..domain.values.restaurant import RestaurantValue
from ....shared_kernel.domain_providers import Providers
from ..domain.entity.yemek_sepeti import YemeksepetiRestaurants


class RestaurantExtractorService(Extractor):
def __init__(self, lat: float, lon: float):
def __init__(self, provider_type: Providers, lat: float, lon: float):
self.lat = lat
self.lon = lon
self.provider = self.initialize_provider(provider_type)

def initialize_provider(
self, provider_type: Providers
) -> YemeksepetiRestaurants | GetirRestaurants:
geo_value = GeoValue(lat=self.lat, lon=self.lon)
if provider_type == Providers.YEMEK_SEPETI:
return YemeksepetiRestaurants(geo_value)
elif provider_type == Providers.GETIR:
return GetirRestaurants(geo_value)
else:
ValueError("Provider is not defined.")

def crawl(self) -> List[RestaurantValue]:
pass
return self.provider.process()
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from enum import Enum


class Providers(Enum):
GETIR = "GETIR"
YEMEK_SEPETI = "YEMEK_SEPETI"
6 changes: 6 additions & 0 deletions src/recommendation_engine/app/shared_kernel/extractor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from typing import TypeVar, List
from abc import ABC, abstractmethod

from .entity import BaseEntity
from .domain_providers import Providers
from ..features.menu.domain.values import MenuValue
from ..features.comments.domain.values import CommentValue
from ..features.restaurants.domain.values import RestaurantValue
Expand All @@ -13,3 +15,7 @@ class Extractor(ABC):
@abstractmethod
def crawl(self) -> TypeVar:
pass

@abstractmethod
def initialize_provider(self, provider_type: Providers) -> BaseEntity:
pass
6 changes: 3 additions & 3 deletions src/recommendation_engine/app/tasks/data_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ def run(self, *args, **kwargs):
cities = json.load(open(f"{os.getcwd()}/static/cities.json", "r"))

for i in range(0, len(cities), batch_size):
batch = cities[i:i + batch_size]
batch = cities[i : i + batch_size]
tasks = []

for city in batch:
restaurant_task = RestaurantTask()
tasks.append(
celery.chain(
restaurant_task.s(lat=city['lat'], lon=city['lon']),
restaurant_task.s(lat=city["lat"], lon=city["lon"]),
MenuTask().s(),
CommentTask().s()
CommentTask().s(),
)
)
celery.group(*tasks).apply_async()
Expand Down

0 comments on commit 4fed0ce

Please sign in to comment.