From 725bd640cff14387f2401ccf5f52c432b9a029c1 Mon Sep 17 00:00:00 2001 From: wengtad Date: Thu, 13 Oct 2022 22:25:15 +0800 Subject: [PATCH 1/2] feat: add LeanAndGreenRecipes --- README.rst | 1 + recipe_scrapers/__init__.py | 2 + recipe_scrapers/leanandgreenrecipes.py | 51 + tests/test_data/leanandgreenrecipes.testhtml | 1547 ++++++++++++++++++ tests/test_leanandgreenrecipes.py | 64 + 5 files changed, 1665 insertions(+) create mode 100644 recipe_scrapers/leanandgreenrecipes.py create mode 100644 tests/test_data/leanandgreenrecipes.testhtml create mode 100644 tests/test_leanandgreenrecipes.py diff --git a/README.rst b/README.rst index 38cdc9069..c7e51229d 100644 --- a/README.rst +++ b/README.rst @@ -191,6 +191,7 @@ Scrapers available for: - `https://kuchnia-domowa.pl/ `_ - `https://www.kwestiasmaku.com/ `_ - `https://www.latelierderoxane.com `_ +- `https://leanandgreenrecipes.net `_ - `https://lecremedelacrumb.com/ `_ - `https://www.lecker.de `_ - `https://lekkerensimpel.com `_ diff --git a/recipe_scrapers/__init__.py b/recipe_scrapers/__init__.py index d36ddda2d..dc8f3d132 100644 --- a/recipe_scrapers/__init__.py +++ b/recipe_scrapers/__init__.py @@ -113,6 +113,7 @@ from .kuchniadomowa import KuchniaDomowa from .kwestiasmaku import KwestiaSmaku from .latelierderoxane import LAtelierDeRoxane +from .leanandgreenrecipes import LeanAndGreenRecipes from .lecker import Lecker from .lecremedelacrumb import LeCremeDeLaCrumb from .lekkerensimpel import LekkerEnSimpel @@ -331,6 +332,7 @@ KwestiaSmaku.host(): KwestiaSmaku, LAtelierDeRoxane.host(): LAtelierDeRoxane, LeCremeDeLaCrumb.host(): LeCremeDeLaCrumb, + LeanAndGreenRecipes.host(): LeanAndGreenRecipes, Lecker.host(): Lecker, LekkerEnSimpel.host(): LekkerEnSimpel, LittleSpiceJar.host(): LittleSpiceJar, diff --git a/recipe_scrapers/leanandgreenrecipes.py b/recipe_scrapers/leanandgreenrecipes.py new file mode 100644 index 000000000..696e839b7 --- /dev/null +++ b/recipe_scrapers/leanandgreenrecipes.py @@ -0,0 +1,51 @@ +# mypy: allow-untyped-defs + +from ._abstract import AbstractScraper +from ._utils import normalize_string + + +class LeanAndGreenRecipes(AbstractScraper): + @classmethod + def host(cls): + return "leanandgreenrecipes.net" + + def author(self): + return self.schema.author() + + def title(self): + return self.schema.title() + + def total_time(self): + return self.schema.total_time() + + def yields(self): + return self.schema.yields() + + def image(self): + return self.schema.image() + + def ingredients(self): + return self.schema.ingredients() + + def instructions(self): + instructions = ( + self.soup.find("div", {"class": "item-list"}).find_next("ol").find_all("li") + ) + return "\n".join( + [normalize_string(instruction.get_text()) for instruction in instructions] + ) + + def ratings(self): + return self.schema.ratings() + + def cuisine(self): + cuisine = self.schema.cuisine() + return cuisine[cuisine.find(">") + 1 :].replace("", "") + + def description(self): + return ( + self.schema.description() + .replace("

", "\n") + .replace("

", "") + .replace("

", "") + ) diff --git a/tests/test_data/leanandgreenrecipes.testhtml b/tests/test_data/leanandgreenrecipes.testhtml new file mode 100644 index 000000000..ad1bee16b --- /dev/null +++ b/tests/test_data/leanandgreenrecipes.testhtml @@ -0,0 +1,1547 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Lean and Green Yellow Squash Taco Casserole Recipe | Keto & Low-Carb + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ + + + + + + + + + +
+
+ +
+
+
+
+
+
+
+
 
+ +
+

 

+
 
+
+
+
+ +
+
+
+
+ + +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+ +
+
+
+ +
+ + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+

Keto & Low-Carb Lean and Green +Yellow Squash Taco Casserole

+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
 Profile Photo
by lean.green
Jun 22, 2021 | Jump to Instructions

Print this Recipe
+
+
+
+
+
+
+
+
+
+
OPTAVIA Counts:
  • +
    +
    +
    +
    +
    1
    +
    +
    +
    +
    +
    +
    +
    Lean
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
  • +
    +
    +
    +
    +
    1.33
    +
    +
    +
    +
    +
    +
    +
    Green
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
  • +
    +
    +
    +
    +
    3
    +
    +
    +
    +
    +
    +
    +
    Condiment
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
+
+
+
+
+
+
+
+
+
+
+
Yellow Squash Taco Casserole +
+
+
+
+
+
*Image may vary from completed recipe
+
+
+
+
+
+
+
+

Tip: Recipe makes 5 servings, but casserole can be divided into individual 1 serving portions and freezing for later.

+
+
+
+
+
+
+
+

+
+
Would your family eat
+
+
+
Mexican
+
food every night? Prepare this lean and green
+
+
Yellow Squash Taco Casserole
+
recipe and you will have made a
+
+
Mexican
+
entree that is absolutely amazing, keeps you on plan and satisfies your cravings!
+
+

+
+
+
+
+
+
+
+

 

+ +
 
+ + +
+ +

 

+
+
+
+
+
+
+
+
Difficulty
Easy
Servings
5
Cooking Time
25 minutes
Prep Time
15 minutes
+
+
+
+
+
+
+

About Chris Sloan

+
+
Chris Sloan, OPTAVIA Coach 75lbs weight loss
+

My name is Chris Sloan and I, like so many others struggled with my weight for years not realizing the toll being overweight was taking on my body. At the beginning of 2021 I began to take my weight loss efforts seriously and have lost 75 lbs so far on the OPTAVIA optimal weight 5 in 1 Plan! It's been amazing, and while my journey isn't over, I'm well on my way!
+
+When I started I had a hard time finding the top OPTAVIA 5&1 recipes, so I was so inspired to build this website to help compile some of what I felt are the best OPTAVIA recipes around. I'm happy to share it with you as well!
+
+For those not familiar, OPTAVIA is not some fad diet but instead is a program designed to help those who are looking to lose weight make better choices with their health and wellness via better habits.

+

We've worked hard to make sure that all OPTAVIA 5 and 1 recipes listed are approved for the OPTAVIA optimal weight 5 and 1 plan.

+

The recipes on this site are intended for the OPTAVIA 5&1 Plan; however, they can easily be adapted to a low carb or keto lifestyle. If you following a ketogenic diet or low-calorie diet you can enjoy many of the recipes found here to help keep you on track for your weight loss efforts.

+
+
+
+
+

OPTAVIA 5&1 Plan Must Have Items

+
+

+
+
+
+
+
+

+

 

+
+
+
+
+
+
+
+

 

+ +
 
+ + +
+ +

 

+
+
+
+
+

Save to Your Recipes

+
+
+
+
+
+
+
+
Create an account and login to add this recipe to your saved recipes.
+
+
+
+
+
+
+
+
+
+

Rating

+
+
+ +
+
Average: 3.8 (10 votes)
+
+
+
+
+ + +
+
+
+
+
+
+
+
+

Join our Facebook Group

+
+
Lean and Green Recipes
+
+
+
+
+

+ +
 
+ +

+
+
+
+
+

We're Social Too

+
+
+
+
+
+

Invite a Friend

+
+
+ + + + +
+
+
+ +
+
+

+

 

+
+
+
+
+
+
+
+

The Top 7 Popular Optavia Fueling Hacks

+
+
+
+
+
+
+
+
+
+
+
+

Helpful Cooking Utensils

+
+
+

Missing an item in the kitchen? Checkout the links below to pick one up on Amazon.

+ + +
+
+
+
+
+
+

+ +
 
+ +

+
+
+
+
+
+
+
+
+
+
+
+
+

Lean & Green Yellow Squash Taco Casserole Ingredients

+
+
+
    +
  • 1.25 lbs Lean Ground Beef
  • +
  • 2 cup Yellow Squash Sliced
  • +
  • 1.5 tsp Cumin
  • +
  • 1.5 tsp Paprika
  • +
  • 1.5 tsp Chili Powder
  • +
  • 1/8 tsp Cayenne Pepper
  • +
  • 1/2 tsp Salt
  • +
  • 3/4 tsp Garlic Powder
  • +
  • 2 cup Low Fat Cheddar Cheese Grated
  • +
+
+
+
+
+
+
+
+
+
+
+
+

Lean & Green Yellow Squash Taco Casserole Instructions

+
+
+
  1. Preheat oven to 350*F.
  2. Cook the ground beef. After browning the meat, add the canned Diced tomatoes and seasonings to the ground beef and simmer for 5 minutes.
  3. Place the sliced squash to the bottom of a 9 x 13 inch baking pan.
  4. Place meat mixture on top of squash, sprinkle grated cheese on top.
  5. Bake in preheated oven for about 25 minutes.
+
+
+
+
+
+
+
+
+
+
+
+

Purchase Ingredients

+
+ +
+

*Please note that we do get a small affiliate commission for any purchases of these products. These commissions allow us to keep the site free to everyone.

+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+ +Permalink +
+
+ +
+

+

Hi - the instructions call for adding canned diced tomatoes, but that is missing from the ingredient list. What quantity of canned diced tomatoes should be used? Thanks!

+
+ +
+
+
+
+
+ +
+
+ +Permalink +
+
+ +
+

+

Can I use ground turkey instead of beef for any of the recipes that call for beef?

+
+ +
+
+
+
+
+ +
+
+ +Permalink +
+
+ +
+

+

Can I use ground turkey instead of beef for any of the recipes that call for beef?

+
+ +
+
+
+
+
+ +
+
+ +Permalink +
+
+ +
+

+

Can I use ground turkey instead of beef for any of the recipes that call for beef?

+
+ +
+
+
+
+

Leave a review or comment

+
+
+ + +
+ + +
+ + +
+
+
+
+ +
+ +
+
+ +
+
+
+ +
+
+
+
+
+ + +
+
+
+
+
+
+
+
+ + +
+
+
+
+
+
+
 
+ + +
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+

Subscribe to our Newsletter

+

Subscribe to our newsletter and get lean and green recipes delivered right to your email inbox!

+

+
+
+
+
+
+
+ + + +
+
+
+
+
+ + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/test_leanandgreenrecipes.py b/tests/test_leanandgreenrecipes.py new file mode 100644 index 000000000..f3f31a28b --- /dev/null +++ b/tests/test_leanandgreenrecipes.py @@ -0,0 +1,64 @@ +# mypy: allow-untyped-defs + +from recipe_scrapers.leanandgreenrecipes import LeanAndGreenRecipes +from tests import ScraperTest + + +class TestLeanAndGreenRecipesScraper(ScraperTest): + + scraper_class = LeanAndGreenRecipes + + def test_host(self): + self.assertEqual("leanandgreenrecipes.net", self.harvester_class.host()) + + def test_author(self): + self.assertEqual("lean.green", self.harvester_class.author()) + + def test_title(self): + self.assertEqual("Yellow Squash Taco Casserole", self.harvester_class.title()) + + def test_total_time(self): + self.assertEqual(40.0, self.harvester_class.total_time()) + + def test_yields(self): + self.assertEqual("5 servings", self.harvester_class.yields()) + + def test_image(self): + self.assertEqual( + "https://leanandgreenrecipes.net/sites/default/files/2021-08/Yellow%20Squash%20Taco%20Casserole.jpg", + self.harvester_class.image(), + ) + + def test_ingredients(self): + self.assertEqual( + [ + "1.25 lbs Lean Ground Beef", + "2 cup Yellow Squash", + "1.5 tsp Cumin", + "1.5 tsp Paprika", + "1.5 tsp Chili Powder", + "1/8 tsp Cayenne Pepper", + "1/2 tsp Salt", + "3/4 tsp Garlic Powder", + "2 cup Low Fat Cheddar Cheese", + ], + self.harvester_class.ingredients(), + ) + + def test_instructions(self): + self.assertEqual( + "Preheat oven to 350*F.\nCook the ground beef. After browning the meat, add the canned Diced tomatoes and seasonings to the ground beef and simmer for 5 minutes.\nPlace the sliced squash to the bottom of a 9 x 13 inch baking pan.\nPlace meat mixture on top of squash, sprinkle grated cheese on top.\nBake in preheated oven for about 25 minutes.", + self.harvester_class.instructions(), + ) + + def test_ratings(self): + self.assertEqual(3.8, self.harvester_class.ratings()) + + def test_cuisine(self): + self.assertEqual("Mexican", self.harvester_class.cuisine()) + + def test_description(self): + self.assertEqual( + "Tip: Recipe makes 5 servings, but casserole can be divided into individual 1 serving portions and freezing for later.", + self.harvester_class.description(), + ) From e28cf287e11421fd5034d032a8b236b912093025 Mon Sep 17 00:00:00 2001 From: wengtad Date: Fri, 14 Oct 2022 20:47:04 +0800 Subject: [PATCH 2/2] fix: content parsing --- recipe_scrapers/leanandgreenrecipes.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/recipe_scrapers/leanandgreenrecipes.py b/recipe_scrapers/leanandgreenrecipes.py index 696e839b7..197da0b1a 100644 --- a/recipe_scrapers/leanandgreenrecipes.py +++ b/recipe_scrapers/leanandgreenrecipes.py @@ -1,5 +1,7 @@ # mypy: allow-untyped-defs +from bs4 import BeautifulSoup + from ._abstract import AbstractScraper from ._utils import normalize_string @@ -39,13 +41,13 @@ def ratings(self): return self.schema.ratings() def cuisine(self): - cuisine = self.schema.cuisine() - return cuisine[cuisine.find(">") + 1 :].replace("", "") + soup = BeautifulSoup(str(self.schema.cuisine()), features="html.parser") + return soup.get_text() def description(self): - return ( - self.schema.description() - .replace("

", "\n") - .replace("

", "") - .replace("

", "") + descriptions = self.soup.find( + "div", {"class": "block-field-blocknoderecipebody"} + ).find_all("p") + return "\n".join( + [normalize_string(description.get_text()) for description in descriptions] )