Skip to content

Commit

Permalink
refactor (#1470)
Browse files Browse the repository at this point in the history
  • Loading branch information
jknndy authored Feb 2, 2025
1 parent 0c81973 commit 3ce2315
Show file tree
Hide file tree
Showing 5 changed files with 1,184 additions and 210 deletions.
76 changes: 52 additions & 24 deletions recipe_scrapers/latelierderoxane.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from ._abstract import AbstractScraper
from ._utils import get_minutes, get_yields, normalize_string
from ._grouping_utils import IngredientGroup


class LAtelierDeRoxane(AbstractScraper):
Expand All @@ -8,47 +9,74 @@ def host(cls):
return "latelierderoxane.com"

def title(self):
div = self.soup.find("div", {"class": "bloc_titreh1 bloc_blog"})
return div.find("h1").get_text()
return self._get_text_from_bloc("bloc_titreh1", "h1")

def description(self):
div = self.soup.find("div", {"class": "bloc_chapeau bloc_blog"})
cleaned_description = div.find("p").get_text()
return normalize_string(cleaned_description)
return normalize_string(self._get_text_from_bloc("bloc_chapeau", "p"))

def total_time(self):
return get_minutes(self.get_bloc_temps_value_by_index(0))
return get_minutes(self._get_bloc_temps_value_by_index(0))

def prep_time(self):
return get_minutes(self.get_bloc_temps_value_by_index(1))
return get_minutes(self._get_bloc_temps_value_by_index(1))

def cook_time(self):
return get_minutes(self.get_bloc_temps_value_by_index(2))
return get_minutes(self._get_bloc_temps_value_by_index(2))

def yields(self):
return get_yields(self.get_bloc_temps_value_by_index(4))
return get_yields(self._get_bloc_temps_value_by_index(4))

def ingredients(self):
raw_ingredients = self.soup.find_all("div", {"class": "ingredient"})
formatted_ingredients = []
for ingredient in raw_ingredients:
formatted_ingredients.append(normalize_string(ingredient.get_text()))
return formatted_ingredients
ingredients_divs = self.soup.find_all("div", {"class": "ingredient"})
ingredients = []
for ingredient_div in ingredients_divs:
text = normalize_string(ingredient_div.get_text(strip=True))
if text and ":" not in text:
ingredients.append(text)
return ingredients

def ingredient_groups(self):
ingredients_divs = self.soup.find_all("div", {"class": "ingredient"})
groups = []
current_group = {"purpose": None, "ingredients": []}

for ingredient_div in ingredients_divs:
text = normalize_string(ingredient_div.get_text(strip=True))
if not text:
continue
if ":" in text:
if current_group["ingredients"]:
groups.append(current_group)
current_group = {"purpose": text.strip(":"), "ingredients": []}
else:
current_group["ingredients"].append(text)

if current_group["ingredients"]:
groups.append(current_group)

return [
IngredientGroup(ingredients=group["ingredients"], purpose=group["purpose"])
for group in groups
]

def instructions(self):
instruction_bloc = self.soup.find(
instructions_div = self.soup.find(
"div", {"class": "bloc_texte_simple bloc_blog"}
)
instructions = instruction_bloc.find_all("li")
instructions_list = instructions_div.find_all("li")
return "\n".join(
[normalize_string(instruction.get_text()) for instruction in instructions]
[
normalize_string(instruction.get_text(strip=True))
for instruction in instructions_list
]
)

def site_name(self):
return "L'Atelier de Roxane"
def _get_bloc_temps_value_by_index(self, index):
temps_div = self.soup.find("div", {"class": "bloc_temps bloc_blog"})
infos_div = temps_div.find("div", {"class": "infos"})
value_spans = infos_div.find_all("span", {"class": "valeur"})
return value_spans[index].get_text(strip=True)

def get_bloc_temps_value_by_index(self, i):
div_bloc = self.soup.find("div", {"class": "bloc_temps bloc_blog"})
div_infos = div_bloc.find("div", {"class": "infos"})
span_value = div_infos.find_all("span", {"class": "valeur"})
return span_value[i].get_text()
def _get_text_from_bloc(self, bloc_class, tag):
bloc_div = self.soup.find("div", {"class": f"{bloc_class} bloc_blog"})
return bloc_div.find(tag).get_text(strip=True)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"canonical_url": "https://www.latelierderoxane.com/blog/recette-cake-marbre/",
"site_name": "L'Atelier de Roxane",
"site_name": "L'atelier de Roxane",
"host": "latelierderoxane.com",
"language": "fr-FR",
"title": "Recette cake savane maison",
Expand All @@ -16,13 +16,13 @@
],
"instructions_list": [
"Préchauffe le four à 165°.",
"Commence par fouetter les œufs et le sucre, à l’aide de ton robot ou batteur électrique, pendant 10 minutes : ton mélange doit s’éclaircir et doubler de volume !",
"Commence par fouetter les œufs et le sucre, à l’aide de ton robot oubatteur électrique, pendant 10 minutes : ton mélange doit s’éclaircir et doubler de volume !",
"Ajoute le beurre fondu, la levure, la farine et fouette brièvement.",
"Verse le lait et fouette jusqu’à l’obtention d’un mélange homogène.",
"Sépare la préparation obtenue dans deux bols.",
"Dans un des deux bols, ajoute l’arôme ou la poudre de vanille.",
"Dans un des deux bols, ajoutel’arômeou la poudre de vanille.",
"Fais fondre ton chocolat, au bain-marie ou au micro-ondes et incorpore-le dans le second bol à l’aide d’une maryse.",
"Récupère ton moule à cake et beurre-le généreusement.",
"Récupère tonmoule à cakeet beurre-le généreusement.",
"Verse, dans le fond de ton moule, la moitié de la pâte à la vanille puis la moitié de celle au chocolat.",
"Répète l’opération une deuxième fois.",
"Enfourne pendant 45 min.",
Expand All @@ -31,7 +31,7 @@
"À manger sans modération !"
],
"yields": "6 servings",
"description": "Je pense que nous avons déjà tous acheté, au moins une fois, un cake type Savane au supermarché ! Aujourd’hui, je te propose une recette facile et rapide pour réaliser un délicieux marbré au chocolat, moelleux à souhait au bon goût de vanille et cacao ! Réalise cette recette et tu n’achèteras plus l’industriel ! Découvre ma box de pâtisserie goûters faits maison",
"description": "Je pense que nous avons déjà tous acheté, au moins une fois, un cake type Savane au supermarché ! Aujourd’hui, je te propose une recette facile et rapide pour réaliser un délicieux marbré au chocolat, moelleux à souhait au bon goût de vanille et cacao ! Réalise cette recette et tu n’achèteras plus l’industriel !",
"total_time": 65,
"cook_time": 45,
"prep_time": 20,
Expand Down
Loading

0 comments on commit 3ce2315

Please sign in to comment.