Bläddra i källkod

Added more websites to the parser list.

Thomas Flucke 1 år sedan
förälder
incheckning
da3730a756
1 ändrade filer med 39 tillägg och 26 borttagningar
  1. 39 26
      server/app/com/weEat/controllers/ParserController.scala

+ 39 - 26
server/app/com/weEat/controllers/ParserController.scala

@@ -74,9 +74,14 @@ class ParserController @Inject()(
       ("familycookierecipes.com" -> Parser.recipeTinEats),
       ("familyfreshmeals.com" -> Parser.recipeTinEats),
       ("handmadefarmhouse.com" -> Parser.recipeTinEats),
+      ("tastesoflizzyt.com" -> Parser.recipeTinEats),
+      ("omnivorescookbook.com" -> Parser.recipeTinEats),
+      ("growforagecookferment.com" -> Parser.recipeTinEats),
+      ("joyfoodsunshine.com" -> Parser.recipeTinEats),
       ("sallysbakingaddiction.com" -> Parser.tastyRecipes),
       ("darngoodveggies.com" -> Parser.tastyRecipes),
       ("pickledplum.com" -> Parser.tastyRecipes),
+      ("iheartvegetables.com" -> Parser.tastyRecipes),
       ("seriouseats.com" -> Parser.seriousEats),
       ("greatist.com" -> Parser.greatist),
       ("dimitrasdishes.com" -> Parser.dimitrasDishes),
@@ -172,31 +177,37 @@ object Parser {
     text("span.wprm-recipe-servings").map(_.toFloatOption),
     Some(text("span.wprm-recipe-prep_time-minutes")),
     Some(text("span.wprm-recipe-cook_time-minutes")),
-    texts("li.wprm-recipe-ingredient")
-      .map(_.map(_
-        .replaceAll("\u00BD", "1/2")
-        .replaceAll("\u00BC", "1/4")
-        .replaceAll("\u00BE", "3/4")
-        .replaceAll("\u2150", "1/7")
-        .replaceAll("\u2151", "1/9")
-        .replaceAll("\u2152", "1/10")
-        .replaceAll("\u2153", "1/3")
-        .replaceAll("\u2154", "2/3")
-        .replaceAll("\u2155", "1/5")
-        .replaceAll("\u2156", "2/5")
-        .replaceAll("\u2157", "3/5")
-        .replaceAll("\u2158", "4/5")
-        .replaceAll("\u2159", "1/6")
-        .replaceAll("\u215A", "5/6")
-        .replaceAll("\u215B", "1/8")
-        .replaceAll("\u215C", "3/8")
-        .replaceAll("\u215D", "5/8")
-        .replaceAll("\u215E", "7/8")
-        .replaceAll("\u215F", "1/")
-        .replaceAll("\u00F1", "n")
-        .trim
-      ))
-      .map(_.map(_parseIngredient _)),
+    elementList("li.wprm-recipe-ingredient").map(_.map({ (li) => (
+      (li >?> text("span.wprm-recipe-ingredient-amount")
+        .map(_
+          .replaceAll("\u00BD", "1/2")
+          .replaceAll("\u00BC", "1/4")
+          .replaceAll("\u00BE", "3/4")
+          .replaceAll("\u2150", "1/7")
+          .replaceAll("\u2151", "1/9")
+          .replaceAll("\u2152", "1/10")
+          .replaceAll("\u2153", "1/3")
+          .replaceAll("\u2154", "2/3")
+          .replaceAll("\u2155", "1/5")
+          .replaceAll("\u2156", "2/5")
+          .replaceAll("\u2157", "3/5")
+          .replaceAll("\u2158", "4/5")
+          .replaceAll("\u2159", "1/6")
+          .replaceAll("\u215A", "5/6")
+          .replaceAll("\u215B", "1/8")
+          .replaceAll("\u215C", "3/8")
+          .replaceAll("\u215D", "5/8")
+          .replaceAll("\u215E", "7/8")
+          .replaceAll("\u215F", "1/")
+        ))
+        .flatMap(_parseFraction _)
+        .getOrElse(0.0f),
+      (li >?> text("span.wprm-recipe-ingredient-unit"))
+        .flatMap(MeasureUnit.guessUnit _)
+        .getOrElse(Count),
+      li >> text("span.wprm-recipe-ingredient-name")
+        .map(_.replaceAll("\u00F1", "n"))
+    ) })),
     texts("div.wprm-recipe-instruction-text")
   )
 
@@ -222,7 +233,9 @@ object Parser {
               .flatMap(MeasureUnit.guessUnit _)
               .getOrElse(Count)
           ),
-        (listItem >?> text("strong")).getOrElse(listItem.ownText)
+        (listItem >?> text("strong"))
+          .filterNot(_.contains("optional"))
+          .getOrElse(listItem.ownText)
       )})
     ),
     texts("div.tasty-recipes-instructions-body > ol > li")