Browse Source

Added Greatist.com parser.

Thomas Flucke 2 years ago
parent
commit
b7d8266a17
1 changed files with 31 additions and 2 deletions
  1. 31 2
      server/app/com/weEat/controllers/ParserController.scala

+ 31 - 2
server/app/com/weEat/controllers/ParserController.scala

@@ -70,8 +70,10 @@ class ParserController @Inject()(
       ("mccormick.com" -> Parser.mccormick),
       ("recipetineats.com" -> Parser.recipeTinEats),
       ("mamalovestocook.com" -> Parser.recipeTinEats),
+      ("soulfullymade.com" -> Parser.recipeTinEats),
       ("sallysbakingaddiction.com" -> Parser.sallysBakingAddiction),
-      ("seriouseats.com" -> Parser.seriousEats)
+      ("seriouseats.com" -> Parser.seriousEats),
+      ("greatist.com" -> Parser.greatist),
     ).get(hostNoWWW)
   }
 
@@ -83,7 +85,8 @@ class ParserController @Inject()(
       .filter(_ <= 0x7f)
       .filterNot(_ == ':')
       .filterNot(_ == '/'), Seq(
-      Branded, Foundation, SRLegacy
+      // Branded, 
+        Foundation, SRLegacy
     ), pageSize = Some(10))().flatMap({ (fdcResult) =>
       Future.sequence(
         fdcResult.foods.map((food) => foodController.getByFdcId(food.fdcId))
@@ -160,6 +163,7 @@ object Parser {
         .replaceAll("\u215D", "5/8")
         .replaceAll("\u215E", "7/8")
         .replaceAll("\u215F", "1/")
+        .replaceAll("\u00F1", "n")
         .trim
       ))
       .map(_.map(_parseIngredient _)),
@@ -230,6 +234,31 @@ object Parser {
     texts("div.structured-project__steps_1-0 > ol > li > p")
   )
 
+  val greatist = Parser(
+    text("h1"),
+    elementList("article.article-body > ul > li").map(
+        _.filter((listItem) => (listItem >?> text("strong")) == Some("Yield"))
+        .map(_ >> text)
+        .head
+      ).map("Yield: \\D*(\\d+).*".r.findFirstMatchIn(_).map(_.group(1).toFloat)),
+    // tflucke@[2023-11-28]: TODO They don't give passive, only Active + Total
+    None,
+    Some(
+      elementList("article.article-body > ul > li").map(
+        _.filter((listItem) => (listItem >?> text("strong")) == Some("Active"))
+        .map(_ >> text)
+        .head
+      ).map("Active: \\D*(\\d+).*".r.findFirstMatchIn(_).fold("0")(_.group(1)))
+    ),
+    elementList("article.article-body > ul > li").map(_
+      .filter((listItem) => (listItem >?> text("strong")) == None)
+      .map(_ >> text)
+      .map(_.replaceAll("\u00F1", "n"))
+      .map(_parseIngredient _)
+    ),
+    texts("article.article-body > ol > li")
+  )
+
   private def _parseFraction(fractionLine: String) = {
     val fractionPattern = raw"(\d+)/(\d+)".r
     val mixedFractionPattern = raw"(\d+)\w+(\d+)/(\d+)".r