From 2445637c29cf577d420a86b6e2ada580d1eb4242 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20Blenneg=C3=A5rd?= Date: Fri, 28 Jun 2024 07:17:54 +0200 Subject: [PATCH 01/11] Added handling of numeric values for nutritional information, as well as function for ensuring units to always be imported in same way. --- internal/models/schema-recipe.go | 92 ++++++++++---------- internal/models/schema-recipe_test.go | 121 ++++++++++++++++++++++---- internal/utils/extensions/strings.go | 18 +++- 3 files changed, 169 insertions(+), 62 deletions(-) diff --git a/internal/models/schema-recipe.go b/internal/models/schema-recipe.go index 843a9779..00be72cb 100644 --- a/internal/models/schema-recipe.go +++ b/internal/models/schema-recipe.go @@ -3,8 +3,6 @@ package models import ( "encoding/json" "fmt" - "github.com/reaper47/recipya/internal/app" - "github.com/reaper47/recipya/internal/utils/extensions" "log/slog" "math" "slices" @@ -12,6 +10,9 @@ import ( "strings" "time" + "github.com/reaper47/recipya/internal/app" + "github.com/reaper47/recipya/internal/utils/extensions" + "github.com/google/uuid" ) @@ -869,33 +870,17 @@ func (n *NutritionSchema) UnmarshalJSON(data []byte) error { switch x := v.(type) { case map[string]any: - if val, ok := x["calories"].(string); ok { - n.Calories = strings.TrimSpace(val) - } - - if val, ok := x["carbohydrateContent"].(string); ok { - n.Carbohydrates = val - } - - if val, ok := x["cholesterolContent"].(string); ok { - n.Cholesterol = val - } - - if val, ok := x["fatContent"].(string); ok { - n.Fat = val - } - - if val, ok := x["fiberContent"].(string); ok { - n.Fiber = val - } - - if val, ok := x["proteinContent"].(string); ok { - n.Protein = val - } - - if val, ok := x["saturatedFatContent"].(string); ok { - n.SaturatedFat = val - } + n.Calories = EnsureNutritionUnitForString(extensions.ConvertToString(x["calories"]), "calories") + n.Carbohydrates = EnsureNutritionUnitForString(extensions.ConvertToString(x["carbohydrateContent"]), "carbohydrateContent") + n.Cholesterol = EnsureNutritionUnitForString(extensions.ConvertToString(x["cholesterolContent"]), "cholesterolContent") + n.Fat = EnsureNutritionUnitForString(extensions.ConvertToString(x["fatContent"]), "fatContent") + n.Fiber = EnsureNutritionUnitForString(extensions.ConvertToString(x["fiberContent"]), "fiberContent") + n.Protein = EnsureNutritionUnitForString(extensions.ConvertToString(x["proteinContent"]), "proteinContent") + n.SaturatedFat = EnsureNutritionUnitForString(extensions.ConvertToString(x["saturatedFatContent"]), "saturatedFatContent") + n.Sodium = EnsureNutritionUnitForString(extensions.ConvertToString(x["sodiumContent"]), "sodiumContent") + n.Sugar = EnsureNutritionUnitForString(extensions.ConvertToString(x["sugarContent"]), "sugarContent") + n.TransFat = EnsureNutritionUnitForString(extensions.ConvertToString(x["transFatContent"]), "transFatContent") + n.UnsaturatedFat = EnsureNutritionUnitForString(extensions.ConvertToString(x["unsaturatedFatContent"]), "unsaturatedFatContent") if val, ok := x["servingSize"].(string); ok { xs := strings.Split(val, " ") @@ -911,26 +896,45 @@ func (n *NutritionSchema) UnmarshalJSON(data []byte) error { } } } + default: + slog.Warn("Could not parse nutrition schema", "schema", v, "type", x) + } + return nil +} - if val, ok := x["sodiumContent"].(string); ok { - n.Sodium = val - } - - if val, ok := x["sugarContent"].(string); ok { - n.Sugar = val - } - - if val, ok := x["transFatContent"].(string); ok { - n.TransFat = val +// EnsureNutritionUnitForString checks for existing unit suffix for nutritional property. +// If not already present, add unit to the input string. +func EnsureNutritionUnitForString(nutritionString string, nutritionProperty string) string { + switch nutritionProperty { + case "calories": + if nutritionString == "" { + return strings.TrimSpace(nutritionString) + } else { + nutritionString = strings.TrimSuffix(nutritionString, "calories") + nutritionString = strings.TrimSuffix(nutritionString, "kcal") + return strings.TrimSpace(nutritionString) + " kcal" } - - if val, ok := x["unsaturatedFatContent"].(string); ok { - n.UnsaturatedFat = val + case "carbohydrateContent", "fatContent", "fiberContent", "proteinContent", "saturatedFatContent", "sugarContent", "transFatContent", "unsaturatedFatContent": + if nutritionString == "" { + return strings.TrimSpace(nutritionString) + } else { + nutritionString = strings.TrimSuffix(nutritionString, "gram") + nutritionString = strings.TrimSuffix(nutritionString, "grams") + nutritionString = strings.TrimSuffix(nutritionString, "g") + return strings.TrimSpace(nutritionString) + " g" + } + case "cholesterolContent", "sodiumContent": + if nutritionString == "" { + return strings.TrimSpace(nutritionString) + } else { + nutritionString = strings.TrimSuffix(nutritionString, "milligram") + nutritionString = strings.TrimSuffix(nutritionString, "milligrams") + nutritionString = strings.TrimSuffix(nutritionString, "mg") + return strings.TrimSpace(nutritionString) + " mg" } default: - slog.Warn("Could not parse nutrition schema", "schema", v, "type", x) + return nutritionString } - return nil } // Tools holds the list of tools used for a recipe. diff --git a/internal/models/schema-recipe_test.go b/internal/models/schema-recipe_test.go index 8ab2832d..f0477f94 100644 --- a/internal/models/schema-recipe_test.go +++ b/internal/models/schema-recipe_test.go @@ -2,14 +2,16 @@ package models_test import ( "encoding/json" - "github.com/google/go-cmp/cmp" - "github.com/reaper47/recipya/internal/models" "strings" "testing" "time" - "github.com/google/uuid" + "github.com/google/go-cmp/cmp" + "github.com/reaper47/recipya/internal/models" + "slices" + + "github.com/google/uuid" ) func TestCategory_UnmarshalJSON(t *testing.T) { @@ -304,17 +306,17 @@ func TestNutritionSchema_UnmarshalJSON(t *testing.T) { want := models.RecipeSchema{ NutritionSchema: &models.NutritionSchema{ Calories: "420 kcal", - Carbohydrates: "4g", - Cholesterol: "3mg", - Fat: "5g", - Fiber: "7g", - Protein: "9g", - SaturatedFat: "10g", + Carbohydrates: "4 g", + Cholesterol: "3 mg", + Fat: "5 g", + Fiber: "7 g", + Protein: "9 g", + SaturatedFat: "10 g", Servings: "4", - Sodium: "350mg", - Sugar: "13g", - TransFat: "2g", - UnsaturatedFat: "54g", + Sodium: "350 mg", + Sugar: "13 g", + TransFat: "2 g", + UnsaturatedFat: "54 g", }, } @@ -323,22 +325,107 @@ func TestNutritionSchema_UnmarshalJSON(t *testing.T) { data string }{ { - name: "simple string", + name: "nutrional info without space characters", data: `{"nutrition":{ "calories": "420 kcal", "carbohydrateContent": "4g", "cholesterolContent": "3mg", - "fatContent": "5g", - "fiberContent": "7g", + "fatContent": "5gram", + "fiberContent": "7grams", "proteinContent": "9g", "saturatedFatContent": "10g", "servingSize": "makes 4 loaves", - "sodiumContent": "350mg", + "sodiumContent": "350milligram", "sugarContent": "13g", "transFatContent": "2g", "unsaturatedFatContent": "54g" }}`, }, + { + name: "nutrional info with abbreviated suffixes", + data: `{"nutrition":{ + "calories": "420 kcal", + "carbohydrateContent": "4 g", + "cholesterolContent": "3 mg", + "fatContent": "5 g", + "fiberContent": "7 g", + "proteinContent": "9 g", + "saturatedFatContent": "10 g", + "servingSize": "makes 4 loaves", + "sodiumContent": "350 mg", + "sugarContent": "13 g", + "transFatContent": "2 g", + "unsaturatedFatContent": "54 g" + }}`, + }, + { + name: "nutrional info with non-abbreviated singular suffixes", + data: `{"nutrition":{ + "calories": "420 calories", + "carbohydrateContent": "4 gram", + "cholesterolContent": "3 milligram", + "fatContent": "5 gram", + "fiberContent": "7 gram", + "proteinContent": "9 gram", + "saturatedFatContent": "10 gram", + "servingSize": "makes 4 loave", + "sodiumContent": "350 milligram", + "sugarContent": "13 gram", + "transFatContent": "2 gram", + "unsaturatedFatContent": " 54 gram" + }}`, + }, + { + name: "nutrional info with non-abbreviated plural suffixes", + data: `{"nutrition":{ + "calories": "420 calories", + "carbohydrateContent": "4 grams", + "cholesterolContent": "3 milligrams", + "fatContent": "5 grams", + "fiberContent": "7 grams", + "proteinContent": "9 grams", + "saturatedFatContent": "10 grams", + "servingSize": "makes 4 loaves", + "sodiumContent": "350 milligrams", + "sugarContent": "13 grams", + "transFatContent": "2 grams", + "unsaturatedFatContent": " 54 grams" + }}`, + }, + { + name: "nutrional info without suffixes as strings", + data: `{"nutrition":{ + "calories": "420", + "carbohydrateContent": "4", + "cholesterolContent": "3", + "fatContent": "5", + "fiberContent": "7", + "proteinContent": "9", + "saturatedFatContent": "10", + "servingSize": "4", + "sodiumContent": "350", + "sugarContent": "13", + "transFatContent": "2", + "unsaturatedFatContent": "54" + }}`, + }, + { + name: "nutrional info without suffixes as integers", + data: `{"nutrition":{ + "calories": 420, + "carbohydrateContent": 4, + "cholesterolContent": 3, + "fatContent": 5, + "fiberContent": 7, + "proteinContent": 9, + "saturatedFatContent": 10, + "servingSize": "4 servings", + "sodiumContent": 350, + "sugarContent": 13, + "transFatContent": 2, + "unsaturatedFatContent": 54 + }}`, + }, } for _, tc := range testcases { t.Run(tc.name, func(t *testing.T) { diff --git a/internal/utils/extensions/strings.go b/internal/utils/extensions/strings.go index 6c8e4a5d..fdeedc7b 100644 --- a/internal/utils/extensions/strings.go +++ b/internal/utils/extensions/strings.go @@ -2,9 +2,10 @@ package extensions import ( "fmt" - "github.com/reaper47/recipya/internal/utils/regex" "strconv" "strings" + + "github.com/reaper47/recipya/internal/utils/regex" ) // FloatToString converts a float to a string. Trailing zeroes will be trimmed. @@ -16,6 +17,21 @@ func FloatToString(number float64, format string) string { return formatted } +// ConvertToString converts the input value to a string. +// If a conversion cannot be made, an empty string is returned. +func ConvertToString(v interface{}) string { + switch val := v.(type) { + case string: + return val + case int: + return strconv.Itoa(val) + case float64: + return strconv.FormatFloat(val, 'f', -1, 64) + default: + return "" + } +} + // ScaleString scales the numbers in the string in-place. The string may contain fractions. func ScaleString(s string, scale float64) string { return regex.Digit.ReplaceAllStringFunc(s, func(s string) string { From 5e5cf3cb9d9b79fa2286c08ccfb30f4879b38928 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20Blenneg=C3=A5rd?= Date: Fri, 28 Jun 2024 09:23:38 +0200 Subject: [PATCH 02/11] Added handling of number values for nutritional.servingSize property --- internal/models/schema-recipe.go | 2 +- internal/models/schema-recipe_test.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/models/schema-recipe.go b/internal/models/schema-recipe.go index 00be72cb..8c0af82a 100644 --- a/internal/models/schema-recipe.go +++ b/internal/models/schema-recipe.go @@ -882,7 +882,7 @@ func (n *NutritionSchema) UnmarshalJSON(data []byte) error { n.TransFat = EnsureNutritionUnitForString(extensions.ConvertToString(x["transFatContent"]), "transFatContent") n.UnsaturatedFat = EnsureNutritionUnitForString(extensions.ConvertToString(x["unsaturatedFatContent"]), "unsaturatedFatContent") - if val, ok := x["servingSize"].(string); ok { + if val := extensions.ConvertToString(x["servingSize"]); val != "" { xs := strings.Split(val, " ") if len(xs) == 2 && len(xs[1]) < 4 { n.Servings = val diff --git a/internal/models/schema-recipe_test.go b/internal/models/schema-recipe_test.go index f0477f94..9287771e 100644 --- a/internal/models/schema-recipe_test.go +++ b/internal/models/schema-recipe_test.go @@ -368,7 +368,7 @@ func TestNutritionSchema_UnmarshalJSON(t *testing.T) { "fiberContent": "7 gram", "proteinContent": "9 gram", "saturatedFatContent": "10 gram", - "servingSize": "makes 4 loave", + "servingSize": "makes 4 loaf", "sodiumContent": "350 milligram", "sugarContent": "13 gram", "transFatContent": "2 gram", @@ -385,7 +385,7 @@ func TestNutritionSchema_UnmarshalJSON(t *testing.T) { "fiberContent": "7 grams", "proteinContent": "9 grams", "saturatedFatContent": "10 grams", - "servingSize": "makes 4 loaves", + "servingSize": "makes 4 servings", "sodiumContent": "350 milligrams", "sugarContent": "13 grams", "transFatContent": "2 grams", @@ -419,7 +419,7 @@ func TestNutritionSchema_UnmarshalJSON(t *testing.T) { "fiberContent": 7, "proteinContent": 9, "saturatedFatContent": 10, - "servingSize": "4 servings", + "servingSize": 4, "sodiumContent": 350, "sugarContent": 13, "transFatContent": 2, From 225ed237060cd0c9781ce7f333c075e560414ba4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20Blenneg=C3=A5rd?= Date: Sat, 29 Jun 2024 16:19:49 +0200 Subject: [PATCH 03/11] Adjustments as discussed in PR https://github.com/reaper47/recipya/pull/382 --- internal/models/schema-recipe.go | 62 +++++++++++---------------- internal/models/schema-recipe_test.go | 2 +- internal/utils/extensions/strings.go | 2 +- 3 files changed, 28 insertions(+), 38 deletions(-) diff --git a/internal/models/schema-recipe.go b/internal/models/schema-recipe.go index 8c0af82a..0409eb34 100644 --- a/internal/models/schema-recipe.go +++ b/internal/models/schema-recipe.go @@ -12,6 +12,7 @@ import ( "github.com/reaper47/recipya/internal/app" "github.com/reaper47/recipya/internal/utils/extensions" + "github.com/reaper47/recipya/internal/utils/regex" "github.com/google/uuid" ) @@ -870,17 +871,17 @@ func (n *NutritionSchema) UnmarshalJSON(data []byte) error { switch x := v.(type) { case map[string]any: - n.Calories = EnsureNutritionUnitForString(extensions.ConvertToString(x["calories"]), "calories") - n.Carbohydrates = EnsureNutritionUnitForString(extensions.ConvertToString(x["carbohydrateContent"]), "carbohydrateContent") - n.Cholesterol = EnsureNutritionUnitForString(extensions.ConvertToString(x["cholesterolContent"]), "cholesterolContent") - n.Fat = EnsureNutritionUnitForString(extensions.ConvertToString(x["fatContent"]), "fatContent") - n.Fiber = EnsureNutritionUnitForString(extensions.ConvertToString(x["fiberContent"]), "fiberContent") - n.Protein = EnsureNutritionUnitForString(extensions.ConvertToString(x["proteinContent"]), "proteinContent") - n.SaturatedFat = EnsureNutritionUnitForString(extensions.ConvertToString(x["saturatedFatContent"]), "saturatedFatContent") - n.Sodium = EnsureNutritionUnitForString(extensions.ConvertToString(x["sodiumContent"]), "sodiumContent") - n.Sugar = EnsureNutritionUnitForString(extensions.ConvertToString(x["sugarContent"]), "sugarContent") - n.TransFat = EnsureNutritionUnitForString(extensions.ConvertToString(x["transFatContent"]), "transFatContent") - n.UnsaturatedFat = EnsureNutritionUnitForString(extensions.ConvertToString(x["unsaturatedFatContent"]), "unsaturatedFatContent") + n.Calories = ensureNutritionUnitForString(extensions.ConvertToString(x["calories"]), "calories") + n.Carbohydrates = ensureNutritionUnitForString(extensions.ConvertToString(x["carbohydrateContent"]), "carbohydrateContent") + n.Cholesterol = ensureNutritionUnitForString(extensions.ConvertToString(x["cholesterolContent"]), "cholesterolContent") + n.Fat = ensureNutritionUnitForString(extensions.ConvertToString(x["fatContent"]), "fatContent") + n.Fiber = ensureNutritionUnitForString(extensions.ConvertToString(x["fiberContent"]), "fiberContent") + n.Protein = ensureNutritionUnitForString(extensions.ConvertToString(x["proteinContent"]), "proteinContent") + n.SaturatedFat = ensureNutritionUnitForString(extensions.ConvertToString(x["saturatedFatContent"]), "saturatedFatContent") + n.Sodium = ensureNutritionUnitForString(extensions.ConvertToString(x["sodiumContent"]), "sodiumContent") + n.Sugar = ensureNutritionUnitForString(extensions.ConvertToString(x["sugarContent"]), "sugarContent") + n.TransFat = ensureNutritionUnitForString(extensions.ConvertToString(x["transFatContent"]), "transFatContent") + n.UnsaturatedFat = ensureNutritionUnitForString(extensions.ConvertToString(x["unsaturatedFatContent"]), "unsaturatedFatContent") if val := extensions.ConvertToString(x["servingSize"]); val != "" { xs := strings.Split(val, " ") @@ -902,36 +903,25 @@ func (n *NutritionSchema) UnmarshalJSON(data []byte) error { return nil } -// EnsureNutritionUnitForString checks for existing unit suffix for nutritional property. +// ensureNutritionUnitForString checks for existing unit suffix for nutritional property. // If not already present, add unit to the input string. -func EnsureNutritionUnitForString(nutritionString string, nutritionProperty string) string { +func ensureNutritionUnitForString(nutritionString string, nutritionProperty string) string { + var nutritionStringDigits string = regex.Digit.FindString(nutritionString) + + // Early return if no digits could be found + if nutritionStringDigits == "" { + return nutritionStringDigits + } + + // Concatenate unit to found digits switch nutritionProperty { case "calories": - if nutritionString == "" { - return strings.TrimSpace(nutritionString) - } else { - nutritionString = strings.TrimSuffix(nutritionString, "calories") - nutritionString = strings.TrimSuffix(nutritionString, "kcal") - return strings.TrimSpace(nutritionString) + " kcal" - } + return nutritionStringDigits + " kcal" case "carbohydrateContent", "fatContent", "fiberContent", "proteinContent", "saturatedFatContent", "sugarContent", "transFatContent", "unsaturatedFatContent": - if nutritionString == "" { - return strings.TrimSpace(nutritionString) - } else { - nutritionString = strings.TrimSuffix(nutritionString, "gram") - nutritionString = strings.TrimSuffix(nutritionString, "grams") - nutritionString = strings.TrimSuffix(nutritionString, "g") - return strings.TrimSpace(nutritionString) + " g" - } + return nutritionStringDigits + " g" case "cholesterolContent", "sodiumContent": - if nutritionString == "" { - return strings.TrimSpace(nutritionString) - } else { - nutritionString = strings.TrimSuffix(nutritionString, "milligram") - nutritionString = strings.TrimSuffix(nutritionString, "milligrams") - nutritionString = strings.TrimSuffix(nutritionString, "mg") - return strings.TrimSpace(nutritionString) + " mg" - } + return nutritionStringDigits + " mg" + // Return original string if the property is unhandled, e.g. if the schema has received new or updated property names which are not included in the other cases default: return nutritionString } diff --git a/internal/models/schema-recipe_test.go b/internal/models/schema-recipe_test.go index 9287771e..43ad4fae 100644 --- a/internal/models/schema-recipe_test.go +++ b/internal/models/schema-recipe_test.go @@ -385,7 +385,7 @@ func TestNutritionSchema_UnmarshalJSON(t *testing.T) { "fiberContent": "7 grams", "proteinContent": "9 grams", "saturatedFatContent": "10 grams", - "servingSize": "makes 4 servings", + "servingSize": "makes 4 loaves", "sodiumContent": "350 milligrams", "sugarContent": "13 grams", "transFatContent": "2 grams", diff --git a/internal/utils/extensions/strings.go b/internal/utils/extensions/strings.go index fdeedc7b..028714b9 100644 --- a/internal/utils/extensions/strings.go +++ b/internal/utils/extensions/strings.go @@ -19,7 +19,7 @@ func FloatToString(number float64, format string) string { // ConvertToString converts the input value to a string. // If a conversion cannot be made, an empty string is returned. -func ConvertToString(v interface{}) string { +func ConvertToString(v any) string { switch val := v.(type) { case string: return val From 36ea5bd9a56e31da5cdbe433bf3285a2d7e956de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20Blenneg=C3=A5rd?= Date: Mon, 1 Jul 2024 11:24:57 +0200 Subject: [PATCH 04/11] Updated scraper to only extract digits from nutritional information --- internal/models/recipe.go | 39 ++++++++++++++++++------------- internal/models/schema-recipe.go | 40 +++++++++++++++++--------------- web/components/recipes.templ | 18 +++++++------- 3 files changed, 53 insertions(+), 44 deletions(-) diff --git a/internal/models/recipe.go b/internal/models/recipe.go index 5e70c747..0e6b6f15 100644 --- a/internal/models/recipe.go +++ b/internal/models/recipe.go @@ -4,14 +4,6 @@ import ( "bufio" "bytes" "errors" - "github.com/PuerkitoBio/goquery" - "github.com/donna-legal/word2number" - "github.com/google/uuid" - "github.com/reaper47/recipya/internal/app" - "github.com/reaper47/recipya/internal/units" - "github.com/reaper47/recipya/internal/utils/duration" - "github.com/reaper47/recipya/internal/utils/extensions" - "github.com/reaper47/recipya/internal/utils/regex" "io" "log/slog" "net/url" @@ -20,6 +12,15 @@ import ( "strings" "sync" "time" + + "github.com/PuerkitoBio/goquery" + "github.com/donna-legal/word2number" + "github.com/google/uuid" + "github.com/reaper47/recipya/internal/app" + "github.com/reaper47/recipya/internal/units" + "github.com/reaper47/recipya/internal/utils/duration" + "github.com/reaper47/recipya/internal/utils/extensions" + "github.com/reaper47/recipya/internal/utils/regex" ) var ( @@ -482,48 +483,54 @@ func (n *Nutrition) Format() string { var sb strings.Builder if n.Calories != "" { sb.WriteString("calories ") - sb.WriteString(n.Calories) + sb.WriteString(EnsureNutritionUnitForString(n.Calories, "Calories")) sb.WriteString("; ") } if n.TotalCarbohydrates != "" { sb.WriteString("total carbohydrates ") - sb.WriteString(n.TotalCarbohydrates) + sb.WriteString(EnsureNutritionUnitForString(n.TotalCarbohydrates, "Carbohydrates")) sb.WriteString("; ") } if n.Sugars != "" { sb.WriteString("sugar ") - sb.WriteString(n.Sugars) + sb.WriteString(EnsureNutritionUnitForString(n.Sugars, "Sugar")) sb.WriteString("; ") } if n.Protein != "" { sb.WriteString("protein ") - sb.WriteString(n.Protein) + sb.WriteString(EnsureNutritionUnitForString(n.Protein, "Protein")) sb.WriteString("; ") } if n.TotalFat != "" { sb.WriteString("total fat ") - sb.WriteString(n.TotalFat) + sb.WriteString(EnsureNutritionUnitForString(n.TotalFat, "Fat")) sb.WriteString("; ") } if n.SaturatedFat != "" { sb.WriteString("saturated fat ") - sb.WriteString(n.SaturatedFat) + sb.WriteString(EnsureNutritionUnitForString(n.SaturatedFat, "SaturatedFat")) sb.WriteString("; ") } if n.Cholesterol != "" { sb.WriteString("cholesterol ") - sb.WriteString(n.Cholesterol) + sb.WriteString(EnsureNutritionUnitForString(n.Cholesterol, "Cholesterol")) + sb.WriteString("; ") + } + + if n.Sodium != "" { + sb.WriteString("sodium ") + sb.WriteString(EnsureNutritionUnitForString(n.Sodium, "Sodium")) sb.WriteString("; ") } if n.Fiber != "" { sb.WriteString("fiber ") - sb.WriteString(n.Fiber) + sb.WriteString(EnsureNutritionUnitForString(n.Fiber, "Fiber")) } return "Per 100g: " + sb.String() diff --git a/internal/models/schema-recipe.go b/internal/models/schema-recipe.go index 0409eb34..22f8c82d 100644 --- a/internal/models/schema-recipe.go +++ b/internal/models/schema-recipe.go @@ -871,17 +871,17 @@ func (n *NutritionSchema) UnmarshalJSON(data []byte) error { switch x := v.(type) { case map[string]any: - n.Calories = ensureNutritionUnitForString(extensions.ConvertToString(x["calories"]), "calories") - n.Carbohydrates = ensureNutritionUnitForString(extensions.ConvertToString(x["carbohydrateContent"]), "carbohydrateContent") - n.Cholesterol = ensureNutritionUnitForString(extensions.ConvertToString(x["cholesterolContent"]), "cholesterolContent") - n.Fat = ensureNutritionUnitForString(extensions.ConvertToString(x["fatContent"]), "fatContent") - n.Fiber = ensureNutritionUnitForString(extensions.ConvertToString(x["fiberContent"]), "fiberContent") - n.Protein = ensureNutritionUnitForString(extensions.ConvertToString(x["proteinContent"]), "proteinContent") - n.SaturatedFat = ensureNutritionUnitForString(extensions.ConvertToString(x["saturatedFatContent"]), "saturatedFatContent") - n.Sodium = ensureNutritionUnitForString(extensions.ConvertToString(x["sodiumContent"]), "sodiumContent") - n.Sugar = ensureNutritionUnitForString(extensions.ConvertToString(x["sugarContent"]), "sugarContent") - n.TransFat = ensureNutritionUnitForString(extensions.ConvertToString(x["transFatContent"]), "transFatContent") - n.UnsaturatedFat = ensureNutritionUnitForString(extensions.ConvertToString(x["unsaturatedFatContent"]), "unsaturatedFatContent") + n.Calories = regex.Digit.FindString(extensions.ConvertToString(x["calories"])) + n.Carbohydrates = regex.Digit.FindString(extensions.ConvertToString(x["carbohydrateContent"])) + n.Cholesterol = regex.Digit.FindString(extensions.ConvertToString(x["cholesterolContent"])) + n.Fat = regex.Digit.FindString(extensions.ConvertToString(x["fatContent"])) + n.Fiber = regex.Digit.FindString(extensions.ConvertToString(x["fiberContent"])) + n.Protein = regex.Digit.FindString(extensions.ConvertToString(x["proteinContent"])) + n.SaturatedFat = regex.Digit.FindString(extensions.ConvertToString(x["saturatedFatContent"])) + n.Sodium = regex.Digit.FindString(extensions.ConvertToString(x["sodiumContent"])) + n.Sugar = regex.Digit.FindString(extensions.ConvertToString(x["sugarContent"])) + n.TransFat = regex.Digit.FindString(extensions.ConvertToString(x["transFatContent"])) + n.UnsaturatedFat = regex.Digit.FindString(extensions.ConvertToString(x["unsaturatedFatContent"])) if val := extensions.ConvertToString(x["servingSize"]); val != "" { xs := strings.Split(val, " ") @@ -903,9 +903,11 @@ func (n *NutritionSchema) UnmarshalJSON(data []byte) error { return nil } -// ensureNutritionUnitForString checks for existing unit suffix for nutritional property. -// If not already present, add unit to the input string. -func ensureNutritionUnitForString(nutritionString string, nutritionProperty string) string { +// EnsureNutritionUnitForString extracts digits from nutritional property and appends metric unit. +// Returns a string value. +func EnsureNutritionUnitForString(nutritionValue any, nutritionProperty string) string { + var nutritionPropertyLowerCase = strings.ToLower(nutritionProperty) + var nutritionString string = extensions.ConvertToString(nutritionValue) var nutritionStringDigits string = regex.Digit.FindString(nutritionString) // Early return if no digits could be found @@ -913,15 +915,15 @@ func ensureNutritionUnitForString(nutritionString string, nutritionProperty stri return nutritionStringDigits } - // Concatenate unit to found digits - switch nutritionProperty { + // Concatenate metric unit to extracted digits + switch nutritionPropertyLowerCase { case "calories": return nutritionStringDigits + " kcal" - case "carbohydrateContent", "fatContent", "fiberContent", "proteinContent", "saturatedFatContent", "sugarContent", "transFatContent", "unsaturatedFatContent": + case "carbohydrates", "fat", "fiber", "protein", "saturatedfat", "sugar", "transfat", "unsaturatedfat": return nutritionStringDigits + " g" - case "cholesterolContent", "sodiumContent": + case "cholesterol", "sodium": return nutritionStringDigits + " mg" - // Return original string if the property is unhandled, e.g. if the schema has received new or updated property names which are not included in the other cases + // If the property is unhandled, e.g. if the schema has received new or updated property names which are not included in the other cases. default: return nutritionString } diff --git a/web/components/recipes.templ b/web/components/recipes.templ index 3f30586f..d6ff2702 100644 --- a/web/components/recipes.templ +++ b/web/components/recipes.templ @@ -2000,7 +2000,7 @@ templ viewRecipe(data *templates.ViewRecipeData, isAuthenticated bool) { if data.Recipe.Nutrition.Calories == "" { - } else { - { data.Recipe.Nutrition.Calories } + { models.EnsureNutritionUnitForString(data.Recipe.Nutrition.Calories,"Calories") } } @@ -2010,7 +2010,7 @@ templ viewRecipe(data *templates.ViewRecipeData, isAuthenticated bool) { if data.Recipe.Nutrition.TotalCarbohydrates == "" { - } else { - { data.Recipe.Nutrition.TotalCarbohydrates } + { models.EnsureNutritionUnitForString(data.Recipe.Nutrition.TotalCarbohydrates,"Carbohydrates") } } @@ -2020,7 +2020,7 @@ templ viewRecipe(data *templates.ViewRecipeData, isAuthenticated bool) { if data.Recipe.Nutrition.Sugars == "" { - } else { - { data.Recipe.Nutrition.Sugars } + { models.EnsureNutritionUnitForString(data.Recipe.Nutrition.Sugars,"Sugar") } } @@ -2030,7 +2030,7 @@ templ viewRecipe(data *templates.ViewRecipeData, isAuthenticated bool) { if data.Recipe.Nutrition.Protein == "" { - } else { - { data.Recipe.Nutrition.Protein } + { models.EnsureNutritionUnitForString(data.Recipe.Nutrition.Protein,"Protein") } } @@ -2040,7 +2040,7 @@ templ viewRecipe(data *templates.ViewRecipeData, isAuthenticated bool) { if data.Recipe.Nutrition.TotalFat == "" { - } else { - { data.Recipe.Nutrition.TotalFat } + { models.EnsureNutritionUnitForString(data.Recipe.Nutrition.TotalFat,"Fat") } } @@ -2050,7 +2050,7 @@ templ viewRecipe(data *templates.ViewRecipeData, isAuthenticated bool) { if data.Recipe.Nutrition.SaturatedFat == "" { - } else { - { data.Recipe.Nutrition.SaturatedFat } + { models.EnsureNutritionUnitForString(data.Recipe.Nutrition.SaturatedFat,"SaturatedFat") } } @@ -2060,7 +2060,7 @@ templ viewRecipe(data *templates.ViewRecipeData, isAuthenticated bool) { if data.Recipe.Nutrition.Cholesterol == "" { - } else { - { data.Recipe.Nutrition.Cholesterol } + { models.EnsureNutritionUnitForString(data.Recipe.Nutrition.Cholesterol,"Cholesterol") } } @@ -2070,7 +2070,7 @@ templ viewRecipe(data *templates.ViewRecipeData, isAuthenticated bool) { if data.Recipe.Nutrition.Sodium == "" { - } else { - { data.Recipe.Nutrition.Sodium } + { models.EnsureNutritionUnitForString(data.Recipe.Nutrition.Sodium,"Sodium") } } @@ -2080,7 +2080,7 @@ templ viewRecipe(data *templates.ViewRecipeData, isAuthenticated bool) { if data.Recipe.Nutrition.Fiber == "" { - } else { - { data.Recipe.Nutrition.Fiber } + { models.EnsureNutritionUnitForString(data.Recipe.Nutrition.Fiber,"Fiber") } } From df964dc16d46979b975a4cc2c443908846ee6137 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20Blenneg=C3=A5rd?= Date: Mon, 1 Jul 2024 14:49:05 +0200 Subject: [PATCH 05/11] Changed placeholder texts to not confuse when moving between view and edit mode for a recipe --- web/components/recipes.templ | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/web/components/recipes.templ b/web/components/recipes.templ index d6ff2702..8249a7dd 100644 --- a/web/components/recipes.templ +++ b/web/components/recipes.templ @@ -1361,7 +1361,7 @@ templ editRecipe(data *templates.ViewRecipeData) { type="text" name="calories" autocomplete="off" - placeholder="368kcal" + placeholder="kcal" class="input input-bordered input-xs max-w-24" value={ data.Recipe.Nutrition.Calories } /> @@ -1376,7 +1376,7 @@ templ editRecipe(data *templates.ViewRecipeData) { type="text" name="total-carbohydrates" autocomplete="off" - placeholder="35g" + placeholder="g" class="input input-bordered input-xs max-w-24" value={ data.Recipe.Nutrition.TotalCarbohydrates } /> @@ -1391,7 +1391,7 @@ templ editRecipe(data *templates.ViewRecipeData) { type="text" name="sugars" autocomplete="off" - placeholder="3g" + placeholder="g" class="input input-bordered input-xs max-w-24" value={ data.Recipe.Nutrition.Sugars } /> @@ -1406,7 +1406,7 @@ templ editRecipe(data *templates.ViewRecipeData) { type="text" name="protein" autocomplete="off" - placeholder="21g" + placeholder="g" class="input input-bordered input-xs max-w-24" value={ data.Recipe.Nutrition.Protein } /> @@ -1421,7 +1421,7 @@ templ editRecipe(data *templates.ViewRecipeData) { type="text" name="total-fat" autocomplete="off" - placeholder="15g" + placeholder="g" class="input input-bordered input-xs max-w-24" value={ data.Recipe.Nutrition.TotalFat } /> @@ -1436,7 +1436,7 @@ templ editRecipe(data *templates.ViewRecipeData) { type="text" name="saturated-fat" autocomplete="off" - placeholder="1.8g" + placeholder="g" class="input input-bordered input-xs max-w-24" value={ data.Recipe.Nutrition.SaturatedFat } /> @@ -1451,7 +1451,7 @@ templ editRecipe(data *templates.ViewRecipeData) { type="text" name="cholesterol" autocomplete="off" - placeholder="1.1mg" + placeholder="mg" class="input input-bordered input-xs max-w-24" value={ data.Recipe.Nutrition.Cholesterol } /> @@ -1466,7 +1466,7 @@ templ editRecipe(data *templates.ViewRecipeData) { type="text" name="sodium" autocomplete="off" - placeholder="100mg" + placeholder="mg" class="input input-bordered input-xs max-w-24" value={ data.Recipe.Nutrition.Sodium } /> @@ -1481,7 +1481,7 @@ templ editRecipe(data *templates.ViewRecipeData) { type="text" name="fiber" autocomplete="off" - placeholder="8g" + placeholder="g" class="input input-bordered input-xs max-w-24" value={ data.Recipe.Nutrition.Fiber } /> From 71a1de1957ffd668a0fdcb47a690dc0af880f90b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20Blenneg=C3=A5rd?= Date: Mon, 1 Jul 2024 15:13:51 +0200 Subject: [PATCH 06/11] Added missing nutrition propery (unsaturated fat) to front end --- internal/models/recipe.go | 6 ++++++ web/components/recipes.templ | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/internal/models/recipe.go b/internal/models/recipe.go index 0e6b6f15..f712fff3 100644 --- a/internal/models/recipe.go +++ b/internal/models/recipe.go @@ -516,6 +516,12 @@ func (n *Nutrition) Format() string { sb.WriteString("; ") } + if n.UnsaturatedFat != "" { + sb.WriteString("unsaturated fat ") + sb.WriteString(EnsureNutritionUnitForString(n.UnsaturatedFat, "UnsaturatedFat")) + sb.WriteString("; ") + } + if n.Cholesterol != "" { sb.WriteString("cholesterol ") sb.WriteString(EnsureNutritionUnitForString(n.Cholesterol, "Cholesterol")) diff --git a/web/components/recipes.templ b/web/components/recipes.templ index 8249a7dd..e8320433 100644 --- a/web/components/recipes.templ +++ b/web/components/recipes.templ @@ -1443,6 +1443,21 @@ templ editRecipe(data *templates.ViewRecipeData) { + + Unsaturated fat + + + + Cholesterol @@ -2054,6 +2069,16 @@ templ viewRecipe(data *templates.ViewRecipeData, isAuthenticated bool) { } + + Unsaturated fat: + + if data.Recipe.Nutrition.UnsaturatedFat == "" { + - + } else { + { models.EnsureNutritionUnitForString(data.Recipe.Nutrition.UnsaturatedFat,"UnsaturatedFat") } + } + + Cholesterol: From 228f34d4f2203256bb3d9ce06eda42f74c39c1bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20Blenneg=C3=A5rd?= Date: Mon, 1 Jul 2024 15:14:20 +0200 Subject: [PATCH 07/11] Grouped fat properties in case --- internal/models/schema-recipe.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/models/schema-recipe.go b/internal/models/schema-recipe.go index 22f8c82d..48fab052 100644 --- a/internal/models/schema-recipe.go +++ b/internal/models/schema-recipe.go @@ -919,7 +919,7 @@ func EnsureNutritionUnitForString(nutritionValue any, nutritionProperty string) switch nutritionPropertyLowerCase { case "calories": return nutritionStringDigits + " kcal" - case "carbohydrates", "fat", "fiber", "protein", "saturatedfat", "sugar", "transfat", "unsaturatedfat": + case "carbohydrates", "protein", "fat", "saturatedfat", "sugar", "transfat", "unsaturatedfat", "fiber": return nutritionStringDigits + " g" case "cholesterol", "sodium": return nutritionStringDigits + " mg" From c4d57af40b6eb646d62e4f1ca1056260d744feb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20Blenneg=C3=A5rd?= Date: Mon, 1 Jul 2024 18:37:32 +0200 Subject: [PATCH 08/11] Added handling of commas as decimal separator in nutrition scraper --- internal/models/schema-recipe.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/internal/models/schema-recipe.go b/internal/models/schema-recipe.go index 48fab052..b8917d8b 100644 --- a/internal/models/schema-recipe.go +++ b/internal/models/schema-recipe.go @@ -871,17 +871,17 @@ func (n *NutritionSchema) UnmarshalJSON(data []byte) error { switch x := v.(type) { case map[string]any: - n.Calories = regex.Digit.FindString(extensions.ConvertToString(x["calories"])) - n.Carbohydrates = regex.Digit.FindString(extensions.ConvertToString(x["carbohydrateContent"])) - n.Cholesterol = regex.Digit.FindString(extensions.ConvertToString(x["cholesterolContent"])) - n.Fat = regex.Digit.FindString(extensions.ConvertToString(x["fatContent"])) - n.Fiber = regex.Digit.FindString(extensions.ConvertToString(x["fiberContent"])) - n.Protein = regex.Digit.FindString(extensions.ConvertToString(x["proteinContent"])) - n.SaturatedFat = regex.Digit.FindString(extensions.ConvertToString(x["saturatedFatContent"])) - n.Sodium = regex.Digit.FindString(extensions.ConvertToString(x["sodiumContent"])) - n.Sugar = regex.Digit.FindString(extensions.ConvertToString(x["sugarContent"])) - n.TransFat = regex.Digit.FindString(extensions.ConvertToString(x["transFatContent"])) - n.UnsaturatedFat = regex.Digit.FindString(extensions.ConvertToString(x["unsaturatedFatContent"])) + n.Calories = regex.Digit.FindString(strings.Replace(extensions.ConvertToString(x["calories"]), ",", ".", -1)) + n.Carbohydrates = regex.Digit.FindString(strings.Replace(extensions.ConvertToString(x["carbohydrateContent"]), ",", ".", -1)) + n.Cholesterol = regex.Digit.FindString(strings.Replace(extensions.ConvertToString(x["cholesterolContent"]), ",", ".", -1)) + n.Fat = regex.Digit.FindString(strings.Replace(extensions.ConvertToString(x["fatContent"]), ",", ".", -1)) + n.SaturatedFat = regex.Digit.FindString(strings.Replace(extensions.ConvertToString(x["saturatedFatContent"]), ",", ".", -1)) + n.UnsaturatedFat = regex.Digit.FindString(strings.Replace(extensions.ConvertToString(x["unsaturatedFatContent"]), ",", ".", -1)) + n.TransFat = regex.Digit.FindString(strings.Replace(extensions.ConvertToString(x["transFatContent"]), ",", ".", -1)) + n.Protein = regex.Digit.FindString(strings.Replace(extensions.ConvertToString(x["proteinContent"]), ",", ".", -1)) + n.Sugar = regex.Digit.FindString(strings.Replace(extensions.ConvertToString(x["sugarContent"]), ",", ".", -1)) + n.Sodium = regex.Digit.FindString(strings.Replace(extensions.ConvertToString(x["sodiumContent"]), ",", ".", -1)) + n.Fiber = regex.Digit.FindString(strings.Replace(extensions.ConvertToString(x["fiberContent"]), ",", ".", -1)) if val := extensions.ConvertToString(x["servingSize"]); val != "" { xs := strings.Split(val, " ") From 581333157d6987f46249ac8ca33343e67e9fc10f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20Blenneg=C3=A5rd?= Date: Mon, 1 Jul 2024 18:39:16 +0200 Subject: [PATCH 09/11] Verified and updated all testcases to accomodate digits only scraping of nutritional information --- internal/integrations/nextcloud_test.go | 33 +-- internal/models/recipe_test.go | 19 +- internal/models/schema-recipe_test.go | 34 +-- internal/scraper/bettybossi.go | 7 +- internal/scraper/bodybuilding.go | 12 +- internal/scraper/cdkitchen.go | 28 +-- internal/scraper/closetcooking.go | 26 ++- internal/scraper/fitmencook.go | 17 +- internal/scraper/myplate.go | 22 +- internal/scraper/projectgezond.go | 14 +- internal/scraper/quitoque.go | 19 +- internal/scraper/scraper_A_test.go | 134 +++++------ internal/scraper/scraper_B_test.go | 243 ++++++++++---------- internal/scraper/scraper_C_test.go | 189 ++++++++-------- internal/scraper/scraper_D_test.go | 67 +++--- internal/scraper/scraper_E_test.go | 107 ++++----- internal/scraper/scraper_F_test.go | 173 +++++++------- internal/scraper/scraper_G_test.go | 27 +-- internal/scraper/scraper_H_test.go | 49 ++-- internal/scraper/scraper_I_test.go | 51 +++-- internal/scraper/scraper_J_test.go | 105 ++++----- internal/scraper/scraper_K_test.go | 59 ++--- internal/scraper/scraper_L_test.go | 87 +++---- internal/scraper/scraper_M_test.go | 175 +++++++------- internal/scraper/scraper_N_test.go | 79 +++---- internal/scraper/scraper_O_test.go | 51 +++-- internal/scraper/scraper_P_test.go | 167 +++++++------- internal/scraper/scraper_Q_test.go | 19 +- internal/scraper/scraper_R_test.go | 79 +++---- internal/scraper/scraper_S_test.go | 245 ++++++++++---------- internal/scraper/scraper_T_test.go | 277 ++++++++++++----------- internal/scraper/scraper_V_test.go | 43 ++-- internal/scraper/scraper_W_test.go | 67 +++--- internal/scraper/scraper_{0-9}_test.go | 13 +- internal/scraper/woop.go | 17 +- internal/server/handlers_recipes_test.go | 49 ++-- 36 files changed, 1426 insertions(+), 1377 deletions(-) diff --git a/internal/integrations/nextcloud_test.go b/internal/integrations/nextcloud_test.go index 29e9e464..0501a664 100644 --- a/internal/integrations/nextcloud_test.go +++ b/internal/integrations/nextcloud_test.go @@ -2,10 +2,6 @@ package integrations_test import ( "fmt" - "github.com/google/go-cmp/cmp" - "github.com/google/uuid" - "github.com/reaper47/recipya/internal/integrations" - "github.com/reaper47/recipya/internal/models" "io" "mime/multipart" "net/http" @@ -13,6 +9,11 @@ import ( "regexp" "testing" "time" + + "github.com/google/go-cmp/cmp" + "github.com/google/uuid" + "github.com/reaper47/recipya/internal/integrations" + "github.com/reaper47/recipya/internal/models" ) func TestNextcloudImport(t *testing.T) { @@ -121,15 +122,15 @@ func TestNextcloudImport(t *testing.T) { Keywords: []string{""}, Name: "Best Chocolate Chip Cookies", Nutrition: models.Nutrition{ - Calories: "146 kcal", - Cholesterol: "10 mg", - Fiber: "1 g", - Protein: "2 g", - SaturatedFat: "4 g", - Sodium: "76 mg", - TotalCarbohydrates: "19 g", - TotalFat: "8 g", - UnsaturatedFat: "0 g", + Calories: "146", + Cholesterol: "10", + Fiber: "1", + Protein: "2", + SaturatedFat: "4", + Sodium: "76", + TotalCarbohydrates: "19", + TotalFat: "8", + UnsaturatedFat: "0", }, UpdatedAt: t1, URL: "https://www.allrecipes.com/recipe/10813/best-chocolate-chip-cookies/", @@ -149,10 +150,10 @@ func TestNextcloudImport(t *testing.T) { Keywords: []string{"chips", "jesus"}, Name: "Jesus Buds", Nutrition: models.Nutrition{ - Calories: "450kcal", + Calories: "450", IsPerServing: true, - Protein: "2 g", - Sugars: "50g", + Protein: "2", + Sugars: "50", }, Times: times, UpdatedAt: t2, diff --git a/internal/models/recipe_test.go b/internal/models/recipe_test.go index 3341f219..885e73d2 100644 --- a/internal/models/recipe_test.go +++ b/internal/models/recipe_test.go @@ -3,18 +3,19 @@ package models_test import ( "bytes" "errors" - "github.com/PuerkitoBio/goquery" - "github.com/google/go-cmp/cmp" - "github.com/google/uuid" - "github.com/reaper47/recipya/internal/app" - "github.com/reaper47/recipya/internal/models" - "github.com/reaper47/recipya/internal/units" "io" "math" "net/url" "slices" "testing" "time" + + "github.com/PuerkitoBio/goquery" + "github.com/google/go-cmp/cmp" + "github.com/google/uuid" + "github.com/reaper47/recipya/internal/app" + "github.com/reaper47/recipya/internal/models" + "github.com/reaper47/recipya/internal/units" ) func BenchmarkRecipe_ConvertMeasurementSystem(b *testing.B) { @@ -747,8 +748,8 @@ func TestNutrition_Format(t *testing.T) { }, { name: "selected fields", - in: models.Nutrition{Calories: "354 kcal", Cholesterol: "207.44 ug", Fiber: "7.10 g"}, - want: "Per 100g: calories 354 kcal; cholesterol 207.44 ug; fiber 7.10 g", + in: models.Nutrition{Calories: "354 kcal", Cholesterol: "207.44 mg", Fiber: "7.10 g"}, + want: "Per 100g: calories 354 kcal; cholesterol 207.44 mg; fiber 7.10 g", }, { name: "all fields", @@ -764,7 +765,7 @@ func TestNutrition_Format(t *testing.T) { TotalFat: "20g", UnsaturatedFat: "15g", }, - want: "Per 100g: calories 150 kcal; total carbohydrates 89g; sugar 66g; protein 8g; total fat 20g; saturated fat 1g; cholesterol 34mg; fiber 6g", + want: "Per 100g: calories 150 kcal; total carbohydrates 89 g; sugar 66 g; protein 8 g; total fat 20 g; saturated fat 1 g; unsaturated fat 15 g; cholesterol 34 mg; sodium 567 mg; fiber 6 g", }, } for _, tc := range testcases { diff --git a/internal/models/schema-recipe_test.go b/internal/models/schema-recipe_test.go index 43ad4fae..e7b25cf9 100644 --- a/internal/models/schema-recipe_test.go +++ b/internal/models/schema-recipe_test.go @@ -305,18 +305,18 @@ func TestSchemaType_UnmarshalJSON(t *testing.T) { func TestNutritionSchema_UnmarshalJSON(t *testing.T) { want := models.RecipeSchema{ NutritionSchema: &models.NutritionSchema{ - Calories: "420 kcal", - Carbohydrates: "4 g", - Cholesterol: "3 mg", - Fat: "5 g", - Fiber: "7 g", - Protein: "9 g", - SaturatedFat: "10 g", + Calories: "420", + Carbohydrates: "4", + Cholesterol: "3", + Fat: "5", + Fiber: "7", + Protein: "9", + SaturatedFat: "10.5", Servings: "4", - Sodium: "350 mg", - Sugar: "13 g", - TransFat: "2 g", - UnsaturatedFat: "54 g", + Sodium: "350", + Sugar: "13", + TransFat: "2", + UnsaturatedFat: "54", }, } @@ -333,7 +333,7 @@ func TestNutritionSchema_UnmarshalJSON(t *testing.T) { "fatContent": "5gram", "fiberContent": "7grams", "proteinContent": "9g", - "saturatedFatContent": "10g", + "saturatedFatContent": "10.5g, saturated fat", "servingSize": "makes 4 loaves", "sodiumContent": "350milligram", "sugarContent": "13g", @@ -350,7 +350,7 @@ func TestNutritionSchema_UnmarshalJSON(t *testing.T) { "fatContent": "5 g", "fiberContent": "7 g", "proteinContent": "9 g", - "saturatedFatContent": "10 g", + "saturatedFatContent": "10.5 g", "servingSize": "makes 4 loaves", "sodiumContent": "350 mg", "sugarContent": "13 g", @@ -367,7 +367,7 @@ func TestNutritionSchema_UnmarshalJSON(t *testing.T) { "fatContent": "5 gram", "fiberContent": "7 gram", "proteinContent": "9 gram", - "saturatedFatContent": "10 gram", + "saturatedFatContent": "10.5 gram, saturated fat", "servingSize": "makes 4 loaf", "sodiumContent": "350 milligram", "sugarContent": "13 gram", @@ -384,7 +384,7 @@ func TestNutritionSchema_UnmarshalJSON(t *testing.T) { "fatContent": "5 grams", "fiberContent": "7 grams", "proteinContent": "9 grams", - "saturatedFatContent": "10 grams", + "saturatedFatContent": "10,5 grams, saturated fat", "servingSize": "makes 4 loaves", "sodiumContent": "350 milligrams", "sugarContent": "13 grams", @@ -401,7 +401,7 @@ func TestNutritionSchema_UnmarshalJSON(t *testing.T) { "fatContent": "5", "fiberContent": "7", "proteinContent": "9", - "saturatedFatContent": "10", + "saturatedFatContent": "10,5", "servingSize": "4", "sodiumContent": "350", "sugarContent": "13", @@ -418,7 +418,7 @@ func TestNutritionSchema_UnmarshalJSON(t *testing.T) { "fatContent": 5, "fiberContent": 7, "proteinContent": 9, - "saturatedFatContent": 10, + "saturatedFatContent": 10.5, "servingSize": 4, "sodiumContent": 350, "sugarContent": 13, diff --git a/internal/scraper/bettybossi.go b/internal/scraper/bettybossi.go index be36eb8b..107eaa7f 100644 --- a/internal/scraper/bettybossi.go +++ b/internal/scraper/bettybossi.go @@ -2,11 +2,12 @@ package scraper import ( "encoding/json" - "github.com/PuerkitoBio/goquery" - "github.com/reaper47/recipya/internal/models" "strconv" "strings" "time" + + "github.com/PuerkitoBio/goquery" + "github.com/reaper47/recipya/internal/models" ) type bettibossi struct { @@ -130,7 +131,7 @@ func scrapeBettybossi(root *goquery.Document) (models.RecipeSchema, error) { var ns models.NutritionSchema for _, n := range b.Naehrwerte { - v := strconv.Itoa(n.Wert1) + " " + n.Wert1Einheit + v := strconv.Itoa(n.Wert1) // + " " + n.Wert1Einheit 2024-07-01: Commented out this section (left the original code as it was in German in case we need to revert) as we only scrape the digits, as part of https://github.com/reaper47/recipya/pull/382 switch n.Kurzbezeichnung { case "E": if n.Bezeichnung == "Eiweiss" { diff --git a/internal/scraper/bodybuilding.go b/internal/scraper/bodybuilding.go index 3c90f8ee..c10bde66 100644 --- a/internal/scraper/bodybuilding.go +++ b/internal/scraper/bodybuilding.go @@ -1,10 +1,12 @@ package scraper import ( + "strings" + "github.com/PuerkitoBio/goquery" "github.com/reaper47/recipya/internal/models" "github.com/reaper47/recipya/internal/utils/extensions" - "strings" + "github.com/reaper47/recipya/internal/utils/regex" ) func scrapeBodybuilding(root *goquery.Document) (models.RecipeSchema, error) { @@ -26,13 +28,13 @@ func scrapeBodybuilding(root *goquery.Document) (models.RecipeSchema, error) { nodes.Each(func(_ int, sel *goquery.Selection) { switch sel.Text() { case "Calories": - n.Calories = sel.Prev().Text() + " kcal" + n.Calories = regex.Digit.FindString(sel.Prev().Text()) case "Carbs": - n.Carbohydrates = sel.Prev().Text() + n.Carbohydrates = regex.Digit.FindString(sel.Prev().Text()) case "Protein": - n.Protein = sel.Prev().Text() + n.Protein = regex.Digit.FindString(sel.Prev().Text()) case "Fat": - n.Fat = sel.Prev().Text() + n.Fat = regex.Digit.FindString(sel.Prev().Text()) } }) rs.NutritionSchema = &n diff --git a/internal/scraper/cdkitchen.go b/internal/scraper/cdkitchen.go index dbae4125..c3af7707 100644 --- a/internal/scraper/cdkitchen.go +++ b/internal/scraper/cdkitchen.go @@ -1,10 +1,12 @@ package scraper import ( - "github.com/PuerkitoBio/goquery" - "github.com/reaper47/recipya/internal/models" "strconv" "strings" + + "github.com/PuerkitoBio/goquery" + "github.com/reaper47/recipya/internal/models" + "github.com/reaper47/recipya/internal/utils/regex" ) func scrapeCdKitchen(root *goquery.Document) (models.RecipeSchema, error) { @@ -38,17 +40,17 @@ func scrapeCdKitchen(root *goquery.Document) (models.RecipeSchema, error) { node = content.Find("span[itemprop='nutrition']") rs.NutritionSchema = &models.NutritionSchema{ - Calories: node.Find("span[itemprop='calories']").Text(), - Carbohydrates: node.Find(".carbohydrateContent").Text(), - Sugar: node.Find(".sugarContent").Text(), - Protein: node.Find(".proteinContent").Text(), - Fat: node.Find(".fatContent").Text(), - SaturatedFat: node.Find(".saturatedFatContent").Text(), - Cholesterol: node.Find(".cholesterolContent").Text(), - Sodium: node.Find(".sodiumContent").Text(), - Fiber: node.Find(".fiberContent").Text(), - TransFat: node.Find(".transFatContent").Text(), - UnsaturatedFat: node.Find(".unsaturatedFatContent").Text(), + Calories: regex.Digit.FindString(node.Find("span[itemprop='calories']").Text()), + Carbohydrates: regex.Digit.FindString(node.Find(".carbohydrateContent").Text()), + Sugar: regex.Digit.FindString(node.Find(".sugarContent").Text()), + Protein: regex.Digit.FindString(node.Find(".proteinContent").Text()), + Fat: regex.Digit.FindString(node.Find(".fatContent").Text()), + SaturatedFat: regex.Digit.FindString(node.Find(".saturatedFatContent").Text()), + Cholesterol: regex.Digit.FindString(node.Find(".cholesterolContent").Text()), + Sodium: regex.Digit.FindString(node.Find(".sodiumContent").Text()), + Fiber: regex.Digit.FindString(node.Find(".fiberContent").Text()), + TransFat: regex.Digit.FindString(node.Find(".transFatContent").Text()), + UnsaturatedFat: regex.Digit.FindString(node.Find(".unsaturatedFatContent").Text()), } rs.CookTime, _ = content.Find("meta[itemprop='cookTime']").Attr("content") diff --git a/internal/scraper/closetcooking.go b/internal/scraper/closetcooking.go index 6ac555ba..5f34320b 100644 --- a/internal/scraper/closetcooking.go +++ b/internal/scraper/closetcooking.go @@ -1,9 +1,11 @@ package scraper import ( + "strings" + "github.com/PuerkitoBio/goquery" "github.com/reaper47/recipya/internal/models" - "strings" + "github.com/reaper47/recipya/internal/utils/regex" ) func scrapeClosetcooking(root *goquery.Document) (models.RecipeSchema, error) { @@ -39,17 +41,17 @@ func scrapeClosetcooking(root *goquery.Document) (models.RecipeSchema, error) { rs.Keywords.Values = strings.Join(xk, ",") rs.NutritionSchema = &models.NutritionSchema{ - Calories: root.Find("span[itemprop='calories']").Text(), - Carbohydrates: root.Find("span[itemprop='carbohydrateContent']").Text(), - Sugar: root.Find("span[itemprop='sugarContent']").Text(), - Protein: root.Find("span[itemprop='proteinContent']").Text(), - Fat: root.Find("span[itemprop='fatContent']").Text(), - SaturatedFat: root.Find("span[itemprop='saturatedFatContent']").Text(), - Cholesterol: root.Find("span[itemprop='cholesterolContent']").Text(), - Sodium: root.Find("span[itemprop='sodiumContent']").Text(), - Fiber: root.Find("span[itemprop='fiberContent']").Text(), - TransFat: root.Find("span[itemprop='transFatContent']").Text(), - UnsaturatedFat: root.Find("span[itemprop='unsaturatedFatContent']").Text(), + Calories: regex.Digit.FindString(root.Find("span[itemprop='calories']").Text()), + Carbohydrates: regex.Digit.FindString(root.Find("span[itemprop='carbohydrateContent']").Text()), + Sugar: regex.Digit.FindString(root.Find("span[itemprop='sugarContent']").Text()), + Protein: regex.Digit.FindString(root.Find("span[itemprop='proteinContent']").Text()), + Fat: regex.Digit.FindString(root.Find("span[itemprop='fatContent']").Text()), + SaturatedFat: regex.Digit.FindString(root.Find("span[itemprop='saturatedFatContent']").Text()), + Cholesterol: regex.Digit.FindString(root.Find("span[itemprop='cholesterolContent']").Text()), + Sodium: regex.Digit.FindString(root.Find("span[itemprop='sodiumContent']").Text()), + Fiber: regex.Digit.FindString(root.Find("span[itemprop='fiberContent']").Text()), + TransFat: regex.Digit.FindString(root.Find("span[itemprop='transFatContent']").Text()), + UnsaturatedFat: regex.Digit.FindString(root.Find("span[itemprop='unsaturatedFatContent']").Text()), } rs.Yield.Value = findYield(root.Find("span[itemprop='recipeYield']").Text()) diff --git a/internal/scraper/fitmencook.go b/internal/scraper/fitmencook.go index 3e660027..2e0d7185 100644 --- a/internal/scraper/fitmencook.go +++ b/internal/scraper/fitmencook.go @@ -1,10 +1,11 @@ package scraper import ( + "strings" + "github.com/PuerkitoBio/goquery" "github.com/reaper47/recipya/internal/models" "github.com/reaper47/recipya/internal/utils/regex" - "strings" ) func scrapeFitMenCook(root *goquery.Document) (models.RecipeSchema, error) { @@ -59,22 +60,22 @@ func scrapeFitMenCook(root *goquery.Document) (models.RecipeSchema, error) { var n models.NutritionSchema nNodes := root.Find(".fmc_macro_cals") - n.Calories = nNodes.First().Find("span").Text() + n.Calories = regex.Digit.FindString(nNodes.First().Find("span").Text()) nNodes.NextAll().Each(func(_ int, s *goquery.Selection) { switch strings.ToLower(s.Nodes[0].FirstChild.Data) { case "protein": - n.Protein = s.Find("span").Text() + n.Protein = regex.Digit.FindString(s.Find("span").Text()) case "fats": - n.Fat = s.Find("span").Text() + n.Fat = regex.Digit.FindString(s.Find("span").Text()) case "carbs": - n.Carbohydrates = s.Find("span").Text() + n.Carbohydrates = regex.Digit.FindString(s.Find("span").Text()) case "sodium": - n.Sodium = s.Find("span").Text() + n.Sodium = regex.Digit.FindString(s.Find("span").Text()) case "fiber": - n.Fiber = s.Find("span").Text() + n.Fiber = regex.Digit.FindString(s.Find("span").Text()) case "sugar": - n.Sugar = s.Find("span").Text() + n.Sugar = regex.Digit.FindString(s.Find("span").Text()) } }) rs.NutritionSchema = &n diff --git a/internal/scraper/myplate.go b/internal/scraper/myplate.go index 539618d8..0590a2d0 100644 --- a/internal/scraper/myplate.go +++ b/internal/scraper/myplate.go @@ -2,10 +2,12 @@ package scraper import ( "fmt" - "github.com/PuerkitoBio/goquery" "strings" + "github.com/PuerkitoBio/goquery" + "github.com/reaper47/recipya/internal/models" + "github.com/reaper47/recipya/internal/utils/regex" ) func scrapeMyPlate(root *goquery.Document) (models.RecipeSchema, error) { @@ -43,15 +45,15 @@ func scrapeMyPlate(root *goquery.Document) (models.RecipeSchema, error) { }) rs.NutritionSchema = &models.NutritionSchema{ - Calories: root.Find(".total_calories td").Last().Text(), - Carbohydrates: root.Find(".carbohydrates td").Last().Text(), - Cholesterol: root.Find(".cholesterol td").Last().Text(), - Fat: root.Find(".total_fat td").Last().Text(), - Fiber: root.Find(".dietary_fiber td").Last().Text(), - Protein: root.Find(".protein td").Last().Text(), - SaturatedFat: root.Find(".saturated_fat td").Last().Text(), - Sodium: root.Find(".sodium td").Last().Text(), - Sugar: root.Find(".total_sugars td").Last().Text(), + Calories: regex.Digit.FindString(root.Find(".total_calories td").Last().Text()), + Carbohydrates: regex.Digit.FindString(root.Find(".carbohydrates td").Last().Text()), + Cholesterol: regex.Digit.FindString(root.Find(".cholesterol td").Last().Text()), + Fat: regex.Digit.FindString(root.Find(".total_fat td").Last().Text()), + Fiber: regex.Digit.FindString(root.Find(".dietary_fiber td").Last().Text()), + Protein: regex.Digit.FindString(root.Find(".protein td").Last().Text()), + SaturatedFat: regex.Digit.FindString(root.Find(".saturated_fat td").Last().Text()), + Sodium: regex.Digit.FindString(root.Find(".sodium td").Last().Text()), + Sugar: regex.Digit.FindString(root.Find(".total_sugars td").Last().Text()), } return rs, nil diff --git a/internal/scraper/projectgezond.go b/internal/scraper/projectgezond.go index 2fb79e1f..668a16c1 100644 --- a/internal/scraper/projectgezond.go +++ b/internal/scraper/projectgezond.go @@ -1,9 +1,11 @@ package scraper import ( + "strings" + "github.com/PuerkitoBio/goquery" "github.com/reaper47/recipya/internal/models" - "strings" + "github.com/reaper47/recipya/internal/utils/regex" ) func scrapeProjectgezond(root *goquery.Document) (models.RecipeSchema, error) { @@ -69,11 +71,11 @@ func scrapeProjectgezond(root *goquery.Document) (models.RecipeSchema, error) { } rs.NutritionSchema = &models.NutritionSchema{ - Calories: cal + " kcal", - Carbohydrates: carbs, - Fat: fat, - Fiber: fiber, - Protein: protein, + Calories: regex.Digit.FindString(cal), + Carbohydrates: regex.Digit.FindString(carbs), + Fat: regex.Digit.FindString(fat), + Fiber: regex.Digit.FindString(fiber), + Protein: regex.Digit.FindString(protein), } return rs, nil diff --git a/internal/scraper/quitoque.go b/internal/scraper/quitoque.go index 0417de22..753e2ea2 100644 --- a/internal/scraper/quitoque.go +++ b/internal/scraper/quitoque.go @@ -3,11 +3,12 @@ package scraper import ( "encoding/json" "errors" - "github.com/reaper47/recipya/internal/models" "io" "net/http" "strconv" "strings" + + "github.com/reaper47/recipya/internal/models" ) type quitoque struct { @@ -241,15 +242,15 @@ func (s *Scraper) scrapeQuitoque(rawURL string) (models.RecipeSchema, error) { if len(q.Data.Recipe.NutritionalInformations) > 0 { n := q.Data.Recipe.NutritionalInformations[0] ns = models.NutritionSchema{ - Calories: strconv.FormatFloat(n.KiloCalorie, 'g', 10, 64) + " kcal", - Carbohydrates: strconv.FormatFloat(n.Carbohydrate, 'g', 10, 64) + " g", - Fat: strconv.FormatFloat(n.Fat, 'g', 10, 64) + " g", - Fiber: strconv.FormatFloat(n.Fiber, 'g', 10, 64) + " g", - Protein: strconv.FormatFloat(n.Protein, 'g', 10, 64) + " g", - SaturatedFat: strconv.FormatFloat(n.SaturatedFat, 'g', 10, 64) + " g", + Calories: strconv.FormatFloat(n.KiloCalorie, 'g', 10, 64), + Carbohydrates: strconv.FormatFloat(n.Carbohydrate, 'g', 10, 64), + Fat: strconv.FormatFloat(n.Fat, 'g', 10, 64), + Fiber: strconv.FormatFloat(n.Fiber, 'g', 10, 64), + Protein: strconv.FormatFloat(n.Protein, 'g', 10, 64), + SaturatedFat: strconv.FormatFloat(n.SaturatedFat, 'g', 10, 64), Servings: strconv.Itoa(n.NbPerson), - Sodium: strconv.FormatFloat(n.Salt, 'g', 10, 64) + " g", - Sugar: strconv.FormatFloat(n.SugarCarbohydrate, 'g', 10, 64) + " g", + Sodium: strconv.FormatFloat(n.Salt, 'g', 10, 64), + Sugar: strconv.FormatFloat(n.SugarCarbohydrate, 'g', 10, 64), } } diff --git a/internal/scraper/scraper_A_test.go b/internal/scraper/scraper_A_test.go index 193b7419..a321b945 100644 --- a/internal/scraper/scraper_A_test.go +++ b/internal/scraper/scraper_A_test.go @@ -1,8 +1,9 @@ package scraper_test import ( - "github.com/reaper47/recipya/internal/models" "testing" + + "github.com/reaper47/recipya/internal/models" ) func TestScraper_A(t *testing.T) { @@ -147,16 +148,16 @@ func TestScraper_A(t *testing.T) { }, }, NutritionSchema: &models.NutritionSchema{ - Calories: "149 calories", - Carbohydrates: "14.6 g", - Cholesterol: "3.6 mg", - Fat: "9.2 g", - Fiber: "6.5 g", - Protein: "6.5 g", - SaturatedFat: "2.1 g", - Sodium: "271.1 mg", - Sugar: "3 g", - TransFat: "0 g", + Calories: "149", + Carbohydrates: "14.6", + Cholesterol: "3.6", + Fat: "9.2", + Fiber: "6.5", + Protein: "6.5", + SaturatedFat: "2.1", + Sodium: "271.1", + Sugar: "3", + TransFat: "0", }, PrepTime: "PT10M", CookTime: "PT7M", @@ -194,16 +195,16 @@ func TestScraper_A(t *testing.T) { }, Name: "Easy Grape Jelly Meatballs Recipe", NutritionSchema: &models.NutritionSchema{ - Calories: "140 kcal", - Carbohydrates: "34 g", - Fat: "0.2 g", - Fiber: "1 g", - Protein: "0.4 g", - SaturatedFat: "0.02 g", + Calories: "140", + Carbohydrates: "34", + Fat: "0.2", + Fiber: "1", + Protein: "0.4", + SaturatedFat: "0.02", Servings: "1", - Sodium: "377 mg", - Sugar: "26 g", - UnsaturatedFat: "0.08 g", + Sodium: "377", + Sugar: "26", + UnsaturatedFat: "0.08", }, PrepTime: "PT5M", TotalTime: "PT245M", @@ -323,11 +324,11 @@ func TestScraper_A(t *testing.T) { }, Name: "Boeuf bourguignon uit de oven met geroosterde spruiten", NutritionSchema: &models.NutritionSchema{ - Calories: "640 kcal", - Carbohydrates: "23 g", - Fat: "33 g", - Protein: "52 g", - SaturatedFat: "12 g", + Calories: "640", + Carbohydrates: "23", + Fat: "33", + Protein: "52", + SaturatedFat: "12", }, PrepTime: "PT30M", Tools: &models.Tools{Values: []models.HowToItem{}}, @@ -383,7 +384,7 @@ func TestScraper_A(t *testing.T) { }, Name: "Εύκολος μπακλαβάς", NutritionSchema: &models.NutritionSchema{ - Calories: "508 calories", + Calories: "508", }, PrepTime: "PT35M", Tools: &models.Tools{Values: []models.HowToItem{}}, @@ -482,15 +483,15 @@ func TestScraper_A(t *testing.T) { }, Name: "Best Chocolate Chip Cookies", NutritionSchema: &models.NutritionSchema{ - Calories: "146 kcal", - Carbohydrates: "19 g", - Cholesterol: "10 mg", - Fat: "8 g", - Fiber: "1 g", - Protein: "2 g", - SaturatedFat: "4 g", - Sodium: "76 mg", - UnsaturatedFat: "0 g", + Calories: "146", + Carbohydrates: "19", + Cholesterol: "10", + Fat: "8", + Fiber: "1", + Protein: "2", + SaturatedFat: "4", + Sodium: "76", + UnsaturatedFat: "0", }, PrepTime: "PT20M", TotalTime: "PT30M", @@ -658,14 +659,14 @@ func TestScraper_A(t *testing.T) { Values: "lemon garlic butter salmon, lemon garlic salmon, lemon honey garlic salmon", }, NutritionSchema: &models.NutritionSchema{ - Calories: "279 kcal", - Carbohydrates: "9.3 g", - Fat: "17.2 g", - Fiber: "0.1 g", - Protein: "21.3 g", - SaturatedFat: "7.6 g", + Calories: "279", + Carbohydrates: "9.3", + Fat: "17.2", + Fiber: "0.1", + Protein: "21.3", + SaturatedFat: "7.6", Servings: "1", - Sugar: "8.2 g", + Sugar: "8.2", }, Name: "Honey Lemon Garlic Salmon", PrepTime: "PT10M", @@ -716,15 +717,16 @@ func TestScraper_A(t *testing.T) { }, Name: "Marbled Blueberry Bundt Cake", NutritionSchema: &models.NutritionSchema{ - Carbohydrates: "76 grams", - Cholesterol: "93 miligrams", - Fat: "19 grams", - Protein: "6 grams", - SaturatedFat: "11 grams", - Sodium: "375 miligrams", - Sugar: "49 grams", - TransFat: "0 grams", - UnsaturatedFat: "6 grams", + Calories: "500", + Carbohydrates: "76", + Cholesterol: "93", + Fat: "19", + Protein: "6", + SaturatedFat: "11", + Sodium: "375", + Sugar: "49", + TransFat: "0", + UnsaturatedFat: "6", }, Tools: &models.Tools{ Values: []models.HowToItem{ @@ -891,10 +893,10 @@ func TestScraper_A(t *testing.T) { }, Name: "Kycklingpasta med spenat och parmesan", NutritionSchema: &models.NutritionSchema{ - Calories: "575 kcal", - Carbohydrates: "57 g", - Fat: "22 g", - Protein: "34 g", + Calories: "575", + Carbohydrates: "57", + Fat: "22", + Protein: "34", }, TotalTime: "PT00M", Yield: &models.Yield{Value: 4}, @@ -994,18 +996,18 @@ func TestScraper_A(t *testing.T) { }, Name: "Slow Cooker Beef Stroganoff", NutritionSchema: &models.NutritionSchema{ - Calories: "575 kcal", - Carbohydrates: "30 g", - Cholesterol: "191 mg", - Fat: "23 g", - Fiber: "2 g", - Protein: "62 g", - SaturatedFat: "11 g", + Calories: "575", + Carbohydrates: "30", + Cholesterol: "191", + Fat: "23", + Fiber: "2", + Protein: "62", + SaturatedFat: "11", Servings: "1", - Sodium: "1288 mg", - Sugar: "6 g", - TransFat: "1 g", - UnsaturatedFat: "12 g", + Sodium: "1288", + Sugar: "6", + TransFat: "1", + UnsaturatedFat: "12", }, PrepTime: "PT10M", TotalTime: "PT490M", diff --git a/internal/scraper/scraper_B_test.go b/internal/scraper/scraper_B_test.go index 90f59625..614baef4 100644 --- a/internal/scraper/scraper_B_test.go +++ b/internal/scraper/scraper_B_test.go @@ -1,8 +1,9 @@ package scraper_test import ( - "github.com/reaper47/recipya/internal/models" "testing" + + "github.com/reaper47/recipya/internal/models" ) func TestScraper_B(t *testing.T) { @@ -40,7 +41,7 @@ func TestScraper_B(t *testing.T) { }, Name: "Italian Roasted Potatoes", NutritionSchema: &models.NutritionSchema{ - Calories: "194 kcal", + Calories: "194", Servings: "1", }, PrepTime: "PT10M", @@ -85,18 +86,18 @@ func TestScraper_B(t *testing.T) { Keywords: &models.Keywords{Values: "pancake, potato"}, Name: "Irish Potato Farls Recipe", NutritionSchema: &models.NutritionSchema{ - Calories: "165 kcal", - Carbohydrates: "25 g", - Cholesterol: "15 mg", - Fat: "6 g", - Fiber: "2 g", - Protein: "3 g", - SaturatedFat: "4 g", + Calories: "165", + Carbohydrates: "25", + Cholesterol: "15", + Fat: "6", + Fiber: "2", + Protein: "3", + SaturatedFat: "4", Servings: "1", - Sodium: "519 mg", - Sugar: "1 g", - TransFat: "1 g", - UnsaturatedFat: "3 g", + Sodium: "519", + Sugar: "1", + TransFat: "1", + UnsaturatedFat: "3", }, PrepTime: "PT30M", Yield: &models.Yield{Value: 8}, @@ -185,13 +186,13 @@ func TestScraper_B(t *testing.T) { }, Name: "Healthy sausage casserole", NutritionSchema: &models.NutritionSchema{ - Calories: "348kcal", - Carbohydrates: "33.5g", - Fat: "7g", - Fiber: "9.5g", - Protein: "34g", - SaturatedFat: "2g", - Sugar: "18g", + Calories: "348", + Carbohydrates: "33.5", + Fat: "7", + Fiber: "9.5", + Protein: "34", + SaturatedFat: "2", + Sugar: "18", }, PrepTime: "PT30M", Tools: &models.Tools{Values: []models.HowToItem{}}, @@ -243,15 +244,15 @@ func TestScraper_B(t *testing.T) { }, Name: "Three-cheese risotto", NutritionSchema: &models.NutritionSchema{ - Calories: "451 calories", - Carbohydrates: "42 grams", - Fat: "20 grams", - Fiber: "2 grams", - Protein: "17 grams", - SaturatedFat: "12 grams", + Calories: "451", + Carbohydrates: "42", + Fat: "20", + Fiber: "2", + Protein: "17", + SaturatedFat: "12", Servings: "1", - Sodium: "0.9 milligram", - Sugar: "4 grams", + Sodium: "0.9", + Sugar: "4", }, PrepTime: "PT20M", Tools: &models.Tools{Values: []models.HowToItem{}}, @@ -303,15 +304,15 @@ func TestScraper_B(t *testing.T) { }, Name: "Three-cheese risotto", NutritionSchema: &models.NutritionSchema{ - Calories: "451 calories", - Carbohydrates: "42 grams", - Fat: "20 grams", - Fiber: "2 grams", - Protein: "17 grams", - SaturatedFat: "12 grams", + Calories: "451", + Carbohydrates: "42", + Fat: "20", + Fiber: "2", + Protein: "17", + SaturatedFat: "12", Servings: "1", - Sodium: "0.9 milligram", - Sugar: "4 grams", + Sodium: "0.9", + Sugar: "4", }, PrepTime: "PT20M", Tools: &models.Tools{Values: []models.HowToItem{}}, @@ -354,15 +355,15 @@ func TestScraper_B(t *testing.T) { }, Name: "Pan-fried salmon", NutritionSchema: &models.NutritionSchema{ - Calories: "524 calories", - Carbohydrates: "0.3 grams", - Fat: "44 grams", - Fiber: "0.3 grams", - Protein: "31 grams", - SaturatedFat: "15 grams", + Calories: "524", + Carbohydrates: "0.3", + Fat: "44", + Fiber: "0.3", + Protein: "31", + SaturatedFat: "15", Servings: "2", - Sodium: "0.17 milligram", - Sugar: "0.3 grams", + Sodium: "0.17", + Sugar: "0.3", }, PrepTime: "PT1M", Tools: &models.Tools{Values: []models.HowToItem{}}, @@ -412,14 +413,14 @@ func TestScraper_B(t *testing.T) { }}, Name: "Kokos-Schokolade-Würfel", NutritionSchema: &models.NutritionSchema{ - Calories: "353 kcal", - Carbohydrates: "44 g", - Fat: "18 g", - Fiber: "1 g", - Protein: "4 g", - SaturatedFat: "11 g", - Sodium: "0 g", - Sugar: "30 g", + Calories: "353", + Carbohydrates: "44", + Fat: "18", + Fiber: "1", + Protein: "4", + SaturatedFat: "11", + Sodium: "0", + Sugar: "30", }, PrepTime: "PT20M", Tools: &models.Tools{Values: []models.HowToItem{}}, @@ -470,16 +471,16 @@ func TestScraper_B(t *testing.T) { Name: "Spinach Mushroom Quiche", NutritionSchema: &models.NutritionSchema{ Calories: "260", - Carbohydrates: "16 g", - Cholesterol: "120 mg", - Fat: "2 ", - Fiber: "0 g", - Protein: "9 g", - SaturatedFat: "6 g", + Carbohydrates: "16", + Cholesterol: "120", + Fat: "2", + Fiber: "0", + Protein: "9", + SaturatedFat: "6", Servings: "1", - Sodium: "340 mg", - Sugar: "4 g", - TransFat: "2 g", + Sodium: "340", + Sugar: "4", + TransFat: "2", UnsaturatedFat: "", }, PrepTime: "PT0H30M", @@ -535,18 +536,18 @@ func TestScraper_B(t *testing.T) { }, Name: "Vegetables in Coconut Milk (Sayur Lodeh)", NutritionSchema: &models.NutritionSchema{ - Calories: "269 kcal", - Carbohydrates: "22 g", - Cholesterol: "126 mg", - Fat: "17 g", - Fiber: "6 g", - Protein: "14 g", - SaturatedFat: "11 g", + Calories: "269", + Carbohydrates: "22", + Cholesterol: "126", + Fat: "17", + Fiber: "6", + Protein: "14", + SaturatedFat: "11", Servings: "1", - Sodium: "789 mg", - Sugar: "11 g", - TransFat: "1 g", - UnsaturatedFat: "4 g", + Sodium: "789", + Sugar: "11", + TransFat: "1", + UnsaturatedFat: "4", }, PrepTime: "PT15M", TotalTime: "PT35M", @@ -604,15 +605,15 @@ func TestScraper_B(t *testing.T) { }, Name: "Vegan Mexican Stuffed Peppers", NutritionSchema: &models.NutritionSchema{ - Calories: "409.7 kcal", - Carbohydrates: "69.8 g", - Fat: "10.3 g", - Fiber: "11.4 g", - Protein: "12.4 g", - SaturatedFat: "2.4 g", + Calories: "409.7", + Carbohydrates: "69.8", + Fat: "10.3", + Fiber: "11.4", + Protein: "12.4", + SaturatedFat: "2.4", Servings: "1", - Sodium: "703.9 mg", - Sugar: "8.7 g", + Sodium: "703.9", + Sugar: "8.7", }, PrepTime: "PT20M", Yield: &models.Yield{Value: 4}, @@ -657,17 +658,17 @@ func TestScraper_B(t *testing.T) { }, Name: "Vegetable Tempura - Japanese", NutritionSchema: &models.NutritionSchema{ - Calories: "300 calories", - Carbohydrates: "60.0488662958771 g", - Cholesterol: "52.445 mg", - Fat: "2.32476678639706 g", - Fiber: "5.44774018914959 g", - Protein: "11.4823529627363 g", - SaturatedFat: "0.619135359073004 g", + Calories: "300", + Carbohydrates: "60.0488662958771", + Cholesterol: "52.445", + Fat: "2.32476678639706", + Fiber: "5.44774018914959", + Protein: "11.4823529627363", + SaturatedFat: "0.619135359073004", Servings: "1", - Sodium: "50.8475852783613 mg", - Sugar: "54.6011261067275 g", - TransFat: "0.476087607733719 g", + Sodium: "50.8475852783613", + Sugar: "54.6011261067275", + TransFat: "0.476087607733719", }, PrepTime: "PT30M", Tools: &models.Tools{Values: []models.HowToItem{}}, @@ -857,18 +858,18 @@ func TestScraper_B(t *testing.T) { }, Name: "Apple Dutch Baby Pancake", NutritionSchema: &models.NutritionSchema{ - Calories: "248 kcal", - Carbohydrates: "25 g", - Cholesterol: "139 mg", - Fat: "14 g", - Fiber: "1 g", - Protein: "6 g", - SaturatedFat: "8 g", + Calories: "248", + Carbohydrates: "25", + Cholesterol: "139", + Fat: "14", + Fiber: "1", + Protein: "6", + SaturatedFat: "8", Servings: "1", - Sodium: "218 mg", - Sugar: "13 g", - TransFat: "0.3 g", - UnsaturatedFat: "5 g", + Sodium: "218", + Sugar: "13", + TransFat: "0.3", + UnsaturatedFat: "5", }, PrepTime: "PT10M", Tools: &models.Tools{Values: []models.HowToItem{}}, @@ -1111,10 +1112,10 @@ func TestScraper_B(t *testing.T) { Keywords: &models.Keywords{Values: "Dinner,Lunch"}, Name: "Beef Teriyaki Rice and Stir Fry", NutritionSchema: &models.NutritionSchema{ - Calories: "352 kcal", - Carbohydrates: "38 g", - Fat: "5 g", - Protein: "40 g", + Calories: "352", + Carbohydrates: "38", + Fat: "5", + Protein: "40", }, PrepTime: "PT5M", Tools: &models.Tools{Values: []models.HowToItem{}}, @@ -1283,17 +1284,17 @@ func TestScraper_B(t *testing.T) { }, Name: "Mini Meatloaves", NutritionSchema: &models.NutritionSchema{ - Calories: "356 kcal", - Carbohydrates: "10 g", - Cholesterol: "121 mg", - Fat: "25 g", - Fiber: "1 g", - Protein: "23 g", - SaturatedFat: "9 g", + Calories: "356", + Carbohydrates: "10", + Cholesterol: "121", + Fat: "25", + Fiber: "1", + Protein: "23", + SaturatedFat: "9", Servings: "1", - Sodium: "474 mg", - Sugar: "2 g", - TransFat: "1 g", + Sodium: "474", + Sugar: "2", + TransFat: "1", }, PrepTime: "PT10M", TotalTime: "PT35M", @@ -1347,14 +1348,14 @@ func TestScraper_B(t *testing.T) { }, Name: "Easy Vegetable Stir Fry", NutritionSchema: &models.NutritionSchema{ - Calories: "209 kcal", - Carbohydrates: "27 g", + Calories: "209", + Carbohydrates: "27", Cholesterol: "", - Fat: "9 g", - Fiber: "6 g", - Protein: "8 g", + Fat: "9", + Fiber: "6", + Protein: "8", SaturatedFat: "", - Sodium: "869 mg", + Sodium: "869", Sugar: "", TransFat: "", UnsaturatedFat: ""}, diff --git a/internal/scraper/scraper_C_test.go b/internal/scraper/scraper_C_test.go index 7afeb135..aebfbbac 100644 --- a/internal/scraper/scraper_C_test.go +++ b/internal/scraper/scraper_C_test.go @@ -1,8 +1,9 @@ package scraper_test import ( - "github.com/reaper47/recipya/internal/models" "testing" + + "github.com/reaper47/recipya/internal/models" ) func TestScraper_C(t *testing.T) { @@ -63,16 +64,16 @@ func TestScraper_C(t *testing.T) { }, Name: "Butter Chicken", NutritionSchema: &models.NutritionSchema{ - Calories: "580 kcal", - Carbohydrates: "17 g", - Cholesterol: "250 mg", - Fat: "41 g", - Fiber: "3 g", - Protein: "36 g", - SaturatedFat: "19 g", + Calories: "580", + Carbohydrates: "17", + Cholesterol: "250", + Fat: "41", + Fiber: "3", + Protein: "36", + SaturatedFat: "19", Servings: "1", - Sodium: "1601 mg", - Sugar: "8 g", + Sodium: "1601", + Sugar: "8", }, PrepTime: "PT15M", TotalTime: "PT45M", @@ -119,18 +120,18 @@ func TestScraper_C(t *testing.T) { }, Name: "Balsamic Mushrooms with Herbed Veggie Mash", NutritionSchema: &models.NutritionSchema{ - Calories: "201 kcal", - Carbohydrates: "12 g", + Calories: "201", + Carbohydrates: "12", Cholesterol: "", - Fat: "16 g", - Fiber: "3 g", - Protein: "4 g", - SaturatedFat: "3 g", + Fat: "16", + Fiber: "3", + Protein: "4", + SaturatedFat: "3", Servings: "1", - Sodium: "310 mg", - Sugar: "5 g", - TransFat: "2 g", - UnsaturatedFat: "13 g", + Sodium: "310", + Sugar: "5", + TransFat: "2", + UnsaturatedFat: "13", }, PrepTime: "PT10M", TotalTime: "PT40M", @@ -190,10 +191,10 @@ func TestScraper_C(t *testing.T) { }, Keywords: &models.Keywords{}, NutritionSchema: &models.NutritionSchema{ - Calories: "565 calories", - Carbohydrates: "28 grams carbohydrates", - Fat: "34 grams fat", - Protein: "36 grams protein", + Calories: "565", + Carbohydrates: "28", + Fat: "34", + Protein: "36", }, Tools: &models.Tools{Values: []models.HowToItem{}}, URL: "https://www.cdkitchen.com/recipes/recs/285/MerleHaggardsRainbowStew65112.shtml", @@ -294,10 +295,10 @@ func TestScraper_C(t *testing.T) { }, Name: "Knusprige Ofenkartoffeln", NutritionSchema: &models.NutritionSchema{ - Calories: "389 kcal", - Carbohydrates: "53,93g", - Fat: "14,10g", - Protein: "8,52g", + Calories: "389", + Carbohydrates: "53.93", + Fat: "14.10", + Protein: "8.52", Servings: "1", }, PrepTime: "P0DT0H20M", @@ -394,15 +395,15 @@ func TestScraper_C(t *testing.T) { }, Name: "Crispy Baked Chicken Wings", NutritionSchema: &models.NutritionSchema{ - Calories: "204 kcal", - Cholesterol: "71 mg", - Fat: "15 g", - Protein: "17 g", - SaturatedFat: "4 g", + Calories: "204", + Cholesterol: "71", + Fat: "15", + Protein: "17", + SaturatedFat: "4", Servings: "1", - Sodium: "67 mg", - TransFat: "0.2 g", - UnsaturatedFat: "9 g", + Sodium: "67", + TransFat: "0.2", + UnsaturatedFat: "9", }, PrepTime: "PT15M", TotalTime: "PT60M", @@ -558,16 +559,16 @@ func TestScraper_C(t *testing.T) { }, Name: "Chipotle Roast Sweet Potatoes", NutritionSchema: &models.NutritionSchema{ - Calories: "Calories 214", - Carbohydrates: "Carbs 46g", - Cholesterol: "Cholesterol 0", - Fat: "Fat 7g", - Fiber: "Fiber 7g", - Protein: "Protein 3g", - SaturatedFat: "Saturated 0.5g", - Sodium: "Sodium 436mg", - Sugar: "Sugars 9g", - TransFat: "Trans 0", + Calories: "214", + Carbohydrates: "46", + Cholesterol: "0", + Fat: "7", + Fiber: "7", + Protein: "3", + SaturatedFat: "0.5", + Sodium: "436", + Sugar: "9", + TransFat: "0", }, PrepTime: "PT10M", Tools: &models.Tools{Values: []models.HowToItem{}}, @@ -618,16 +619,16 @@ func TestScraper_C(t *testing.T) { }, Name: "Pudim no Copinho para Festa", NutritionSchema: &models.NutritionSchema{ - Calories: "215 kcal", - Carbohydrates: "36 g", - Fat: "6.5 g", - Fiber: "0 g", - Protein: "3.6 g", - SaturatedFat: "3.7 g", + Calories: "215", + Carbohydrates: "36", + Fat: "6.5", + Fiber: "0", + Protein: "3.6", + SaturatedFat: "3.7", Servings: "50", - Sodium: "57 mg", - TransFat: "0 g", - UnsaturatedFat: "1.6 g", + Sodium: "57", + TransFat: "0", + UnsaturatedFat: "1.6", }, PrepTime: "PT20M", Tools: &models.Tools{Values: []models.HowToItem{}}, @@ -682,17 +683,17 @@ func TestScraper_C(t *testing.T) { Keywords: &models.Keywords{}, Name: "Balinese BBQ Pork Roast - Babi Guling", NutritionSchema: &models.NutritionSchema{ - Calories: "", - Carbohydrates: "4.05 g", - Cholesterol: "0 g", - Fat: "6.92 g", - Fiber: "0.4 g", - Protein: "0.26 g", - SaturatedFat: "0.52 g", + Calories: "76", + Carbohydrates: "4.05", + Cholesterol: "0", + Fat: "6.92", + Fiber: "0.4", + Protein: "0.26", + SaturatedFat: "0.52", Servings: "20 g", - Sodium: "777 g", - Sugar: "2.36 g", - TransFat: "0.18 g", + Sodium: "777", + Sugar: "2.36", + TransFat: "0.18", }, PrepTime: "PT30M", Tools: &models.Tools{Values: []models.HowToItem{}}, @@ -742,17 +743,17 @@ func TestScraper_C(t *testing.T) { }, Name: "Honey Butter Cornbread", NutritionSchema: &models.NutritionSchema{ - Calories: "200 calories", - Carbohydrates: "30.3 g", - Cholesterol: "52 mg", - Fat: "7.8 g", - Fiber: "2.1 g", - Protein: "4.5 g", - SaturatedFat: "4.3 g", + Calories: "200", + Carbohydrates: "30.3", + Cholesterol: "52", + Fat: "7.8", + Fiber: "2.1", + Protein: "4.5", + SaturatedFat: "4.3", Servings: "1", - Sodium: "268.9 mg", - Sugar: "12.9 g", - TransFat: "0 g", + Sodium: "268.9", + Sugar: "12.9", + TransFat: "0", }, PrepTime: "PT10M", TotalTime: "PT45M", @@ -918,16 +919,16 @@ func TestScraper_C(t *testing.T) { }, Name: "McDonald's Egg McMuffin", NutritionSchema: &models.NutritionSchema{ - Calories: "420 kcal", - Carbohydrates: "28 g", - Cholesterol: "229 mg", - Fat: "25 g", - Fiber: "2 g", - Protein: "20 g", - SaturatedFat: "13 g", + Calories: "420", + Carbohydrates: "28", + Cholesterol: "229", + Fat: "25", + Fiber: "2", + Protein: "20", + SaturatedFat: "13", Servings: "1", - Sodium: "1037 mg", - Sugar: "1 g", + Sodium: "1037", + Sugar: "1", }, PrepTime: "PT5M", Yield: &models.Yield{Value: 4}, @@ -1163,17 +1164,17 @@ func TestScraper_C(t *testing.T) { }, Name: "Moist & Fluffy Pumpkin Vegan Muffins", NutritionSchema: &models.NutritionSchema{ - Calories: "290 kcal", - Carbohydrates: "40 g", - Fat: "14 g", - Fiber: "2 g", - Protein: "3 g", - SaturatedFat: "6 g", + Calories: "290", + Carbohydrates: "40", + Fat: "14", + Fiber: "2", + Protein: "3", + SaturatedFat: "6", Servings: "1", - Sodium: "173 mg", - Sugar: "23 g", - TransFat: "1 g", - UnsaturatedFat: "8 g", + Sodium: "173", + Sugar: "23", + TransFat: "1", + UnsaturatedFat: "8", }, PrepTime: "PT20M", TotalTime: "PT45M", diff --git a/internal/scraper/scraper_D_test.go b/internal/scraper/scraper_D_test.go index f229c430..632a8f4d 100644 --- a/internal/scraper/scraper_D_test.go +++ b/internal/scraper/scraper_D_test.go @@ -1,8 +1,9 @@ package scraper_test import ( - "github.com/reaper47/recipya/internal/models" "testing" + + "github.com/reaper47/recipya/internal/models" ) func TestScraper_D(t *testing.T) { @@ -59,13 +60,13 @@ func TestScraper_D(t *testing.T) { }, Name: "BEST Giardiniera (Hot or Mild)", NutritionSchema: &models.NutritionSchema{ - Calories: "19 kcal", - Carbohydrates: "2 g", - Fiber: "1 g", - SaturatedFat: "5 g", + Calories: "19", + Carbohydrates: "2", + Fiber: "1", + SaturatedFat: "5", Servings: "85 g", - Sodium: "457 mg", - Sugar: "1 g", + Sodium: "457", + Sugar: "1", }, PrepTime: "PT30M", TotalTime: "PT40M", @@ -164,16 +165,16 @@ func TestScraper_D(t *testing.T) { }, Name: "Beef & Broccoli", NutritionSchema: &models.NutritionSchema{ - Calories: "609 Calories", - Carbohydrates: "26 g", - Cholesterol: "111 mg", - Fat: "35 g", - Fiber: "7 g", - Protein: "46 g", - SaturatedFat: "10 g", - Sodium: "1918 mg", - Sugar: "9 g", - TransFat: "1 g", + Calories: "609", + Carbohydrates: "26", + Cholesterol: "111", + Fat: "35", + Fiber: "7", + Protein: "46", + SaturatedFat: "10", + Sodium: "1918", + Sugar: "9", + TransFat: "1", }, PrepTime: "PT10M", TotalTime: "PT40M", @@ -226,15 +227,15 @@ func TestScraper_D(t *testing.T) { }, Name: "Easy Keto Samosas Recipe (Air Fryer Recipe)", NutritionSchema: &models.NutritionSchema{ - Calories: "69.6 kcal", - Carbohydrates: "7.5 g", - Fat: "4.5 g", - Fiber: "3.8 g", - Protein: "1.2 g", + Calories: "69.6", + Carbohydrates: "7.5", + Fat: "4.5", + Fiber: "3.8", + Protein: "1.2", SaturatedFat: "", Servings: "1", - Sodium: "30.7 mg", - Sugar: "0.9 g", + Sodium: "30.7", + Sugar: "0.9", }, PrepTime: "PT30M", Yield: &models.Yield{Value: 12}, @@ -315,16 +316,16 @@ func TestScraper_D(t *testing.T) { }, Name: "Best Baked Chicken Breast", NutritionSchema: &models.NutritionSchema{ - Calories: "163 kcal", - Carbohydrates: "1 g", - Cholesterol: "72 mg", - Fat: "7 g", - Fiber: "1 g", - Protein: "24 g", - SaturatedFat: "1 g", + Calories: "163", + Carbohydrates: "1", + Cholesterol: "72", + Fat: "7", + Fiber: "1", + Protein: "24", + SaturatedFat: "1", Servings: "1", - Sodium: "713 mg", - Sugar: "1 g", + Sodium: "713", + Sugar: "1", }, PrepTime: "PT5M", TotalTime: "PT25M", diff --git a/internal/scraper/scraper_E_test.go b/internal/scraper/scraper_E_test.go index d7253a78..d02aaf8f 100644 --- a/internal/scraper/scraper_E_test.go +++ b/internal/scraper/scraper_E_test.go @@ -1,8 +1,9 @@ package scraper_test import ( - "github.com/reaper47/recipya/internal/models" "testing" + + "github.com/reaper47/recipya/internal/models" ) func TestScraper_E(t *testing.T) { @@ -59,17 +60,17 @@ func TestScraper_E(t *testing.T) { }, Name: "Fluffy Cinnamon Rolls", NutritionSchema: &models.NutritionSchema{ - Calories: "269 kcal", - Carbohydrates: "37 g", - Cholesterol: "43 mg", - Fat: "11 g", - Fiber: "1 g", - Protein: "6 g", - SaturatedFat: "6 g", + Calories: "269", + Carbohydrates: "37", + Cholesterol: "43", + Fat: "11", + Fiber: "1", + Protein: "6", + SaturatedFat: "6", Servings: "1", - Sodium: "252 mg", - Sugar: "14 g", - UnsaturatedFat: "3 g", + Sodium: "252", + Sugar: "14", + UnsaturatedFat: "3", }, PrepTime: "PT30M", TotalTime: "PT175M", @@ -116,15 +117,15 @@ func TestScraper_E(t *testing.T) { }, Name: "Lemon Chicken Piccata", NutritionSchema: &models.NutritionSchema{ - Calories: "264 kcal", - Carbohydrates: "7 g", - Cholesterol: "70 mg", - Fat: "13 g", - Protein: "24 g", - SaturatedFat: "4 g", - Sodium: "382 mg", - Sugar: "1 g", - UnsaturatedFat: "0 g", + Calories: "264", + Carbohydrates: "7", + Cholesterol: "70", + Fat: "13", + Protein: "24", + SaturatedFat: "4", + Sodium: "382", + Sugar: "1", + UnsaturatedFat: "0", }, TotalTime: "PT20M", Yield: &models.Yield{Value: 4}, @@ -363,14 +364,14 @@ func TestScraper_E(t *testing.T) { }, Name: "Vegan Moussaka", NutritionSchema: &models.NutritionSchema{ - Calories: "400 kcal", - Carbohydrates: "70 g", - Fat: "8 g", - Fiber: "22 g", - Protein: "19 g", - SaturatedFat: "1 g", + Calories: "400", + Carbohydrates: "70", + Fat: "8", + Fiber: "22", + Protein: "19", + SaturatedFat: "1", Servings: "1", - Sugar: "16 g", + Sugar: "16", }, PrepTime: "PT30M", TotalTime: "PT80M", @@ -421,12 +422,12 @@ func TestScraper_E(t *testing.T) { }, Name: "Banana Blossom Vegan Fish", NutritionSchema: &models.NutritionSchema{ - Calories: "160 kcal", - Carbohydrates: "24 g", - Fat: "5 g", - Protein: "3 g", - SaturatedFat: "4 g", - Sodium: "325 mg", + Calories: "160", + Carbohydrates: "24", + Fat: "5", + Protein: "3", + SaturatedFat: "4", + Sodium: "325", Servings: "1", }, PrepTime: "PT10M", @@ -533,18 +534,18 @@ func TestScraper_E(t *testing.T) { }, Name: "Orange Pecan Crumb Muffin Recipe", NutritionSchema: &models.NutritionSchema{ - Calories: "233 calories", - Carbohydrates: "43 grams carbohydrates", - Cholesterol: "43 milligrams cholesterol", - Fat: "6 grams fat", - Fiber: "1 grams fiber", - Protein: "3 grams protein", - SaturatedFat: "3 grams saturated fat", + Calories: "233", + Carbohydrates: "43", + Cholesterol: "43", + Fat: "6", + Fiber: "1", + Protein: "3", + SaturatedFat: "3", Servings: "1", - Sodium: "68 grams sodium", - Sugar: "21 grams sugar", - TransFat: "0 grams trans fat", - UnsaturatedFat: "2 grams unsaturated fat", + Sodium: "68", + Sugar: "21", + TransFat: "0", + UnsaturatedFat: "2", }, PrepTime: "PT45M", Tools: &models.Tools{Values: []models.HowToItem{}}, @@ -649,16 +650,16 @@ func TestScraper_E(t *testing.T) { }, Name: "Baked or Barbecued Sticky Glazed Ribs", NutritionSchema: &models.NutritionSchema{ - Calories: "1539 kcal", - Carbohydrates: "58 g", - Cholesterol: "362 mg", - Fat: "107 g", - Fiber: "3 g", - Protein: "73 g", - SaturatedFat: "34 g", + Calories: "1539", + Carbohydrates: "58", + Cholesterol: "362", + Fat: "107", + Fiber: "3", + Protein: "73", + SaturatedFat: "34", Servings: "1", - Sodium: "3239 mg", - Sugar: "49 g", + Sodium: "3239", + Sugar: "49", }, PrepTime: "PT5M", TotalTime: "PT125M", diff --git a/internal/scraper/scraper_F_test.go b/internal/scraper/scraper_F_test.go index 6c678aa5..8c843cbc 100644 --- a/internal/scraper/scraper_F_test.go +++ b/internal/scraper/scraper_F_test.go @@ -1,8 +1,9 @@ package scraper_test import ( - "github.com/reaper47/recipya/internal/models" "testing" + + "github.com/reaper47/recipya/internal/models" ) func TestScraper_F(t *testing.T) { @@ -94,18 +95,18 @@ func TestScraper_F(t *testing.T) { }, Name: "Sourdough Pretzel Buns", NutritionSchema: &models.NutritionSchema{ - Calories: "192 kcal", - Carbohydrates: "32 g", - Cholesterol: "12 mg", - Fat: "5 g", - Fiber: "1 g", - Protein: "4 g", - SaturatedFat: "3 g", + Calories: "192", + Carbohydrates: "32", + Cholesterol: "12", + Fat: "5", + Fiber: "1", + Protein: "4", + SaturatedFat: "3", Servings: "1", - Sodium: "2155 mg", - Sugar: "1 g", - TransFat: "0.2 g", - UnsaturatedFat: "1.3 g", + Sodium: "2155", + Sugar: "1", + TransFat: "0.2", + UnsaturatedFat: "1.3", }, PrepTime: "PT15M", TotalTime: "PT880M", @@ -202,16 +203,16 @@ func TestScraper_F(t *testing.T) { }, Name: "Orecchiette with Broccoli", NutritionSchema: &models.NutritionSchema{ - Calories: "351 calories", - Carbohydrates: "49.2 g", - Cholesterol: "9.7 mg", - Fat: "12.7 g", - Fiber: "7.5 g", - Protein: "15.6 g", - SaturatedFat: "3.6 g", - Sodium: "518.3 mg", - Sugar: "3.2 g", - TransFat: "0 g", + Calories: "351", + Carbohydrates: "49.2", + Cholesterol: "9.7", + Fat: "12.7", + Fiber: "7.5", + Protein: "15.6", + SaturatedFat: "3.6", + Sodium: "518.3", + Sugar: "3.2", + TransFat: "0", }, PrepTime: "PT5M", TotalTime: "PT30M", @@ -255,15 +256,15 @@ func TestScraper_F(t *testing.T) { }, Name: "Guacamole", NutritionSchema: &models.NutritionSchema{ - Calories: "168 kcal", - Carbohydrates: "10 g", - Fat: "15 g", - Fiber: "7 g", - Protein: "2 g", - SaturatedFat: "2 g", + Calories: "168", + Carbohydrates: "10", + Fat: "15", + Fiber: "7", + Protein: "2", + SaturatedFat: "2", Servings: "1", - Sodium: "307 mg", - Sugar: "2 g", + Sodium: "307", + Sugar: "2", }, PrepTime: "PT10M", TotalTime: "PT10M", @@ -387,13 +388,13 @@ func TestScraper_F(t *testing.T) { }, Name: "Rosemary Blue Cheese Turkey Sliders", NutritionSchema: &models.NutritionSchema{ - Calories: "330cal", - Carbohydrates: "24g", - Fat: "15g", - Fiber: "2g", - Protein: "21g", - Sodium: "670mg", - Sugar: "5g", + Calories: "330", + Carbohydrates: "24", + Fat: "15", + Fiber: "2", + Protein: "21", + Sodium: "670", + Sugar: "5", }, PrepTime: "PT5M", URL: "https://fitmencook.com/rosemary-blue-cheese-turkey-sliders/", @@ -426,16 +427,16 @@ func TestScraper_F(t *testing.T) { }, Name: "Air Fryer Homemade Breakfast Sausage ", NutritionSchema: &models.NutritionSchema{ - Calories: "150 calories", - Carbohydrates: "0.2 g", - Cholesterol: "40.9 mg", - Fat: "12.1 g", - Fiber: "0.1 g", - Protein: "9.6 g", - SaturatedFat: "4.5 g", - Sodium: "322.6 mg", - Sugar: "0 g", - TransFat: "0 g", + Calories: "150", + Carbohydrates: "0.2", + Cholesterol: "40.9", + Fat: "12.1", + Fiber: "0.1", + Protein: "9.6", + SaturatedFat: "4.5", + Sodium: "322.6", + Sugar: "0", + TransFat: "0", }, PrepTime: "PT5M", TotalTime: "PT15M", @@ -604,17 +605,17 @@ func TestScraper_F(t *testing.T) { }, Name: "Chili Pepper Chocolate Bark", NutritionSchema: &models.NutritionSchema{ - Calories: "296 calories", - Carbohydrates: "29 g", - Cholesterol: "2.9 mg", - Fat: "18.9 g", - Fiber: "4.6 g", - Protein: "3.3 g", - SaturatedFat: "10.8 g", + Calories: "296", + Carbohydrates: "29", + Cholesterol: "2.9", + Fat: "18.9", + Fiber: "4.6", + Protein: "3.3", + SaturatedFat: "10.8", Servings: "2", - Sodium: "88.8 mg", - Sugar: "19.9 g", - TransFat: "0 g", + Sodium: "88.8", + Sugar: "19.9", + TransFat: "0", }, PrepTime: "PT10M", TotalTime: "PT3H15M", @@ -762,16 +763,16 @@ func TestScraper_F(t *testing.T) { }, Name: "Gnocchi With Pomodoro Sauce", NutritionSchema: &models.NutritionSchema{ - Calories: "229 kcal", - Carbohydrates: "3 g", - Cholesterol: "29 mg", - Fat: "22 g", - Fiber: "1 g", - Protein: "5 g", - SaturatedFat: "7 g", + Calories: "229", + Carbohydrates: "3", + Cholesterol: "29", + Fat: "22", + Fiber: "1", + Protein: "5", + SaturatedFat: "7", Servings: "1", - Sodium: "207 mg", - Sugar: "1 g", + Sodium: "207", + Sugar: "1", }, PrepTime: "PT10M", TotalTime: "PT40M", @@ -927,18 +928,18 @@ func TestScraper_F(t *testing.T) { }, }, NutritionSchema: &models.NutritionSchema{ - Calories: "274 kcal", - Carbohydrates: "26 g", - Cholesterol: "50 mg", - Fat: "11 g", - Fiber: "6 g", - Protein: "25 g", - SaturatedFat: "5 g", + Calories: "274", + Carbohydrates: "26", + Cholesterol: "50", + Fat: "11", + Fiber: "6", + Protein: "25", + SaturatedFat: "5", Servings: "1", - Sodium: "797 mg", - Sugar: "7 g", - TransFat: "1 g", - UnsaturatedFat: "5 g", + Sodium: "797", + Sugar: "7", + TransFat: "1", + UnsaturatedFat: "5", }, PrepTime: "PT10M", TotalTime: "PT40M", @@ -1027,16 +1028,16 @@ func TestScraper_F(t *testing.T) { }, Name: "Air Fryer Blooming Onion Bites", NutritionSchema: &models.NutritionSchema{ - Calories: "66 kcal", - Carbohydrates: "6 g", - Fat: "5 g", - Fiber: "1 g", - Protein: "1 g", - SaturatedFat: "1 g", + Calories: "66", + Carbohydrates: "6", + Fat: "5", + Fiber: "1", + Protein: "1", + SaturatedFat: "1", Servings: "1", - Sodium: "197 mg", - Sugar: "2 g", - UnsaturatedFat: "4 g", + Sodium: "197", + Sugar: "2", + UnsaturatedFat: "4", }, PrepTime: "PT5M", TotalTime: "PT20M", diff --git a/internal/scraper/scraper_G_test.go b/internal/scraper/scraper_G_test.go index b7709f76..feb24458 100644 --- a/internal/scraper/scraper_G_test.go +++ b/internal/scraper/scraper_G_test.go @@ -1,8 +1,9 @@ package scraper_test import ( - "github.com/reaper47/recipya/internal/models" "testing" + + "github.com/reaper47/recipya/internal/models" ) func TestScraper_G(t *testing.T) { @@ -371,17 +372,17 @@ func TestScraper_G(t *testing.T) { }, Name: "Beef and Tomato Macaroni\u00a0Soup", NutritionSchema: &models.NutritionSchema{ - Calories: "829 kcal", - Carbohydrates: "79 g", - Cholesterol: "80.5 mg", - Fat: "40 g", - Fiber: "8.5 g", - Protein: "36 g", - SaturatedFat: "16 g", + Calories: "829", + Carbohydrates: "79", + Cholesterol: "80.5", + Fat: "40", + Fiber: "8.5", + Protein: "36", + SaturatedFat: "16", Servings: "1", - Sodium: "2643 mg", - Sugar: "9.5 g", - UnsaturatedFat: "7 g", + Sodium: "2643", + Sugar: "9.5", + UnsaturatedFat: "7", }, PrepTime: "PT10M", TotalTime: "PT40M", @@ -430,7 +431,7 @@ func TestScraper_G(t *testing.T) { }, Name: "Hunter's Chicken (with Bacon, BBQ Sauce and Cheese)", NutritionSchema: &models.NutritionSchema{ - Calories: "440 cal", + Calories: "440", }, PrepTime: "PT5M", Tools: &models.Tools{Values: []models.HowToItem{}}, @@ -473,7 +474,7 @@ func TestScraper_G(t *testing.T) { }, Name: "Balsamic Chicken Caprese", NutritionSchema: &models.NutritionSchema{ - Calories: "376 calories", + Calories: "376", }, PrepTime: "PT0S", TotalTime: "PT30M", diff --git a/internal/scraper/scraper_H_test.go b/internal/scraper/scraper_H_test.go index 2149641e..a80a1bea 100644 --- a/internal/scraper/scraper_H_test.go +++ b/internal/scraper/scraper_H_test.go @@ -1,8 +1,9 @@ package scraper_test import ( - "github.com/reaper47/recipya/internal/models" "testing" + + "github.com/reaper47/recipya/internal/models" ) func TestScraper_H(t *testing.T) { @@ -52,7 +53,7 @@ func TestScraper_H(t *testing.T) { }, Name: "Skillet Louisiana Style Chicken and Rice", NutritionSchema: &models.NutritionSchema{ - Calories: "547 kcal", + Calories: "547", Servings: "1", }, PrepTime: "PT20M", @@ -162,8 +163,8 @@ func TestScraper_H(t *testing.T) { }, Name: "Dragon Chicken", NutritionSchema: &models.NutritionSchema{ - Calories: "640 cal", - Fat: "34 g", + Calories: "640", + Fat: "34", Servings: "1", }, PrepTime: "PT20M", @@ -260,18 +261,18 @@ func TestScraper_H(t *testing.T) { Keywords: &models.Keywords{Values: "Broccoli Tots"}, Name: "Broccoli Tots", NutritionSchema: &models.NutritionSchema{ - Calories: "39 kcal", - Carbohydrates: "2 g", - Cholesterol: "16 mg", - Fat: "3 g", - Fiber: "1 g", - Protein: "2 g", - SaturatedFat: "1 g", + Calories: "39", + Carbohydrates: "2", + Cholesterol: "16", + Fat: "3", + Fiber: "1", + Protein: "2", + SaturatedFat: "1", Servings: "1", - Sodium: "31 mg", - Sugar: "1 g", - TransFat: "1 g", - UnsaturatedFat: "2 g", + Sodium: "31", + Sugar: "1", + TransFat: "1", + UnsaturatedFat: "2", }, PrepTime: "PT20M", TotalTime: "PT40M", @@ -374,15 +375,15 @@ func TestScraper_H(t *testing.T) { }, Name: "Creamy Shrimp Tagliatelle with Heirloom Tomatoes, Garlic, and Chili", NutritionSchema: &models.NutritionSchema{ - Calories: "750 kcal", - Carbohydrates: "86 g", - Cholesterol: "350 mg", - Fat: "27 g", - Fiber: "5 g", - Protein: "50 g", - SaturatedFat: "12 g", - Sodium: "880 mg", - Sugar: "9 g", + Calories: "750", + Carbohydrates: "86", + Cholesterol: "350", + Fat: "27", + Fiber: "5", + Protein: "50", + SaturatedFat: "12", + Sodium: "880", + Sugar: "9", }, Tools: &models.Tools{Values: []models.HowToItem{}}, TotalTime: "PT20M", diff --git a/internal/scraper/scraper_I_test.go b/internal/scraper/scraper_I_test.go index 933eaeb6..75733d82 100644 --- a/internal/scraper/scraper_I_test.go +++ b/internal/scraper/scraper_I_test.go @@ -1,8 +1,9 @@ package scraper_test import ( - "github.com/reaper47/recipya/internal/models" "testing" + + "github.com/reaper47/recipya/internal/models" ) func TestScraper_I(t *testing.T) { @@ -47,10 +48,10 @@ func TestScraper_I(t *testing.T) { }, Name: "Chicken à la king", NutritionSchema: &models.NutritionSchema{ - Calories: "775 calories", - Carbohydrates: "58 g", - Fat: "45 g", - Protein: "34 g", + Calories: "775", + Carbohydrates: "58", + Fat: "45", + Protein: "34", Servings: "4", }, Tools: &models.Tools{Values: []models.HowToItem{}}, @@ -92,7 +93,7 @@ func TestScraper_I(t *testing.T) { }, Name: "Cranberry-Walnut Oatmeal Energy Balls (No-Bake)", NutritionSchema: &models.NutritionSchema{ - Calories: "170 kcal", + Calories: "170", Servings: "1", }, PrepTime: "PT10M", @@ -149,15 +150,15 @@ func TestScraper_I(t *testing.T) { }, Name: "Mango Rice Recipe", NutritionSchema: &models.NutritionSchema{ - Calories: "636 kcal", - Carbohydrates: "83 g", - Fat: "28 g", - Fiber: "7 g", - Protein: "11 g", - SaturatedFat: "13 g", + Calories: "636", + Carbohydrates: "83", + Fat: "28", + Fiber: "7", + Protein: "11", + SaturatedFat: "13", Servings: "1", - Sodium: "28 mg", - Sugar: "1 g", + Sodium: "28", + Sugar: "1", }, PrepTime: "PT10M", TotalTime: "PT35M", @@ -204,16 +205,16 @@ func TestScraper_I(t *testing.T) { }, Name: "Coconut Pineapple Rice", NutritionSchema: &models.NutritionSchema{ - Calories: "880 kcal", - Carbohydrates: "88 g", - Cholesterol: "0 mg", - Fat: "56 g", - Fiber: "7 g", - Protein: "12 g", - SaturatedFat: "28 g", - Sodium: "1190 mg", - Sugar: "10 g", - UnsaturatedFat: "28 g", + Calories: "880", + Carbohydrates: "88", + Cholesterol: "0", + Fat: "56", + Fiber: "7", + Protein: "12", + SaturatedFat: "28", + Sodium: "1190", + Sugar: "10", + UnsaturatedFat: "28", }, PrepTime: "PT28M", Tools: &models.Tools{Values: []models.HowToItem{}}, @@ -261,7 +262,7 @@ func TestScraper_I(t *testing.T) { }, Name: "Easy Chicken Cordon Bleu Casserole Recipe", NutritionSchema: &models.NutritionSchema{ - Calories: "455 cal", + Calories: "455", }, PrepTime: "PT10M", Tools: &models.Tools{Values: []models.HowToItem{}}, diff --git a/internal/scraper/scraper_J_test.go b/internal/scraper/scraper_J_test.go index 8abdf13d..0a9b5262 100644 --- a/internal/scraper/scraper_J_test.go +++ b/internal/scraper/scraper_J_test.go @@ -1,8 +1,9 @@ package scraper_test import ( - "github.com/reaper47/recipya/internal/models" "testing" + + "github.com/reaper47/recipya/internal/models" ) func TestScraper_J(t *testing.T) { @@ -52,14 +53,14 @@ func TestScraper_J(t *testing.T) { }, Name: "Thai green chicken curry", NutritionSchema: &models.NutritionSchema{ - Calories: "285 calories", - Carbohydrates: "6.1 g carbohydrate", - Fat: "16.2 g fat", - Fiber: "2.2 g fibre", - Protein: "28.9 g protein", - SaturatedFat: "6.5 g saturated fat", - Sodium: "1.0 g salt", - Sugar: "4.2 g sugar", + Calories: "285", + Carbohydrates: "6.1", + Fat: "16.2", + Fiber: "2.2", + Protein: "28.9", + SaturatedFat: "6.5", + Sodium: "1.0", + Sugar: "4.2", }, Tools: &models.Tools{Values: []models.HowToItem{}}, TotalTime: "PT50M", @@ -160,18 +161,18 @@ func TestScraper_J(t *testing.T) { }, Name: "Vegetarian Hot Honey Pizza", NutritionSchema: &models.NutritionSchema{ - Calories: "193 kcal", - Carbohydrates: "11 g", - Cholesterol: "24 mg", - Fat: "13 g", - Fiber: "1 g", - Protein: "8 g", - SaturatedFat: "5 g", + Calories: "193", + Carbohydrates: "11", + Cholesterol: "24", + Fat: "13", + Fiber: "1", + Protein: "8", + SaturatedFat: "5", Servings: "1", - Sodium: "355 mg", - Sugar: "7 g", + Sodium: "355", + Sugar: "7", TransFat: "", - UnsaturatedFat: "8 g", + UnsaturatedFat: "8", }, PrepTime: "PT10M", TotalTime: "PT55M", @@ -224,7 +225,7 @@ func TestScraper_J(t *testing.T) { }, Name: "Pad Thai", NutritionSchema: &models.NutritionSchema{ - Calories: "389 kcal", + Calories: "389", Servings: "4", }, PrepTime: "PT15M", @@ -270,18 +271,18 @@ func TestScraper_J(t *testing.T) { }, Name: "Peanut Butter Frosting Recipe", NutritionSchema: &models.NutritionSchema{ - Calories: "181 kcal", - Carbohydrates: "17 g", - Cholesterol: "15 mg", - Fat: "12 g", - Fiber: "1 g", - Protein: "3 g", - SaturatedFat: "5 g", + Calories: "181", + Carbohydrates: "17", + Cholesterol: "15", + Fat: "12", + Fiber: "1", + Protein: "3", + SaturatedFat: "5", Servings: "2 TBS", - Sodium: "143 mg", - Sugar: "16 g", - TransFat: "1 g", - UnsaturatedFat: "6 g", + Sodium: "143", + Sugar: "16", + TransFat: "1", + UnsaturatedFat: "6", }, PrepTime: "PT5M", TotalTime: "PT5M", @@ -376,18 +377,18 @@ func TestScraper_J(t *testing.T) { }, Name: "Mini Sour Cream Doughnut Muffins", NutritionSchema: &models.NutritionSchema{ - Calories: "122 kcal", - Carbohydrates: "17 g", - Cholesterol: "17 mg", - Fat: "6 g", - Fiber: "1 g", - Protein: "1 g", - SaturatedFat: "2 g", + Calories: "122", + Carbohydrates: "17", + Cholesterol: "17", + Fat: "6", + Fiber: "1", + Protein: "1", + SaturatedFat: "2", Servings: "1", - Sodium: "57 mg", - Sugar: "11 g", - TransFat: "1 g", - UnsaturatedFat: "3 g", + Sodium: "57", + Sugar: "11", + TransFat: "1", + UnsaturatedFat: "3", }, PrepTime: "PT10M", TotalTime: "PT26M", @@ -498,17 +499,17 @@ func TestScraper_J(t *testing.T) { }, Name: "Pan-Fried Teriyaki Tofu Bowl", NutritionSchema: &models.NutritionSchema{ - Calories: "443 kcal", - Carbohydrates: "27 g", - Fat: "23 g", - Fiber: "3 g", - Protein: "21 g", - SaturatedFat: "3 g", + Calories: "443", + Carbohydrates: "27", + Fat: "23", + Fiber: "3", + Protein: "21", + SaturatedFat: "3", Servings: "1", - Sodium: "979 mg", - Sugar: "10 g", - TransFat: "1 g", - UnsaturatedFat: "20 g", + Sodium: "979", + Sugar: "10", + TransFat: "1", + UnsaturatedFat: "20", }, PrepTime: "PT5M", TotalTime: "PT60M", diff --git a/internal/scraper/scraper_K_test.go b/internal/scraper/scraper_K_test.go index 364f6b78..350bcebf 100644 --- a/internal/scraper/scraper_K_test.go +++ b/internal/scraper/scraper_K_test.go @@ -1,8 +1,9 @@ package scraper_test import ( - "github.com/reaper47/recipya/internal/models" "testing" + + "github.com/reaper47/recipya/internal/models" ) func TestScraper_K(t *testing.T) { @@ -100,17 +101,17 @@ func TestScraper_K(t *testing.T) { }, Name: "Sourdough Zucchini Bread", NutritionSchema: &models.NutritionSchema{ - Calories: "279 calories", - Carbohydrates: "33g", - Cholesterol: "23g", - Fat: "13g", - Fiber: "2g", - Protein: "5g", - SaturatedFat: "2g", + Calories: "279", + Carbohydrates: "33", + Cholesterol: "23", + Fat: "13", + Fiber: "2", + Protein: "5", + SaturatedFat: "2", Servings: "", - Sodium: "202mg", - Sugar: "21g", - TransFat: "0g", + Sodium: "202", + Sugar: "21", + TransFat: "0", UnsaturatedFat: "", }, PrepTime: "PT30M", @@ -163,17 +164,17 @@ func TestScraper_K(t *testing.T) { }, Name: "Fudge Brownies", NutritionSchema: &models.NutritionSchema{ - Calories: "260 calories", - Carbohydrates: "36g", - Cholesterol: "55mg", - Fat: "17g", - Fiber: "2g", - Protein: "3g", - SaturatedFat: "8g", + Calories: "260", + Carbohydrates: "36", + Cholesterol: "55", + Fat: "17", + Fiber: "2", + Protein: "3", + SaturatedFat: "8", Servings: "1", - Sodium: "130mg", - Sugar: "27g", - TransFat: "0g", + Sodium: "130", + Sugar: "27", + TransFat: "0", }, PrepTime: "PT12M", Tools: &models.Tools{}, @@ -220,10 +221,10 @@ func TestScraper_K(t *testing.T) { }, Name: "Vegetarische Paella mit Zucchini und Aubergine", NutritionSchema: &models.NutritionSchema{ - Calories: "448 cal", - Carbohydrates: "69 g", - Fat: "7 g", - Protein: "15 g", + Calories: "448", + Carbohydrates: "69", + Fat: "7", + Protein: "15", Servings: "1", }, PrepTime: "PT45M", @@ -274,10 +275,10 @@ func TestScraper_K(t *testing.T) { }, Name: "Spargelsalat Fruchtig", NutritionSchema: &models.NutritionSchema{ - Calories: "97 kcal", - Carbohydrates: "1,87273 g", - Fat: "9,23273 g", - Protein: "1,78182 g", + Calories: "97", + Carbohydrates: "1.87273", + Fat: "9.23273", + Protein: "1.78182", Servings: "100 g", }, Tools: &models.Tools{Values: []models.HowToItem{}}, diff --git a/internal/scraper/scraper_L_test.go b/internal/scraper/scraper_L_test.go index 02185b36..36ff5292 100644 --- a/internal/scraper/scraper_L_test.go +++ b/internal/scraper/scraper_L_test.go @@ -1,8 +1,9 @@ package scraper_test import ( - "github.com/reaper47/recipya/internal/models" "testing" + + "github.com/reaper47/recipya/internal/models" ) func TestScraper_L(t *testing.T) { @@ -152,10 +153,10 @@ func TestScraper_L(t *testing.T) { }, Name: "Gemüsepfanne mit Hähnchen, Zuckerschoten und Brokkoli", NutritionSchema: &models.NutritionSchema{ - Calories: "260 kcal", - Carbohydrates: "7 g", - Fat: "7 g", - Protein: "38 g", + Calories: "260", + Carbohydrates: "7", + Fat: "7", + Protein: "38", Servings: "1", }, PrepTime: "PT0M", @@ -212,15 +213,15 @@ func TestScraper_L(t *testing.T) { }, Name: "Instant Pot Pot Roast Recipe", NutritionSchema: &models.NutritionSchema{ - Calories: "133 kcal", - Carbohydrates: "23 g", - Fat: "3 g", - Fiber: "3 g", - Protein: "4 g", - SaturatedFat: "1 g", + Calories: "133", + Carbohydrates: "23", + Fat: "3", + Fiber: "3", + Protein: "4", + SaturatedFat: "1", Servings: "1", - Sodium: "1087 mg", - Sugar: "5 g", + Sodium: "1087", + Sugar: "5", }, PrepTime: "PT20M", TotalTime: "PT100M", @@ -339,17 +340,17 @@ func TestScraper_L(t *testing.T) { }, Name: "Chick Fil A Peppermint Milkshake", NutritionSchema: &models.NutritionSchema{ - Calories: "649 kcal", - Carbohydrates: "90 g", - Cholesterol: "88 mg", - Fat: "28 g", - Fiber: "1 g", - Protein: "8 g", - SaturatedFat: "17 g", + Calories: "649", + Carbohydrates: "90", + Cholesterol: "88", + Fat: "28", + Fiber: "1", + Protein: "8", + SaturatedFat: "17", Servings: "1", - Sodium: "171 mg", - Sugar: "76 g", - UnsaturatedFat: "7 g", + Sodium: "171", + Sugar: "76", + UnsaturatedFat: "7", }, PrepTime: "PT1M", TotalTime: "PT1M", @@ -391,7 +392,7 @@ func TestScraper_L(t *testing.T) { }, Name: "Schweinemedaillons mit Ofenkartoffeln, Butterbohnen und Rosmarinbröseln", NutritionSchema: &models.NutritionSchema{ - Calories: "558 Kalorie", + Calories: "558", }, PrepTime: "PT40M", Tools: &models.Tools{ @@ -492,17 +493,17 @@ func TestScraper_L(t *testing.T) { }, Name: "BBQ Ribs on the Charcoal Grill", NutritionSchema: &models.NutritionSchema{ - Calories: "416 calories", - Carbohydrates: "8.9 g", - Cholesterol: "122.9 mg", - Fat: "26.3 g", - Fiber: "0.8 g", - Protein: "36.1 g", - SaturatedFat: "9.1 g", + Calories: "416", + Carbohydrates: "8.9", + Cholesterol: "122.9", + Fat: "26.3", + Fiber: "0.8", + Protein: "36.1", + SaturatedFat: "9.1", Servings: "2", - Sodium: "512.8 mg", - Sugar: "5.1 g", - TransFat: "0.2 g", + Sodium: "512.8", + Sugar: "5.1", + TransFat: "0.2", }, PrepTime: "PT10M", Tools: &models.Tools{Values: []models.HowToItem{}}, @@ -608,16 +609,16 @@ func TestScraper_L(t *testing.T) { }, Name: "Vegan Buffalo Chicken Dip", NutritionSchema: &models.NutritionSchema{ - Calories: "214 kcal", - Carbohydrates: "13 g", - Fat: "16 g", - Fiber: "3 g", - Protein: "8 g", - SaturatedFat: "7 g", + Calories: "214", + Carbohydrates: "13", + Fat: "16", + Fiber: "3", + Protein: "8", + SaturatedFat: "7", Servings: "1", - Sodium: "938 mg", - Sugar: "2 g", - UnsaturatedFat: "8 g", + Sodium: "938", + Sugar: "2", + UnsaturatedFat: "8", }, PrepTime: "PT10M", TotalTime: "PT90M", diff --git a/internal/scraper/scraper_M_test.go b/internal/scraper/scraper_M_test.go index 8ebe2663..febbf158 100644 --- a/internal/scraper/scraper_M_test.go +++ b/internal/scraper/scraper_M_test.go @@ -1,8 +1,9 @@ package scraper_test import ( - "github.com/reaper47/recipya/internal/models" "testing" + + "github.com/reaper47/recipya/internal/models" ) func TestScraper_M(t *testing.T) { @@ -215,7 +216,7 @@ func TestScraper_M(t *testing.T) { }, Name: "Durumboller - nemme italienske boller med durum mel", NutritionSchema: &models.NutritionSchema{ - Calories: "170 kcal", + Calories: "170", Servings: "1", }, PrepTime: "PT15M", @@ -479,16 +480,16 @@ func TestScraper_M(t *testing.T) { }, Name: "Rosemary Ranch Chicken", NutritionSchema: &models.NutritionSchema{ - Calories: "259 kcal", - Carbohydrates: "2 g", - Cholesterol: "100 mg", - Fat: "13 g", - Fiber: "1 g", - Protein: "32 g", - SaturatedFat: "2 g", + Calories: "259", + Carbohydrates: "2", + Cholesterol: "100", + Fat: "13", + Fiber: "1", + Protein: "32", + SaturatedFat: "2", Servings: "1", - Sodium: "718 mg", - Sugar: "1 g", + Sodium: "718", + Sugar: "1", }, PrepTime: "PT500M", TotalTime: "PT512M", @@ -584,14 +585,14 @@ func TestScraper_M(t *testing.T) { }, Name: "Adaptogenic Hot Chocolate Mix", NutritionSchema: &models.NutritionSchema{ - Calories: "183 kcal", - Carbohydrates: "22.7 g", - Fat: "8.8 g", - Fiber: "4 g", - Protein: "4 g", - SaturatedFat: "3.3 g", + Calories: "183", + Carbohydrates: "22.7", + Fat: "8.8", + Fiber: "4", + Protein: "4", + SaturatedFat: "3.3", Servings: "1", - Sugar: "3.3 g", + Sugar: "3.3", }, PrepTime: "PT5M", TotalTime: "PT5M", @@ -633,15 +634,15 @@ func TestScraper_M(t *testing.T) { }, Name: "Cranberry Sauce Recipe", NutritionSchema: &models.NutritionSchema{ - Calories: "125 kcal", - Carbohydrates: "32 g", - Fat: "1 g", - Fiber: "1 g", - Protein: "1 g", - SaturatedFat: "1 g", + Calories: "125", + Carbohydrates: "32", + Fat: "1", + Fiber: "1", + Protein: "1", + SaturatedFat: "1", Servings: "1", - Sodium: "1 mg", - Sugar: "30 g", + Sodium: "1", + Sugar: "30", }, TotalTime: "PT15M", Yield: &models.Yield{Value: 6}, @@ -747,17 +748,17 @@ func TestScraper_M(t *testing.T) { }, Name: "Khinkali Recipe (Georgian Dumplings)", NutritionSchema: &models.NutritionSchema{ - Calories: "127 kcal", - Carbohydrates: "13 g", - Cholesterol: "35 mg", - Fat: "5 g", - Fiber: "1 g", - Protein: "7 g", - SaturatedFat: "2 g", + Calories: "127", + Carbohydrates: "13", + Cholesterol: "35", + Fat: "5", + Fiber: "1", + Protein: "7", + SaturatedFat: "2", Servings: "1", - Sodium: "412 mg", - Sugar: "1 g", - TransFat: "1 g", + Sodium: "412", + Sugar: "1", + TransFat: "1", }, PrepTime: "PT30M", TotalTime: "PT45M", @@ -997,18 +998,18 @@ func TestScraper_M(t *testing.T) { }, Name: "Pistachio Pudding Cake", NutritionSchema: &models.NutritionSchema{ - Calories: "425 kcal", - Carbohydrates: "55 g", - Cholesterol: "50 mg", - Fat: "21 g", - Fiber: "1 g", - Protein: "4 g", - SaturatedFat: "5 g", + Calories: "425", + Carbohydrates: "55", + Cholesterol: "50", + Fat: "21", + Fiber: "1", + Protein: "4", + SaturatedFat: "5", Servings: "1", - Sodium: "454 mg", - Sugar: "37 g", - TransFat: "0.2 g", - UnsaturatedFat: "15 g", + Sodium: "454", + Sugar: "37", + TransFat: "0.2", + UnsaturatedFat: "15", }, PrepTime: "PT5M", TotalTime: "PT50M", @@ -1094,18 +1095,18 @@ func TestScraper_M(t *testing.T) { }, }, NutritionSchema: &models.NutritionSchema{ - Calories: "165 kcal", - Carbohydrates: "17 g", - Cholesterol: "55 mg", - Fat: "10 g", - Fiber: "0.3 g", - Protein: "3 g", - SaturatedFat: "6 g", + Calories: "165", + Carbohydrates: "17", + Cholesterol: "55", + Fat: "10", + Fiber: "0.3", + Protein: "3", + SaturatedFat: "6", Servings: "1", - Sodium: "145 mg", - Sugar: "9 g", - TransFat: "0.3 g", - UnsaturatedFat: "4 g", + Sodium: "145", + Sugar: "9", + TransFat: "0.3", + UnsaturatedFat: "4", }, PrepTime: "PT35M", TotalTime: "PT90M", @@ -1157,18 +1158,18 @@ func TestScraper_M(t *testing.T) { }, }, NutritionSchema: &models.NutritionSchema{ - Calories: "165 kcal", - Carbohydrates: "17 g", - Cholesterol: "55 mg", - Fat: "10 g", - Fiber: "0.3 g", - Protein: "3 g", - SaturatedFat: "6 g", + Calories: "165", + Carbohydrates: "17", + Cholesterol: "55", + Fat: "10", + Fiber: "0.3", + Protein: "3", + SaturatedFat: "6", Servings: "1", - Sodium: "145 mg", - Sugar: "9 g", - TransFat: "0.3 g", - UnsaturatedFat: "4 g", + Sodium: "145", + Sugar: "9", + TransFat: "0.3", + UnsaturatedFat: "4", }, PrepTime: "PT35M", TotalTime: "PT90M", @@ -1221,14 +1222,14 @@ func TestScraper_M(t *testing.T) { }, NutritionSchema: &models.NutritionSchema{ Calories: "77", - Fat: "3 g", - SaturatedFat: "0 g", - Cholesterol: "21 mg", - Sodium: "255 mg", - Carbohydrates: "6 g", - Fiber: "2 g", - Sugar: "3 g", - Protein: "8 g", + Fat: "3", + SaturatedFat: "0", + Cholesterol: "21", + Sodium: "255", + Carbohydrates: "6", + Fiber: "2", + Sugar: "3", + Protein: "8", }, Tools: &models.Tools{Values: []models.HowToItem{}}, URL: "https://www.myplate.gov/recipes/supplemental-nutrition-assistance-program-snap/20-minute-chicken-creole", @@ -1297,17 +1298,17 @@ func TestScraper_M(t *testing.T) { }, Name: "The Best Nachos", NutritionSchema: &models.NutritionSchema{ - Calories: "1237 kcal", - Carbohydrates: "40 g", - Cholesterol: "305 mg", - Fat: "75 g", - Fiber: "7 g", - Protein: "98 g", - SaturatedFat: "29 g", + Calories: "1237", + Carbohydrates: "40", + Cholesterol: "305", + Fat: "75", + Fiber: "7", + Protein: "98", + SaturatedFat: "29", Servings: "Serves 6", - Sodium: "1432 mg", - Sugar: "2 g", - UnsaturatedFat: "0 g", + Sodium: "1432", + Sugar: "2", + UnsaturatedFat: "0", }, PrepTime: "PT15M", TotalTime: "PT30M", diff --git a/internal/scraper/scraper_N_test.go b/internal/scraper/scraper_N_test.go index 1ffd47c8..50dd976e 100644 --- a/internal/scraper/scraper_N_test.go +++ b/internal/scraper/scraper_N_test.go @@ -1,8 +1,9 @@ package scraper_test import ( - "github.com/reaper47/recipya/internal/models" "testing" + + "github.com/reaper47/recipya/internal/models" ) func TestScraper_N(t *testing.T) { @@ -42,18 +43,18 @@ func TestScraper_N(t *testing.T) { }, Name: "Homemade Taco Seasoning Recipe", NutritionSchema: &models.NutritionSchema{ - Calories: "7 kcal", - Carbohydrates: "1 g", + Calories: "7", + Carbohydrates: "1", Cholesterol: "", - Fat: "0.3 g", - Fiber: "1 g", - Protein: "0.3 g", - SaturatedFat: "0.04 g", + Fat: "0.3", + Fiber: "1", + Protein: "0.3", + SaturatedFat: "0.04", Servings: "1", - Sodium: "274 mg", - Sugar: "0.1 g", + Sodium: "274", + Sugar: "0.1", TransFat: "", - UnsaturatedFat: "0.2 g", + UnsaturatedFat: "0.2", }, PrepTime: "PT5M", TotalTime: "PT5M", @@ -255,15 +256,15 @@ func TestScraper_N(t *testing.T) { }, Name: "Kelt pizzatészta", NutritionSchema: &models.NutritionSchema{ - Calories: "2253.255 g", - Carbohydrates: "412.3725 g", - Cholesterol: "0 mg", - Fat: "37.764 g", - Fiber: "16.74 g", - Protein: "57.269 g", + Calories: "2253.255", + Carbohydrates: "412.3725", + Cholesterol: "0", + Fat: "37.764", + Fiber: "16.74", + Protein: "57.269", Servings: "894.5 g", - Sodium: "32.265 g", - Sugar: "3.926 g", + Sodium: "32.265", + Sugar: "3.926", TransFat: "", UnsaturatedFat: "", }, @@ -344,18 +345,18 @@ func TestScraper_N(t *testing.T) { }, Name: "Creamy One Pot Pumpkin Alfredo", NutritionSchema: &models.NutritionSchema{ - Calories: "638 kcal", - Carbohydrates: "48 g", - Cholesterol: "114 mg", - Fat: "41 g", - Fiber: "2 g", - Protein: "21 g", - SaturatedFat: "25 g", + Calories: "638", + Carbohydrates: "48", + Cholesterol: "114", + Fat: "41", + Fiber: "2", + Protein: "21", + SaturatedFat: "25", Servings: "1", - Sodium: "457 mg", - Sugar: "4 g", - TransFat: "0.5 g", - UnsaturatedFat: "13 g", + Sodium: "457", + Sugar: "4", + TransFat: "0.5", + UnsaturatedFat: "13", }, PrepTime: "PT15M", TotalTime: "PT30M", @@ -429,17 +430,17 @@ func TestScraper_N(t *testing.T) { }, Name: "Spaghetti With Fried Eggs", NutritionSchema: &models.NutritionSchema{ - Calories: "", - Carbohydrates: "58 grams", + Calories: "607", + Carbohydrates: "58", Cholesterol: "", - Fat: "34 grams", - Fiber: "3 grams", - Protein: "17 grams", - SaturatedFat: "6 grams", - Sodium: "381 milligrams", - Sugar: "2 grams", - TransFat: "0 grams", - UnsaturatedFat: "26 grams", + Fat: "34", + Fiber: "3", + Protein: "17", + SaturatedFat: "6", + Sodium: "381", + Sugar: "2", + TransFat: "0", + UnsaturatedFat: "26", }, Tools: &models.Tools{Values: []models.HowToItem{}}, TotalTime: "PT20M", diff --git a/internal/scraper/scraper_O_test.go b/internal/scraper/scraper_O_test.go index 4e0cd7ae..d979ff81 100644 --- a/internal/scraper/scraper_O_test.go +++ b/internal/scraper/scraper_O_test.go @@ -1,8 +1,9 @@ package scraper_test import ( - "github.com/reaper47/recipya/internal/models" "testing" + + "github.com/reaper47/recipya/internal/models" ) func TestScraper_O(t *testing.T) { @@ -67,15 +68,15 @@ func TestScraper_O(t *testing.T) { }, Name: "Bread-Free Stuffing Balls", NutritionSchema: &models.NutritionSchema{ - Calories: "140 calorie", - Carbohydrates: "18 grams", - Fat: "6 grams", - Fiber: "2 grams", - Protein: "4 grams", - SaturatedFat: "0.5 grams", + Calories: "140", + Carbohydrates: "18", + Fat: "6", + Fiber: "2", + Protein: "4", + SaturatedFat: "0.5", Servings: "1", - Sodium: "160 milligrams", - Sugar: "9 grams", + Sodium: "160", + Sugar: "9", }, PrepTime: "PT30M", Tools: &models.Tools{Values: []models.HowToItem{}}, @@ -131,15 +132,15 @@ func TestScraper_O(t *testing.T) { }, Name: "Chinese Scallion Pancakes (葱油饼)", NutritionSchema: &models.NutritionSchema{ - Calories: "202 kcal", - Carbohydrates: "25.7 g", - Fat: "9.3 g", - Fiber: "1.1 g", - Protein: "3.6 g", - SaturatedFat: "1.6 g", + Calories: "202", + Carbohydrates: "25.7", + Fat: "9.3", + Fiber: "1.1", + Protein: "3.6", + SaturatedFat: "1.6", Servings: "1", - Sodium: "246 mg", - Sugar: "0.3 g", + Sodium: "246", + Sugar: "0.3", }, PrepTime: "PT10M", TotalTime: "PT60M", @@ -181,14 +182,14 @@ func TestScraper_O(t *testing.T) { Name: "Perfect Basmati Rice", NutritionSchema: &models.NutritionSchema{ Calories: "207", - Carbohydrates: "37 g", - Cholesterol: "11 mg", - Fat: "5 g", - Fiber: "1 g", - Protein: "3 g", - SaturatedFat: "3 g", - Sodium: "120 mg", - Sugar: "0 g", + Carbohydrates: "37", + Cholesterol: "11", + Fat: "5", + Fiber: "1", + Protein: "3", + SaturatedFat: "3", + Sodium: "120", + Sugar: "0", }, PrepTime: "PT0M", Tools: &models.Tools{Values: []models.HowToItem{}}, diff --git a/internal/scraper/scraper_P_test.go b/internal/scraper/scraper_P_test.go index 25e8ee95..fddfe597 100644 --- a/internal/scraper/scraper_P_test.go +++ b/internal/scraper/scraper_P_test.go @@ -1,8 +1,9 @@ package scraper_test import ( - "github.com/reaper47/recipya/internal/models" "testing" + + "github.com/reaper47/recipya/internal/models" ) func TestScraper_P(t *testing.T) { @@ -51,17 +52,17 @@ func TestScraper_P(t *testing.T) { }, Name: "Grain Free Peanut Butter Granola Bars {Vegan, Paleo Option}", NutritionSchema: &models.NutritionSchema{ - Calories: "249 kcal", - Carbohydrates: "12 g", - Cholesterol: "1 mg", - Fat: "21 g", - Fiber: "3 g", - Protein: "6 g", - SaturatedFat: "7 g", + Calories: "249", + Carbohydrates: "12", + Cholesterol: "1", + Fat: "21", + Fiber: "3", + Protein: "6", + SaturatedFat: "7", Servings: "1", - Sodium: "106 mg", - Sugar: "7 g", - TransFat: "1 g", + Sodium: "106", + Sugar: "7", + TransFat: "1", }, PrepTime: "PT15M", Yield: &models.Yield{Value: 20}, @@ -197,18 +198,18 @@ func TestScraper_P(t *testing.T) { }, Name: "Slow Cooker French Toast Casserole", NutritionSchema: &models.NutritionSchema{ - Calories: "494 kcal", - Carbohydrates: "42 g", - Cholesterol: "162 mg", - Fat: "31 g", - Fiber: "2 g", - Protein: "11 g", - SaturatedFat: "17 g", + Calories: "494", + Carbohydrates: "42", + Cholesterol: "162", + Fat: "31", + Fiber: "2", + Protein: "11", + SaturatedFat: "17", Servings: "1 g", - Sodium: "335 mg", - Sugar: "30 g", - TransFat: "0.4 g", - UnsaturatedFat: "13 g", + Sodium: "335", + Sugar: "30", + TransFat: "0.4", + UnsaturatedFat: "13", }, PrepTime: "PT15M", TotalTime: "PT495M", @@ -290,16 +291,16 @@ func TestScraper_P(t *testing.T) { }, Name: "The Best Soft Chocolate Chip Cookies", NutritionSchema: &models.NutritionSchema{ - Calories: "250 calories", - Carbohydrates: "33.4 g", - Cholesterol: "35.9 mg", - Fat: "12.2 g", - Fiber: "1.4 g", - Protein: "3.2 g", - SaturatedFat: "7.5 g", - Sodium: "169.3 mg", - Sugar: "20.5 g", - TransFat: "0.3 g", + Calories: "250", + Carbohydrates: "33.4", + Cholesterol: "35.9", + Fat: "12.2", + Fiber: "1.4", + Protein: "3.2", + SaturatedFat: "7.5", + Sodium: "169.3", + Sugar: "20.5", + TransFat: "0.3", }, PrepTime: "PT10M", TotalTime: "PT20M", @@ -348,7 +349,7 @@ func TestScraper_P(t *testing.T) { }, Name: "Tarte de alho-francês caramelizado", NutritionSchema: &models.NutritionSchema{ - Calories: "411 calories", + Calories: "411", }, PrepTime: "PT45M", Tools: &models.Tools{Values: []models.HowToItem{}}, @@ -399,16 +400,16 @@ func TestScraper_P(t *testing.T) { }, Name: "Cajun Dirty Rice with Smoked Sausage", NutritionSchema: &models.NutritionSchema{ - Calories: "389 kcal", - Carbohydrates: "45.4 g", - Cholesterol: "63 mg", - Fat: "15.5 g", - Fiber: "1.9 g", - Protein: "17 g", - SaturatedFat: "4.8 g", + Calories: "389", + Carbohydrates: "45.4", + Cholesterol: "63", + Fat: "15.5", + Fiber: "1.9", + Protein: "17", + SaturatedFat: "4.8", Servings: "1", - Sodium: "942 mg", - Sugar: "4.5 g", + Sodium: "942", + Sugar: "4.5", }, PrepTime: "PT10M", Tools: &models.Tools{Values: []models.HowToItem{}}, @@ -455,18 +456,18 @@ func TestScraper_P(t *testing.T) { }, Name: "Mushroom Tart Recipe", NutritionSchema: &models.NutritionSchema{ - Calories: "197 kcal", - Carbohydrates: "12 g", - Cholesterol: "29 mg", - Fat: "14 g", - Fiber: "1 g", - Protein: "7 g", - SaturatedFat: "5 g", + Calories: "197", + Carbohydrates: "12", + Cholesterol: "29", + Fat: "14", + Fiber: "1", + Protein: "7", + SaturatedFat: "5", Servings: "1", - Sodium: "274 mg", - Sugar: "1 g", - TransFat: "1 g", - UnsaturatedFat: "8 g", + Sodium: "274", + Sugar: "1", + TransFat: "1", + UnsaturatedFat: "8", }, PrepTime: "PT15M", TotalTime: "PT30M", @@ -541,18 +542,18 @@ func TestScraper_P(t *testing.T) { }, Name: "The Best Rich and Moist Chocolate Cake", NutritionSchema: &models.NutritionSchema{ - Calories: "363 kcal", - Carbohydrates: "37 g", - Cholesterol: "54 mg", - Fat: "23 g", - Fiber: "2 g", - Protein: "5 g", - SaturatedFat: "8 g", + Calories: "363", + Carbohydrates: "37", + Cholesterol: "54", + Fat: "23", + Fiber: "2", + Protein: "5", + SaturatedFat: "8", Servings: "1", - Sodium: "353 mg", - Sugar: "23 g", - TransFat: "0.1 g", - UnsaturatedFat: "13 g", + Sodium: "353", + Sugar: "23", + TransFat: "0.1", + UnsaturatedFat: "13", }, PrepTime: "PT10M", TotalTime: "PT45M", @@ -597,7 +598,7 @@ func TestScraper_P(t *testing.T) { }, Name: "These Cinnamon-Butter Carrots Are Almost Too Easy to Make", NutritionSchema: &models.NutritionSchema{ - Calories: "219 per serving", + Calories: "219", }, Tools: &models.Tools{Values: []models.HowToItem{}}, TotalTime: "PT1H30M", @@ -750,18 +751,18 @@ func TestScraper_P(t *testing.T) { }, Name: "Slow Cooker Crack Chicken (Cheesy Ranch Chicken)", NutritionSchema: &models.NutritionSchema{ - Calories: "603 kcal", - Carbohydrates: "3 g", - Cholesterol: "247 mg", - Fat: "39 g", - Fiber: "1 g", - Protein: "37 g", - SaturatedFat: "23 g", + Calories: "603", + Carbohydrates: "3", + Cholesterol: "247", + Fat: "39", + Fiber: "1", + Protein: "37", + SaturatedFat: "23", Servings: "1", - Sodium: "689 mg", - Sugar: "1 g", - TransFat: "1 g", - UnsaturatedFat: "30 g", + Sodium: "689", + Sugar: "1", + TransFat: "1", + UnsaturatedFat: "30", }, PrepTime: "PT5M", TotalTime: "PT365M", @@ -809,11 +810,11 @@ func TestScraper_P(t *testing.T) { }, Name: "Italiaanse kiprollade met gremolata", NutritionSchema: &models.NutritionSchema{ - Calories: "125 kcal", - Carbohydrates: "1 gram", - Fat: "5 gram", - Fiber: "1 gram", - Protein: "18 gram", + Calories: "125", + Carbohydrates: "1", + Fat: "5", + Fiber: "1", + Protein: "18", }, Tools: &models.Tools{Values: []models.HowToItem{}}, Yield: &models.Yield{Value: 1}, @@ -947,8 +948,8 @@ func TestScraper_P(t *testing.T) { }, Name: "Gnocchi Al Pesto with Charred Green Beans & Lemon Zucchini", NutritionSchema: &models.NutritionSchema{ - Calories: "540 cal", - Fat: "22.0 g", + Calories: "540", + Fat: "22.0", }, PrepTime: "PT30M", Tools: &models.Tools{Values: []models.HowToItem{}}, diff --git a/internal/scraper/scraper_Q_test.go b/internal/scraper/scraper_Q_test.go index 3bd0284d..dba7cc4e 100644 --- a/internal/scraper/scraper_Q_test.go +++ b/internal/scraper/scraper_Q_test.go @@ -1,8 +1,9 @@ package scraper_test import ( - "github.com/reaper47/recipya/internal/models" "testing" + + "github.com/reaper47/recipya/internal/models" ) func TestScraper_Q(t *testing.T) { @@ -41,15 +42,15 @@ func TestScraper_Q(t *testing.T) { }, Name: "Saumon teriyaki et riz au poireau", NutritionSchema: &models.NutritionSchema{ - Calories: "617.85 kcal", - Carbohydrates: "70.12 g", - Fat: "20.49 g", - Fiber: "4.76 g", - Protein: "34.94 g", - SaturatedFat: "2.81 g", + Calories: "617.85", + Carbohydrates: "70.12", + Fat: "20.49", + Fiber: "4.76", + Protein: "34.94", + SaturatedFat: "2.81", Servings: "2", - Sodium: "0.56 g", - Sugar: "10.45 g", + Sodium: "0.56", + Sugar: "10.45", }, PrepTime: "PT20M", Tools: &models.Tools{Values: []models.HowToItem{}}, diff --git a/internal/scraper/scraper_R_test.go b/internal/scraper/scraper_R_test.go index 933eb761..b6a07af3 100644 --- a/internal/scraper/scraper_R_test.go +++ b/internal/scraper/scraper_R_test.go @@ -1,8 +1,9 @@ package scraper_test import ( - "github.com/reaper47/recipya/internal/models" "testing" + + "github.com/reaper47/recipya/internal/models" ) func TestScraper_R(t *testing.T) { @@ -107,16 +108,16 @@ func TestScraper_R(t *testing.T) { }, Name: "Tuscan Stewed Beans", NutritionSchema: &models.NutritionSchema{ - Calories: "472 kcal", - Carbohydrates: "59 g", - Fat: "16 g", - Fiber: "14 g", - Protein: "18 g", - SaturatedFat: "2 g", + Calories: "472", + Carbohydrates: "59", + Fat: "16", + Fiber: "14", + Protein: "18", + SaturatedFat: "2", Servings: "1", - Sodium: "1117 mg", - Sugar: "7 g", - UnsaturatedFat: "13 g", + Sodium: "1117", + Sugar: "7", + UnsaturatedFat: "13", }, PrepTime: "PT15M", TotalTime: "PT75M", @@ -160,15 +161,15 @@ func TestScraper_R(t *testing.T) { }, Name: "Sheet Pan Chicken and Sweet Potatoes", NutritionSchema: &models.NutritionSchema{ - Calories: "533 kcal", - Carbohydrates: "22 g", - Cholesterol: "181 mg", - Fat: "34 g", - Protein: "34 g", - SaturatedFat: "9 g", - Sodium: "670 mg", - Sugar: "5 g", - UnsaturatedFat: "0 g", + Calories: "533", + Carbohydrates: "22", + Cholesterol: "181", + Fat: "34", + Protein: "34", + SaturatedFat: "9", + Sodium: "670", + Sugar: "5", + UnsaturatedFat: "0", }, TotalTime: "PT30M", URL: "https://www.realsimple.com/food-recipes/browse-all-recipes/sheet-pan-chicken-and-sweet-potatoes", @@ -311,18 +312,18 @@ func TestScraper_R(t *testing.T) { }, Name: "Cranberry Apple Sauce", NutritionSchema: &models.NutritionSchema{ - Calories: "117 calories", - Carbohydrates: "30 grams carbohydrates", - Cholesterol: "0 milligrams cholesterol", - Fat: "0 grams fat", - Fiber: "3 grams fiber", - Protein: "0 grams protein", - SaturatedFat: "0 grams saturated fat", + Calories: "117", + Carbohydrates: "30", + Cholesterol: "0", + Fat: "0", + Fiber: "3", + Protein: "0", + SaturatedFat: "0", Servings: "1", - Sodium: "48 milligrams sodium", - Sugar: "23 grams sugar", - TransFat: "0 grams trans fat", - UnsaturatedFat: "0 grams unsaturated fat", + Sodium: "48", + Sugar: "23", + TransFat: "0", + UnsaturatedFat: "0", }, PrepTime: "PT5M", Tools: &models.Tools{Values: []models.HowToItem{}}, @@ -385,15 +386,15 @@ func TestScraper_R(t *testing.T) { }, Name: "Chicken Shawarma (Middle Eastern)", NutritionSchema: &models.NutritionSchema{ - Calories: "275 kcal", - Carbohydrates: "1.1 g", - Cholesterol: "140 mg", - Fat: "16.2 g", - Protein: "32.9 g", - SaturatedFat: "3.2 g", + Calories: "275", + Carbohydrates: "1.1", + Cholesterol: "140", + Fat: "16.2", + Protein: "32.9", + SaturatedFat: "3.2", Servings: "183 g", - Sodium: "918 mg", - UnsaturatedFat: "13 g", + Sodium: "918", + UnsaturatedFat: "13", }, PrepTime: "PT10M", TotalTime: "PT20M", @@ -492,7 +493,7 @@ func TestScraper_R(t *testing.T) { }, Name: "Pork Fried Rice (猪肉炒饭)", NutritionSchema: &models.NutritionSchema{ - Calories: "455 kcal", + Calories: "455", Servings: "1", }, PrepTime: "PT10M", diff --git a/internal/scraper/scraper_S_test.go b/internal/scraper/scraper_S_test.go index d8991038..dbe44e08 100644 --- a/internal/scraper/scraper_S_test.go +++ b/internal/scraper/scraper_S_test.go @@ -1,8 +1,9 @@ package scraper_test import ( - "github.com/reaper47/recipya/internal/models" "testing" + + "github.com/reaper47/recipya/internal/models" ) func TestScraper_S(t *testing.T) { @@ -282,17 +283,17 @@ func TestScraper_S(t *testing.T) { }, Name: "Miyeok-Guk (Korean Seaweed and Brisket Soup)", NutritionSchema: &models.NutritionSchema{ - Calories: "173 kcal", - Carbohydrates: "2 g", - Cholesterol: "60 mg", - Fat: "11 g", - Fiber: "0 g", - Protein: "17 g", - SaturatedFat: "4 g", + Calories: "173", + Carbohydrates: "2", + Cholesterol: "60", + Fat: "11", + Fiber: "0", + Protein: "17", + SaturatedFat: "4", Servings: "4", - Sodium: "421 mg", - Sugar: "0 g", - UnsaturatedFat: "0 g", + Sodium: "421", + Sugar: "0", + UnsaturatedFat: "0", }, PrepTime: "PT5M", TotalTime: "PT185M", @@ -337,16 +338,16 @@ func TestScraper_S(t *testing.T) { }, Name: "Southern Blackberry Cobbler (Vegan + Easy)", NutritionSchema: &models.NutritionSchema{ - Calories: "245 calories", - Carbohydrates: "28.3 g", - Cholesterol: "0 mg", - Fat: "13.5 g", - Fiber: "7 g", - Protein: "5.5 g", - SaturatedFat: "10.1 g", - Sodium: "215.6 mg", - Sugar: "5.5 g", - TransFat: "0 g", + Calories: "245", + Carbohydrates: "28.3", + Cholesterol: "0", + Fat: "13.5", + Fiber: "7", + Protein: "5.5", + SaturatedFat: "10.1", + Sodium: "215.6", + Sugar: "5.5", + TransFat: "0", UnsaturatedFat: "", }, PrepTime: "PT5M", @@ -385,10 +386,10 @@ func TestScraper_S(t *testing.T) { }, Name: "Buntes Paprikagulasch", NutritionSchema: &models.NutritionSchema{ - Calories: "577 kcal", - Carbohydrates: "16 g", - Fat: "36 g", - Protein: "38 g", + Calories: "577", + Carbohydrates: "16", + Fat: "36", + Protein: "38", }, TotalTime: "PT1H59M00S", Tools: &models.Tools{Values: []models.HowToItem{}}, @@ -437,16 +438,16 @@ func TestScraper_S(t *testing.T) { }, Name: "Spicy Kimchi Quinoa Bowls", NutritionSchema: &models.NutritionSchema{ - Calories: "359 kcal", - Carbohydrates: "46 g", - Cholesterol: "163 mg", - Fat: "12 g", - Fiber: "5 g", - Protein: "17 g", - SaturatedFat: "2 g", + Calories: "359", + Carbohydrates: "46", + Cholesterol: "163", + Fat: "12", + Fiber: "5", + Protein: "17", + SaturatedFat: "2", Servings: "1", - Sodium: "489 mg", - Sugar: "1 g", + Sodium: "489", + Sugar: "1", }, PrepTime: "PT3M", TotalTime: "PT13M", @@ -513,17 +514,17 @@ func TestScraper_S(t *testing.T) { }, Name: "Chicken Tikka Masala", NutritionSchema: &models.NutritionSchema{ - Calories: "324 kcal", - Carbohydrates: "25 g", - Cholesterol: "84 mg", - Fat: "10 g", - Fiber: "3 g", - Protein: "34 g", - SaturatedFat: "2 g", + Calories: "324", + Carbohydrates: "25", + Cholesterol: "84", + Fat: "10", + Fiber: "3", + Protein: "34", + SaturatedFat: "2", Servings: "4", - Sodium: "828 mg", - Sugar: "5 g", - UnsaturatedFat: "0 g", + Sodium: "828", + Sugar: "5", + UnsaturatedFat: "0", }, PrepTime: "PT15M", TotalTime: "PT35M", @@ -575,16 +576,16 @@ func TestScraper_S(t *testing.T) { }, Name: "Dill Pickle Pasta Salad", NutritionSchema: &models.NutritionSchema{ - Calories: "386 calories", - Carbohydrates: "25.7 g", - Cholesterol: "16.2 mg", - Fat: "28.5 g", - Fiber: "1.6 g", - Protein: "7 g", - SaturatedFat: "5.1 g", - Sodium: "356.8 mg", - Sugar: "1.9 g", - TransFat: "0.1 g", + Calories: "386", + Carbohydrates: "25.7", + Cholesterol: "16.2", + Fat: "28.5", + Fiber: "1.6", + Protein: "7", + SaturatedFat: "5.1", + Sodium: "356.8", + Sugar: "1.9", + TransFat: "0.1", }, PrepTime: "PT15M", TotalTime: "PT25M", @@ -630,15 +631,15 @@ func TestScraper_S(t *testing.T) { }, Name: "Air Fryer Steak", NutritionSchema: &models.NutritionSchema{ - Calories: "221 kcal", - Carbohydrates: "0.5 g", - Cholesterol: "117.5 mg", - Fat: "7 g", - Fiber: "0.5 g", - Protein: "39.5 g", - SaturatedFat: "2 g", + Calories: "221", + Carbohydrates: "0.5", + Cholesterol: "117.5", + Fat: "7", + Fiber: "0.5", + Protein: "39.5", + SaturatedFat: "2", Servings: "1", - Sodium: "391 mg", + Sodium: "391", }, PrepTime: "PT5M", TotalTime: "PT15M", @@ -964,15 +965,15 @@ func TestScraper_S(t *testing.T) { }, Name: "Split Pea Soup", NutritionSchema: &models.NutritionSchema{ - Calories: "365 kcal", - Carbohydrates: "45 g", - Cholesterol: "29 mg", - Fat: "9 g", - Fiber: "18 g", - Protein: "27 g", - SaturatedFat: "3 g", - Sodium: "900 mg", - Sugar: "8 g", + Calories: "365", + Carbohydrates: "45", + Cholesterol: "29", + Fat: "9", + Fiber: "18", + Protein: "27", + SaturatedFat: "3", + Sodium: "900", + Sugar: "8", }, PrepTime: "PT20M", TotalTime: "PT150M", @@ -1028,10 +1029,10 @@ func TestScraper_S(t *testing.T) { }, Name: "Seafood Dressing Recipe", NutritionSchema: &models.NutritionSchema{ - Calories: "289 kcal", - Carbohydrates: "17 g", - Fat: "9 g", - Protein: "9 g", + Calories: "289", + Carbohydrates: "17", + Fat: "9", + Protein: "9", Servings: "1", }, PrepTime: "PT15M", @@ -1081,16 +1082,16 @@ func TestScraper_S(t *testing.T) { }, Name: "Korean Style Tacos with Kogi BBQ Sauce Recipe", NutritionSchema: &models.NutritionSchema{ - Calories: "503 kcal", - Carbohydrates: "48 g", - Cholesterol: "102 mg", - Fat: "20 g", - Fiber: "5 g", - Protein: "34 g", - SaturatedFat: "6 g", + Calories: "503", + Carbohydrates: "48", + Cholesterol: "102", + Fat: "20", + Fiber: "5", + Protein: "34", + SaturatedFat: "6", Servings: "1", - Sodium: "722 mg", - Sugar: "11 g", + Sodium: "722", + Sugar: "11", }, PrepTime: "PT60M", Tools: &models.Tools{Values: []models.HowToItem{}}, @@ -1170,10 +1171,10 @@ func TestScraper_S(t *testing.T) { }, Name: "Latin-inspired creamy chicken stew", NutritionSchema: &models.NutritionSchema{ - Calories: "490 calories", - Carbohydrates: "36 g", - Fat: "12 g", - Protein: "47 g", + Calories: "490", + Carbohydrates: "36", + Fat: "12", + Protein: "47", }, TotalTime: "PT550M", Tools: &models.Tools{Values: []models.HowToItem{}}, @@ -1226,13 +1227,13 @@ func TestScraper_S(t *testing.T) { Name: "Chicken and dumplings", NutritionSchema: &models.NutritionSchema{ Calories: "520", - Cholesterol: "135mg", - Fat: "21g", - Fiber: "2g", - Protein: "34g", - SaturatedFat: "3.5g", - Sodium: "830mg", - Sugar: "7g", + Cholesterol: "135", + Fat: "21", + Fiber: "2", + Protein: "34", + SaturatedFat: "3.5", + Sodium: "830", + Sugar: "7", }, Tools: &models.Tools{Values: []models.HowToItem{}}, Yield: &models.Yield{Value: 2}, @@ -1277,7 +1278,7 @@ func TestScraper_S(t *testing.T) { }, Name: "Shawarma bowl", NutritionSchema: &models.NutritionSchema{ - Calories: "300 kcal", + Calories: "300", Servings: "1", }, PrepTime: "PT30M", @@ -1329,13 +1330,15 @@ func TestScraper_S(t *testing.T) { {Type: "HowToStep", Text: "Remove pot from heat. Stir in the chocolate, 1/2 tsp. salt, and the remaining 3 tbsp. vinegar. Serve warm, topped with garnishes, if using."}, }, }, - Name: "Veggie Chili", - NutritionSchema: &models.NutritionSchema{}, - PrepTime: "PT0H0M", - Tools: &models.Tools{Values: []models.HowToItem{}}, - TotalTime: "PT0H0M", - Yield: &models.Yield{Value: 8}, - URL: "https://www.sunset.com/recipe/veggie-chili", + Name: "Veggie Chili", + NutritionSchema: &models.NutritionSchema{ + Calories: "0", + }, + PrepTime: "PT0H0M", + Tools: &models.Tools{Values: []models.HowToItem{}}, + TotalTime: "PT0H0M", + Yield: &models.Yield{Value: 8}, + URL: "https://www.sunset.com/recipe/veggie-chili", }, }, { @@ -1382,16 +1385,16 @@ func TestScraper_S(t *testing.T) { }, Name: "Roasted Tomato Marinara Sauce", NutritionSchema: &models.NutritionSchema{ - Calories: "68 kcal", - Carbohydrates: "8 g", - Fat: "4 g", - Fiber: "2 g", - Protein: "1 g", - SaturatedFat: "1 g", + Calories: "68", + Carbohydrates: "8", + Fat: "4", + Fiber: "2", + Protein: "1", + SaturatedFat: "1", Servings: "1", - Sodium: "46 mg", - Sugar: "5 g", - UnsaturatedFat: "3 g", + Sodium: "46", + Sugar: "5", + UnsaturatedFat: "3", }, PrepTime: "PT5M", TotalTime: "PT50M", @@ -1446,16 +1449,16 @@ func TestScraper_S(t *testing.T) { }, Name: "Cilantro Lime Chicken Crockpot Tacos", NutritionSchema: &models.NutritionSchema{ - Calories: "267 kcal", - Carbohydrates: "28 g", - Cholesterol: "73 mg", - Fat: "4 g", - Fiber: "6 g", - Protein: "31 g", - SaturatedFat: "1 g", + Calories: "267", + Carbohydrates: "28", + Cholesterol: "73", + Fat: "4", + Fiber: "6", + Protein: "31", + SaturatedFat: "1", Servings: "0.5 cup", - Sodium: "227 mg", - Sugar: "7 g", + Sodium: "227", + Sugar: "7", }, PrepTime: "PT15M", TotalTime: "PT260M", diff --git a/internal/scraper/scraper_T_test.go b/internal/scraper/scraper_T_test.go index 97fd35b9..40a9e2d5 100644 --- a/internal/scraper/scraper_T_test.go +++ b/internal/scraper/scraper_T_test.go @@ -1,8 +1,9 @@ package scraper_test import ( - "github.com/reaper47/recipya/internal/models" "testing" + + "github.com/reaper47/recipya/internal/models" ) func TestScraper_T(t *testing.T) { @@ -40,13 +41,13 @@ func TestScraper_T(t *testing.T) { }, Name: "Cast-Iron Skillet Steak", NutritionSchema: &models.NutritionSchema{ - Calories: "494 calories", - Carbohydrates: "0 carbohydrate (0 sugars", - Cholesterol: "134mg cholesterol", - Fat: "36g fat (15g saturated fat)", - Fiber: "0 fiber)", - Protein: "40g protein. ", - Sodium: "2983mg sodium", + Calories: "494", + Carbohydrates: "0", + Cholesterol: "134", + Fat: "36", + Fiber: "0", + Protein: "40", + Sodium: "2983", }, PrepTime: "PT5M", Tools: &models.Tools{Values: []models.HowToItem{}}, @@ -97,16 +98,16 @@ func TestScraper_T(t *testing.T) { }, Name: "The BEST Apple Crisp", NutritionSchema: &models.NutritionSchema{ - Calories: "382 kcal", - Carbohydrates: "57 g", - Cholesterol: "42 mg", - Fat: "16 g", - Fiber: "3 g", - Protein: "2 g", - SaturatedFat: "10 g", + Calories: "382", + Carbohydrates: "57", + Cholesterol: "42", + Fat: "16", + Fiber: "3", + Protein: "2", + SaturatedFat: "10", Servings: "1", - Sodium: "64 mg", - Sugar: "38 g", + Sodium: "64", + Sugar: "38", }, PrepTime: "PT15M", TotalTime: "PT50M", @@ -157,18 +158,18 @@ func TestScraper_T(t *testing.T) { }, Name: "Ham Pie", NutritionSchema: &models.NutritionSchema{ - Calories: "474 kcal", - Carbohydrates: "24 g", - Cholesterol: "192 mg", - Fat: "30 g", - Fiber: "1 g", - Protein: "26 g", - SaturatedFat: "14 g", + Calories: "474", + Carbohydrates: "24", + Cholesterol: "192", + Fat: "30", + Fiber: "1", + Protein: "26", + SaturatedFat: "14", Servings: "1", - Sodium: "913 mg", - Sugar: "1 g", - TransFat: "1 g", - UnsaturatedFat: "13 g", + Sodium: "913", + Sugar: "1", + TransFat: "1", + UnsaturatedFat: "13", }, PrepTime: "PT20M", TotalTime: "PT125M", @@ -218,12 +219,12 @@ func TestScraper_T(t *testing.T) { }, Name: "Honey Soy-Glazed Salmon Recipe by Tasty", NutritionSchema: &models.NutritionSchema{ - Calories: "705 calories", - Carbohydrates: "60 grams", - Fat: "35 grams", - Fiber: "0 grams", - Protein: "37 grams", - Sugar: "57 grams", + Calories: "705", + Carbohydrates: "60", + Fat: "35", + Fiber: "0", + Protein: "37", + Sugar: "57", }, Tools: &models.Tools{Values: []models.HowToItem{}}, Yield: &models.Yield{Value: 2}, @@ -300,14 +301,14 @@ func TestScraper_T(t *testing.T) { Image: &models.Image{Value: anUploadedImage.String()}, Yield: &models.Yield{Value: 6}, NutritionSchema: &models.NutritionSchema{ - Calories: "855 calories", - Carbohydrates: "64.2 grams carbohydrate", + Calories: "855", + Carbohydrates: "64.2", Cholesterol: "", - Fat: "44 grams fat", - Fiber: "10.4 grams fibre", - Protein: "51.2 grams protein", - SaturatedFat: "16 grams saturated fat", - Sugar: "21 grams sugar", + Fat: "44", + Fiber: "10.4", + Protein: "51.2", + SaturatedFat: "16", + Sugar: "21", }, Ingredients: &models.Ingredients{ Values: []string{ @@ -578,17 +579,17 @@ func TestScraper_T(t *testing.T) { }, Name: "BLT Pasta Salad", NutritionSchema: &models.NutritionSchema{ - Calories: "653 kcal", - Carbohydrates: "10 g", - Cholesterol: "78 mg", - Fat: "60 g", - Fiber: "3 g", - Protein: "20 g", - SaturatedFat: "15 g", + Calories: "653", + Carbohydrates: "10", + Cholesterol: "78", + Fat: "60", + Fiber: "3", + Protein: "20", + SaturatedFat: "15", Servings: "1", - Sodium: "1533 mg", - Sugar: "3 g", - TransFat: "1 g", + Sodium: "1533", + Sugar: "3", + TransFat: "1", }, PrepTime: "PT30M", Yield: &models.Yield{Value: 12}, @@ -632,17 +633,17 @@ func TestScraper_T(t *testing.T) { }, Name: "The Best Method for Reheating Turkey So It Never Dries Out", NutritionSchema: &models.NutritionSchema{ - Calories: "194 cal", - Carbohydrates: "2.3 g", - Cholesterol: "0 mg", - Fat: "9.1 g", - Fiber: "0 g", - Protein: "26.1 g", - SaturatedFat: "4.3 g", + Calories: "194", + Carbohydrates: "2.3", + Cholesterol: "0", + Fat: "9.1", + Fiber: "0", + Protein: "26.1", + SaturatedFat: "4.3", Servings: "Serves 4", - Sodium: "175.8 mg", - Sugar: "1.0 g", - UnsaturatedFat: "0.0 g", + Sodium: "175.8", + Sugar: "1.0", + UnsaturatedFat: "0.0", }, Tools: &models.Tools{Values: []models.HowToItem{}}, TotalTime: "PT0S", @@ -691,18 +692,18 @@ func TestScraper_T(t *testing.T) { }, Name: "Slow Cooker Apple Cider Pot Roast", NutritionSchema: &models.NutritionSchema{ - Calories: "565 kcal", - Carbohydrates: "26 g", - Cholesterol: "156 mg", - Fat: "31 g", - Fiber: "4 g", - Protein: "46 g", - SaturatedFat: "12 g", + Calories: "565", + Carbohydrates: "26", + Cholesterol: "156", + Fat: "31", + Fiber: "4", + Protein: "46", + SaturatedFat: "12", Servings: "1", - Sodium: "908 mg", - Sugar: "9 g", - TransFat: "2 g", - UnsaturatedFat: "19 g", + Sodium: "908", + Sugar: "9", + TransFat: "2", + UnsaturatedFat: "19", }, PrepTime: "PT15M", TotalTime: "PT495M", @@ -817,16 +818,16 @@ func TestScraper_T(t *testing.T) { }, Name: "Turkey Pozole Rojo", NutritionSchema: &models.NutritionSchema{ - Calories: "406 calories", - Carbohydrates: "47 grams carbohydrates", - Cholesterol: "0 milligrams cholesterol", - Fat: "6 grams fat", - Fiber: "13 grams fiber", - Protein: "8 grams protein", - SaturatedFat: "1 grams saturated fat", + Calories: "406", + Carbohydrates: "47", + Cholesterol: "0", + Fat: "6", + Fiber: "13", + Protein: "8", + SaturatedFat: "1", Servings: "8", - Sodium: "1800 milligrams sodium", - Sugar: "23 grams sugar", + Sodium: "1800", + Sugar: "23", }, PrepTime: "PT20M", TotalTime: "PT1H20M", @@ -956,16 +957,16 @@ func TestScraper_T(t *testing.T) { }, Name: "The Best Avocado Egg Rolls", NutritionSchema: &models.NutritionSchema{ - Calories: "187 kcal", - Carbohydrates: "15 g", - Cholesterol: "1 mg", - Fat: "14 g", - Fiber: "5 g", - Protein: "3 g", - SaturatedFat: "4 g", + Calories: "187", + Carbohydrates: "15", + Cholesterol: "1", + Fat: "14", + Fiber: "5", + Protein: "3", + SaturatedFat: "4", Servings: "1", - Sodium: "80 mg", - Sugar: "1 g", + Sodium: "80", + Sugar: "1", }, PrepTime: "PT15M", TotalTime: "PT20M", @@ -1027,16 +1028,16 @@ func TestScraper_T(t *testing.T) { }, Name: "Pasta With Anchovies and Breadcrumbs Recipe", NutritionSchema: &models.NutritionSchema{ - Calories: "642 kcal", - Carbohydrates: "90 g", - Cholesterol: "3 mg", - Fat: "24 g", - Fiber: "4 g", - Protein: "17 g", - SaturatedFat: "3 g", - Sodium: "518 mg", - Sugar: "5 g", - UnsaturatedFat: "0 g", + Calories: "642", + Carbohydrates: "90", + Cholesterol: "3", + Fat: "24", + Fiber: "4", + Protein: "17", + SaturatedFat: "3", + Sodium: "518", + Sugar: "5", + UnsaturatedFat: "0", }, PrepTime: "PT15M", TotalTime: "PT43M", @@ -1144,16 +1145,16 @@ func TestScraper_T(t *testing.T) { }, Name: "Fried Wontons", NutritionSchema: &models.NutritionSchema{ - Calories: "164 kcal", - Carbohydrates: "15 g", - Cholesterol: "23 mg", - Fat: "8 g", - Fiber: "1 g", - Protein: "7 g", - SaturatedFat: "2 g", + Calories: "164", + Carbohydrates: "15", + Cholesterol: "23", + Fat: "8", + Fiber: "1", + Protein: "7", + SaturatedFat: "2", Servings: "1", - Sodium: "243 mg", - Sugar: "1 g", + Sodium: "243", + Sugar: "1", }, PrepTime: "PT90M", TotalTime: "PT110M", @@ -1193,13 +1194,13 @@ func TestScraper_T(t *testing.T) { }, Name: "Low-Carb Yogurt", NutritionSchema: &models.NutritionSchema{ - Calories: "70 kcal", - Carbohydrates: "4 g", - Fat: "4 g", - Protein: "5 g", + Calories: "70", + Carbohydrates: "4", + Fat: "4", + Protein: "5", Servings: "12", - Sodium: "55 mg", - Sugar: "4 g", + Sodium: "55", + Sugar: "4", }, PrepTime: "PT5M", Yield: &models.Yield{Value: 12}, @@ -1243,18 +1244,18 @@ func TestScraper_T(t *testing.T) { }, Name: "Make-Ahead Mashed Potatoes", NutritionSchema: &models.NutritionSchema{ - Calories: "193 calories", - Carbohydrates: "22 grams carbohydrates", - Cholesterol: "30 milligrams cholesterol", - Fat: "11 grams fat", - Fiber: "2 grams fiber", - Protein: "4 grams protein", - SaturatedFat: "7 grams saturated fat", + Calories: "193", + Carbohydrates: "22", + Cholesterol: "30", + Fat: "11", + Fiber: "2", + Protein: "4", + SaturatedFat: "7", Servings: "1", - Sodium: "221 milligrams sodium", - Sugar: "3 grams sugar", - TransFat: "0 grams trans fat", - UnsaturatedFat: "3 grams unsaturated fat", + Sodium: "221", + Sugar: "3", + TransFat: "0", + UnsaturatedFat: "3", }, PrepTime: "PT15M", Tools: &models.Tools{Values: []models.HowToItem{}}, @@ -1301,7 +1302,7 @@ func TestScraper_T(t *testing.T) { }, Name: "Beetroot Cold Soup Recipe", NutritionSchema: &models.NutritionSchema{ - Calories: "189 cal", + Calories: "189", Servings: "1", }, PrepTime: "PT10M", @@ -1448,18 +1449,18 @@ func TestScraper_T(t *testing.T) { Keywords: &models.Keywords{Values: "vegetarian"}, Name: "Chickpea Salad", NutritionSchema: &models.NutritionSchema{ - Calories: "215 kcal", - Carbohydrates: "32 g", - Cholesterol: "1 mg", - Fat: "5 g", - Fiber: "10 g", - Protein: "14 g", - SaturatedFat: "1 g", + Calories: "215", + Carbohydrates: "32", + Cholesterol: "1", + Fat: "5", + Fiber: "10", + Protein: "14", + SaturatedFat: "1", Servings: "1", - Sodium: "803 mg", - Sugar: "2 g", - TransFat: "1 g", - UnsaturatedFat: "3 g", + Sodium: "803", + Sugar: "2", + TransFat: "1", + UnsaturatedFat: "3", }, PrepTime: "PT10M", TotalTime: "PT6M", diff --git a/internal/scraper/scraper_V_test.go b/internal/scraper/scraper_V_test.go index 69ed36bd..2924892f 100644 --- a/internal/scraper/scraper_V_test.go +++ b/internal/scraper/scraper_V_test.go @@ -1,8 +1,9 @@ package scraper_test import ( - "github.com/reaper47/recipya/internal/models" "testing" + + "github.com/reaper47/recipya/internal/models" ) func TestScraper_V(t *testing.T) { @@ -126,18 +127,18 @@ func TestScraper_V(t *testing.T) { }, Name: "Carrot Cake Bread Recipe", NutritionSchema: &models.NutritionSchema{ - Calories: "476 kcal", - Carbohydrates: "38 g", - Cholesterol: "68 mg", - Fat: "35 g", - Fiber: "2 g", - Protein: "6 g", - SaturatedFat: "22 g", + Calories: "476", + Carbohydrates: "38", + Cholesterol: "68", + Fat: "35", + Fiber: "2", + Protein: "6", + SaturatedFat: "22", Servings: "1", - Sodium: "263 mg", - Sugar: "22 g", - TransFat: "1 g", - UnsaturatedFat: "11 g", + Sodium: "263", + Sugar: "22", + TransFat: "1", + UnsaturatedFat: "11", }, PrepTime: "PT30M", TotalTime: "PT90M", @@ -304,16 +305,16 @@ func TestScraper_V(t *testing.T) { }, Name: "Paneer Butter Masala Recipe (Restaurant Style)", NutritionSchema: &models.NutritionSchema{ - Calories: "307 kcal", - Carbohydrates: "9 g", - Cholesterol: "66 mg", - Fat: "27 g", - Fiber: "2 g", - Protein: "9 g", - SaturatedFat: "15 g", + Calories: "307", + Carbohydrates: "9", + Cholesterol: "66", + Fat: "27", + Fiber: "2", + Protein: "9", + SaturatedFat: "15", Servings: "1", - Sodium: "493 mg", - Sugar: "4 g", + Sodium: "493", + Sugar: "4", }, PrepTime: "PT10M", TotalTime: "PT40M", diff --git a/internal/scraper/scraper_W_test.go b/internal/scraper/scraper_W_test.go index f786ab18..8e3aef64 100644 --- a/internal/scraper/scraper_W_test.go +++ b/internal/scraper/scraper_W_test.go @@ -1,8 +1,9 @@ package scraper_test import ( - "github.com/reaper47/recipya/internal/models" "testing" + + "github.com/reaper47/recipya/internal/models" ) func TestScraper_W(t *testing.T) { @@ -36,14 +37,14 @@ func TestScraper_W(t *testing.T) { }, Name: "The best macaroni cheese", NutritionSchema: &models.NutritionSchema{ - Calories: "724 calories", - Carbohydrates: "60 g", - Fat: "39 g", - Fiber: "2.6 g", - Protein: "32 g", - SaturatedFat: "24 g", - Sodium: "1.6 g", - Sugar: "8.7 g", + Calories: "724", + Carbohydrates: "60", + Fat: "39", + Fiber: "2.6", + Protein: "32", + SaturatedFat: "24", + Sodium: "1.6", + Sugar: "8.7", }, PrepTime: "PT15M", Tools: &models.Tools{Values: []models.HowToItem{}}, @@ -96,7 +97,7 @@ func TestScraper_W(t *testing.T) { }, Name: "Healthy Fried Brown Rice With Vegetables", NutritionSchema: &models.NutritionSchema{ - Calories: "336 kcal", + Calories: "336", Servings: "1", }, PrepTime: "PT15M", @@ -178,7 +179,7 @@ func TestScraper_W(t *testing.T) { }, Name: "Pepperoni flatbread pizza", NutritionSchema: &models.NutritionSchema{ - Calories: "484 kcal", + Calories: "484", }, PrepTime: "PT5M", Tools: &models.Tools{Values: []models.HowToItem{}}, @@ -225,14 +226,14 @@ func TestScraper_W(t *testing.T) { }, Name: "Energy Balls", NutritionSchema: &models.NutritionSchema{ - Calories: "131 kcal", - Carbohydrates: "18 g", - Fat: "5 g", - Fiber: "3 g", - Protein: "4 g", - SaturatedFat: "1 g", + Calories: "131", + Carbohydrates: "18", + Fat: "5", + Fiber: "3", + Protein: "4", + SaturatedFat: "1", Servings: "1", - Sugar: "6 g", + Sugar: "6", }, PrepTime: "PT10M", TotalTime: "PT40M", @@ -279,18 +280,18 @@ func TestScraper_W(t *testing.T) { Keywords: &models.Keywords{Values: "homemade pizza, spring pizza"}, Name: "Pea Prosciutto Spring Pizza", NutritionSchema: &models.NutritionSchema{ - Calories: "610 kcal", - Carbohydrates: "56 g", - Cholesterol: "123 mg", - Fat: "33 g", - Fiber: "5 g", - Protein: "24 g", - SaturatedFat: "11 g", + Calories: "610", + Carbohydrates: "56", + Cholesterol: "123", + Fat: "33", + Fiber: "5", + Protein: "24", + SaturatedFat: "11", Servings: "1", - Sodium: "1124 mg", - Sugar: "11 g", - TransFat: "0.04 g", - UnsaturatedFat: "19 g", + Sodium: "1124", + Sugar: "11", + TransFat: "0.04", + UnsaturatedFat: "19", }, PrepTime: "PT10M", TotalTime: "PT20M", @@ -474,10 +475,10 @@ func TestScraper_W(t *testing.T) { }, Keywords: &models.Keywords{Values: "Magento, Varien, E-commerce"}, NutritionSchema: &models.NutritionSchema{ - Calories: "2536kj (606Kcal)", - Carbohydrates: "43g", - Protein: "44g", - Fat: "28g", + Calories: "606", + Carbohydrates: "43", + Protein: "44", + Fat: "28", }, Tools: &models.Tools{Values: []models.HowToItem{}}, URL: "https://woop.co.nz/thai-marinated-beef-sirlion-344-2-f.html", diff --git a/internal/scraper/scraper_{0-9}_test.go b/internal/scraper/scraper_{0-9}_test.go index 212e1e4b..fffca2a2 100644 --- a/internal/scraper/scraper_{0-9}_test.go +++ b/internal/scraper/scraper_{0-9}_test.go @@ -1,8 +1,9 @@ package scraper_test import ( - "github.com/reaper47/recipya/internal/models" "testing" + + "github.com/reaper47/recipya/internal/models" ) func TestScraper_0to9(t *testing.T) { @@ -40,12 +41,12 @@ func TestScraper_0to9(t *testing.T) { }, }, NutritionSchema: &models.NutritionSchema{ - Calories: "233 kcal", - Carbohydrates: "19 g", + Calories: "233", + Carbohydrates: "19", Cholesterol: "", - Fat: "15 g", - Protein: "6 g", - Sodium: "287 mg", + Fat: "15", + Protein: "6", + Sodium: "287", Servings: "1", }, Keywords: &models.Keywords{Values: "simple"}, diff --git a/internal/scraper/woop.go b/internal/scraper/woop.go index d5f66ad9..747ce479 100644 --- a/internal/scraper/woop.go +++ b/internal/scraper/woop.go @@ -1,10 +1,13 @@ package scraper import ( - "github.com/PuerkitoBio/goquery" + "regexp" "strings" + "github.com/PuerkitoBio/goquery" + "github.com/reaper47/recipya/internal/models" + "github.com/reaper47/recipya/internal/utils/regex" ) func scrapeWoop(root *goquery.Document) (models.RecipeSchema, error) { @@ -40,13 +43,17 @@ func scrapeWoop(root *goquery.Document) (models.RecipeSchema, error) { val := strings.TrimSpace(strings.Join(parts[1:], " ")) switch parts[0] { case "Energy": - nutrition.Calories = val + if match := regexp.MustCompile(`(\d+)Kcal`).FindStringSubmatch(val); len(match) > 1 { + nutrition.Calories = match[1] + } else { + nutrition.Calories = "" + } case "Protein": - nutrition.Protein = val + nutrition.Protein = regex.Digit.FindString(val) case "Carbohydrate": - nutrition.Carbohydrates = val + nutrition.Carbohydrates = regex.Digit.FindString(val) case "Fat": - nutrition.Fat = val + nutrition.Fat = regex.Digit.FindString(val) } }) rs.NutritionSchema = &nutrition diff --git a/internal/server/handlers_recipes_test.go b/internal/server/handlers_recipes_test.go index 00f3d9e1..1ae43ab1 100644 --- a/internal/server/handlers_recipes_test.go +++ b/internal/server/handlers_recipes_test.go @@ -4,12 +4,6 @@ import ( "bytes" "errors" "fmt" - "github.com/google/go-cmp/cmp" - "github.com/google/uuid" - "github.com/reaper47/recipya/internal/app" - "github.com/reaper47/recipya/internal/models" - "github.com/reaper47/recipya/internal/server" - "github.com/reaper47/recipya/internal/services" "io" "net/http" "net/http/httptest" @@ -19,6 +13,13 @@ import ( "strings" "testing" "time" + + "github.com/google/go-cmp/cmp" + "github.com/google/uuid" + "github.com/reaper47/recipya/internal/app" + "github.com/reaper47/recipya/internal/models" + "github.com/reaper47/recipya/internal/server" + "github.com/reaper47/recipya/internal/services" ) func TestHandlers_Recipes(t *testing.T) { @@ -632,15 +633,15 @@ func TestHandlers_Recipes_Edit(t *testing.T) { Name: "Chicken Jersey", Nutrition: models.Nutrition{ Calories: "354", - Cholesterol: "1g", - Fiber: "2g", - Protein: "3g", - SaturatedFat: "4g", - Sodium: "5g", - Sugars: "6g", - TotalCarbohydrates: "7g", - TotalFat: "8g", - UnsaturatedFat: "9g", + Cholesterol: "1", + Fiber: "2", + Protein: "3", + SaturatedFat: "4", + Sodium: "5", + Sugars: "6", + TotalCarbohydrates: "7", + TotalFat: "8", + UnsaturatedFat: "9", }, Times: models.Times{ Prep: 30 * time.Minute, @@ -710,7 +711,7 @@ func TestHandlers_Recipes_Edit(t *testing.T) { `A delicious recipe!`, `PrepCooking`, - `CaloriesTotal carbsSugarsProteinTotal fatSaturated fatCholesterolSodiumFiber`, + `CaloriesTotal carbsSugarsProteinTotal fatSaturated fatUnsaturated fatCholesterolSodiumFiber`, ``, ``, ``, @@ -1260,11 +1261,11 @@ func TestHandlers_Recipes_Share(t *testing.T) { Name: "Chicken Jersey", Nutrition: models.Nutrition{ Calories: "500", - Cholesterol: "1g", + Cholesterol: "1mg", Fiber: "2g", Protein: "3g", SaturatedFat: "4g", - Sodium: "5g", + Sodium: "5mg", Sugars: "6g", TotalCarbohydrates: "7g", TotalFat: "8g", @@ -1314,9 +1315,9 @@ func TestHandlers_Recipes_Share(t *testing.T) { `

2 servings

`, `Source`, ``, - `

Per 100g: calories 500; total carbohydrates 7g; sugar 6g; protein 3g; total fat 8g; saturated fat 4g; cholesterol 1g; fiber 2g

`, + `

Per 100g: calories 500 kcal; total carbohydrates 7 g; sugar 6 g; protein 3 g; total fat 8 g; saturated fat 4 g; unsaturated fat 9 g; cholesterol 1 mg; sodium 5 mg; fiber 2 g

`, `
Timeh:m:s
Prep:
Cooking:
Total:
`, - `
Nutrition (per 100g)Amount
Calories:500
Total carbs:7g
Sugars:6g
Protein:3g
Total fat:8g
Saturated fat:4g
Cholesterol:1g
Sodium:5g
Fiber:2g
`, + `
Nutrition (per 100g)Amount
Calories:500 kcal
Total carbs:7 g
Sugars:6 g
Protein:3 g
Total fat:8 g
Saturated fat:4 g
Unsaturated fat:9 g
Cholesterol:1 mg
Sodium:5 mg
Fiber:2 g
`, `

Ingredients

Instructions

  1. Ins1
  2. Ins2
  3. Ins3
`, `

Instructions

  1. Ins1
  2. Ins2
  3. Ins3
`, } @@ -1604,11 +1605,11 @@ func TestHandlers_Recipes_View(t *testing.T) { Name: "Chicken Jersey", Nutrition: models.Nutrition{ Calories: "500", - Cholesterol: "1g", + Cholesterol: "1mg", Fiber: "2g", Protein: "3g", SaturatedFat: "4g", - Sodium: "5g", + Sodium: "5mg", Sugars: "6g", TotalCarbohydrates: "7g", TotalFat: "8g", @@ -1641,9 +1642,9 @@ func TestHandlers_Recipes_View(t *testing.T) { `
`, `Source`, ``, - `

Per 100g: calories 500; total carbohydrates 7g; sugar 6g; protein 3g; total fat 8g; saturated fat 4g; cholesterol 1g; fiber 2g

`, + `

Per 100g: calories 500 kcal; total carbohydrates 7 g; sugar 6 g; protein 3 g; total fat 8 g; saturated fat 4 g; unsaturated fat 9 g; cholesterol 1 mg; sodium 5 mg; fiber 2 g

`, `
Timeh:m:s
Prep:
Cooking:
Total:
`, - `
Nutrition (per 100g)Amount
Calories:500
Total carbs:7g
Sugars:6g
Protein:3g
Total fat:8g
Saturated fat:4g
Cholesterol:1g
Sodium:5g
Fiber:2g
`, + `
Nutrition (per 100g)Amount
Calories:500 kcal
Total carbs:7 g
Sugars:6 g
Protein:3 g
Total fat:8 g
Saturated fat:4 g
Unsaturated fat:9 g
Cholesterol:1 mg
Sodium:5 mg
Fiber:2 g
`, } assertStringsInHTML(t, getBodyHTML(rr), want) }) From 748a5e9ab670d92e8bb758fe3112d040f8b7a20d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20Blenneg=C3=A5rd?= Date: Thu, 4 Jul 2024 09:49:43 +0200 Subject: [PATCH 10/11] Minor changes as discussed in PR https://github.com/reaper47/recipya/pull/382 --- internal/models/schema-recipe.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/internal/models/schema-recipe.go b/internal/models/schema-recipe.go index b8917d8b..136049b5 100644 --- a/internal/models/schema-recipe.go +++ b/internal/models/schema-recipe.go @@ -871,17 +871,17 @@ func (n *NutritionSchema) UnmarshalJSON(data []byte) error { switch x := v.(type) { case map[string]any: - n.Calories = regex.Digit.FindString(strings.Replace(extensions.ConvertToString(x["calories"]), ",", ".", -1)) - n.Carbohydrates = regex.Digit.FindString(strings.Replace(extensions.ConvertToString(x["carbohydrateContent"]), ",", ".", -1)) - n.Cholesterol = regex.Digit.FindString(strings.Replace(extensions.ConvertToString(x["cholesterolContent"]), ",", ".", -1)) - n.Fat = regex.Digit.FindString(strings.Replace(extensions.ConvertToString(x["fatContent"]), ",", ".", -1)) - n.SaturatedFat = regex.Digit.FindString(strings.Replace(extensions.ConvertToString(x["saturatedFatContent"]), ",", ".", -1)) - n.UnsaturatedFat = regex.Digit.FindString(strings.Replace(extensions.ConvertToString(x["unsaturatedFatContent"]), ",", ".", -1)) - n.TransFat = regex.Digit.FindString(strings.Replace(extensions.ConvertToString(x["transFatContent"]), ",", ".", -1)) - n.Protein = regex.Digit.FindString(strings.Replace(extensions.ConvertToString(x["proteinContent"]), ",", ".", -1)) - n.Sugar = regex.Digit.FindString(strings.Replace(extensions.ConvertToString(x["sugarContent"]), ",", ".", -1)) - n.Sodium = regex.Digit.FindString(strings.Replace(extensions.ConvertToString(x["sodiumContent"]), ",", ".", -1)) - n.Fiber = regex.Digit.FindString(strings.Replace(extensions.ConvertToString(x["fiberContent"]), ",", ".", -1)) + n.Calories = regex.Digit.FindString(strings.ReplaceAll(extensions.ConvertToString(x["calories"]), ",", ".")) + n.Carbohydrates = regex.Digit.FindString(strings.ReplaceAll(extensions.ConvertToString(x["carbohydrateContent"]), ",", ".")) + n.Cholesterol = regex.Digit.FindString(strings.ReplaceAll(extensions.ConvertToString(x["cholesterolContent"]), ",", ".")) + n.Fat = regex.Digit.FindString(strings.ReplaceAll(extensions.ConvertToString(x["fatContent"]), ",", ".")) + n.SaturatedFat = regex.Digit.FindString(strings.ReplaceAll(extensions.ConvertToString(x["saturatedFatContent"]), ",", ".")) + n.UnsaturatedFat = regex.Digit.FindString(strings.ReplaceAll(extensions.ConvertToString(x["unsaturatedFatContent"]), ",", ".")) + n.TransFat = regex.Digit.FindString(strings.ReplaceAll(extensions.ConvertToString(x["transFatContent"]), ",", ".")) + n.Protein = regex.Digit.FindString(strings.ReplaceAll(extensions.ConvertToString(x["proteinContent"]), ",", ".")) + n.Sugar = regex.Digit.FindString(strings.ReplaceAll(extensions.ConvertToString(x["sugarContent"]), ",", ".")) + n.Sodium = regex.Digit.FindString(strings.ReplaceAll(extensions.ConvertToString(x["sodiumContent"]), ",", ".")) + n.Fiber = regex.Digit.FindString(strings.ReplaceAll(extensions.ConvertToString(x["fiberContent"]), ",", ".")) if val := extensions.ConvertToString(x["servingSize"]); val != "" { xs := strings.Split(val, " ") @@ -906,9 +906,9 @@ func (n *NutritionSchema) UnmarshalJSON(data []byte) error { // EnsureNutritionUnitForString extracts digits from nutritional property and appends metric unit. // Returns a string value. func EnsureNutritionUnitForString(nutritionValue any, nutritionProperty string) string { - var nutritionPropertyLowerCase = strings.ToLower(nutritionProperty) - var nutritionString string = extensions.ConvertToString(nutritionValue) - var nutritionStringDigits string = regex.Digit.FindString(nutritionString) + nutritionPropertyLowerCase := strings.ToLower(nutritionProperty) + nutritionString := extensions.ConvertToString(nutritionValue) + nutritionStringDigits := regex.Digit.FindString(nutritionString) // Early return if no digits could be found if nutritionStringDigits == "" { From 3d62cea260307515a4ed242e683e65776c617069 Mon Sep 17 00:00:00 2001 From: reaper47 Date: Thu, 4 Jul 2024 16:38:40 +0200 Subject: [PATCH 11/11] Bump templ version to build the project --- go.mod | 2 +- go.sum | 6 ++---- web/components/core.templ | 2 +- web/components/layouts.templ | 4 +--- web/components/reports.templ | 2 +- 5 files changed, 6 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index d009cae7..85d578df 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.22.0 require ( github.com/PuerkitoBio/goquery v1.9.2 - github.com/a-h/templ v0.2.707 + github.com/a-h/templ v0.2.731 github.com/blang/semver v3.5.1+incompatible github.com/briandowns/spinner v1.23.1 github.com/disintegration/imaging v1.6.2 diff --git a/go.sum b/go.sum index 8fb6928e..6ca97abb 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/PuerkitoBio/goquery v1.9.2 h1:4/wZksC3KgkQw7SQgkKotmKljk0M6V8TUvA8Wb4yPeE= github.com/PuerkitoBio/goquery v1.9.2/go.mod h1:GHPCaP0ODyyxqcNoFGYlAprUFH81NuRPd0GX3Zu2Mvk= -github.com/a-h/templ v0.2.707 h1:T1Gkd2ugbRglZ9rYw/VBchWOSZVKmetDbBkm4YubM7U= -github.com/a-h/templ v0.2.707/go.mod h1:5cqsugkq9IerRNucNsI4DEamdHPsoGMQy99DzydLhM8= +github.com/a-h/templ v0.2.731 h1:yiv4C7whSUsa36y65O06DPr/U/j3+WGB0RmvLOoVFXc= +github.com/a-h/templ v0.2.731/go.mod h1:IejA/ecDD0ul0dCvgCwp9t7bUZXVpGClEAdsqZQigi8= github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw= github.com/andybalholm/cascadia v1.3.2 h1:3Xi6Dw5lHF15JtdcmAHD3i1+T8plmv7BQ/nsViSLyss= github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6lUvCFb+h7KvU= @@ -123,8 +123,6 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/pressly/goose/v3 v3.20.0 h1:uPJdOxF/Ipj7ABVNOAMJXSxwFXZGwMGHNqjC8e61VA0= -github.com/pressly/goose/v3 v3.20.0/go.mod h1:BRfF2GcG4FTG12QfdBVy3q1yveaf4ckL9vWwEcIO3lA= github.com/pressly/goose/v3 v3.21.1 h1:5SSAKKWej8LVVzNLuT6KIvP1eFDuPvxa+B6H0w78buQ= github.com/pressly/goose/v3 v3.21.1/go.mod h1:sqthmzV8PitchEkjecFJII//l43dLOCzfWh8pHEe+vE= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= diff --git a/web/components/core.templ b/web/components/core.templ index c21bb47f..f7b650ab 100644 --- a/web/components/core.templ +++ b/web/components/core.templ @@ -1,8 +1,8 @@ package components import ( - "time" "github.com/reaper47/recipya/internal/templates" + "time" ) templ HomePage(data templates.Data) { diff --git a/web/components/layouts.templ b/web/components/layouts.templ index c3f1c520..7908bad3 100644 --- a/web/components/layouts.templ +++ b/web/components/layouts.templ @@ -1,8 +1,6 @@ package components -import ( - "github.com/reaper47/recipya/internal/templates" -) +import "github.com/reaper47/recipya/internal/templates" templ layoutAuth(title string) { diff --git a/web/components/reports.templ b/web/components/reports.templ index 44a6b83f..0154a242 100644 --- a/web/components/reports.templ +++ b/web/components/reports.templ @@ -2,8 +2,8 @@ package components import ( "fmt" - "time" "github.com/reaper47/recipya/internal/templates" + "time" ) templ ReportsIndex(data templates.Data, isHighlightFirst bool) {