Bladeren bron

Fix build errors. Add video prop to recipe model

Tatiana Inama 6 jaren geleden
bovenliggende
commit
b030ea7632

+ 14 - 14
ktchn/package.json

@@ -5,45 +5,45 @@
   "scripts": {
     "start": "ts-node --inspect-brk=9229 src/server.ts",
     "dev": "node node_modules/nodemon/bin/nodemon.js ts-node --inspect-brk=9229 src/server.ts",
-    "build": "tsc -p .",
+    "build": "cd node_modules/recipe-ingredient-parser && npm run build && cd ../../ && tsc -p .",
     "build:live": "nodemon --watch 'src/**/*.ts' --exec ts-node src/server.ts"
   },
   "dependencies": {
-    "@types/chai": "^4.1.7",
-    "@types/cheerio": "^0.22.9",
+    "@types/chai": "^4.2.8",
+    "@types/cheerio": "^0.22.16",
     "@types/cookie-parser": "^1.4.1",
     "@types/dotenv": "^6.1.1",
-    "@types/express": "^4.16.0",
+    "@types/express": "^4.17.2",
     "@types/jest": "^23.3.12",
-    "@types/mongodb": "^3.1.19",
+    "@types/mongodb": "^3.3.15",
     "@types/natural": "^0.2.33",
-    "@types/request": "^2.48.0",
-    "@types/request-promise": "^4.1.42",
+    "@types/request": "^2.48.4",
+    "@types/request-promise": "^4.1.45",
     "chai": "^4.2.0",
-    "cheerio": "^1.0.0-rc.2",
+    "cheerio": "^1.0.0-rc.3",
     "cookie-parser": "~1.4.3",
     "debug": "~2.6.9",
     "dotenv": "^6.2.0",
     "express": "~4.16.0",
     "moment": "^2.24.0",
-    "mongodb": "^3.1.13",
+    "mongodb": "^3.5.2",
     "morgan": "~1.9.0",
     "nano": "^7.1.0",
     "natural": "^0.6.3",
     "ramda": "^0.26.1",
     "recipe-ingredient-parser": "git+https://github.com/DavidVentura/recipe-parser.git",
     "request": "^2.88.0",
-    "request-promise": "^4.2.4"
+    "request-promise": "^4.2.5"
   },
   "devDependencies": {
     "@types/morgan": "^1.7.35",
-    "@types/node": "^10.12.0",
+    "@types/node": "^10.17.14",
     "@types/ramda": "github:types/npm-ramda#dist",
     "eslint": "^5.8.0",
     "eslint-config-airbnb-base": "^13.1.0",
-    "eslint-plugin-import": "^2.14.0",
-    "nodemon": "^1.18.9",
+    "eslint-plugin-import": "^2.20.1",
+    "nodemon": "^1.19.4",
     "ts-node": "^7.0.1",
-    "typescript": "^3.3.3"
+    "typescript": "3.7.5"
   }
 }

+ 2 - 0
ktchn/src/recipes/model.ts

@@ -33,6 +33,8 @@ export class RecipeDetails {
   preparationTime: string;
   cookingTime: string;
   servings: number;
+  url?: string;
+  video?: string;
 
   constructor(
     prepTime: string = '',

+ 2 - 2
ktchn/src/recipes/scrape/sources/all-recipes.ts

@@ -18,8 +18,8 @@ const SELECTORS = {
 
 function getRecipeDetails($: CheerioSelector): RecipeDetails {
   return {
-    preparationTime: getAttr($)(SELECTORS.PREP_TIME, SELECTORS.DATETIME),
-    cookingTime: getAttr($)(SELECTORS.COOK_TIME, SELECTORS.DATETIME),
+    preparationTime: getAttr($)(SELECTORS.PREP_TIME, SELECTORS.DATETIME) || '',
+    cookingTime: getAttr($)(SELECTORS.COOK_TIME, SELECTORS.DATETIME) || '',
     servings: Number(getAttr($)(SELECTORS.SERVINGS, SELECTORS.CONTENT)),
   };
 }

+ 4 - 2
ktchn/src/recipes/scrape/sources/home-cooking-adventure.ts

@@ -6,6 +6,7 @@ const SELECTORS = {
   TITLE: 'h1[itemprop="name"]',
   PREP_TIME: 'time[itemprop="prepTime"]',
   COOK_TIME: 'time[itemprop="cookTime"]',
+  VIDEO: 'div#subtitle iframe',
   SERVINGS: 'span.ingheading',
   INGREDIENTS: 'div#ingredients_bg ul li',
   INSTRUCTIONS: 'div#preparation ol li',
@@ -18,9 +19,10 @@ function getRecipeName($: CheerioSelector): string {
 
 function getRecipeDetails($: CheerioSelector): RecipeDetails {
   return {
-    preparationTime: $(SELECTORS.PREP_TIME).attr('content'),
-    cookingTime: $(SELECTORS.COOK_TIME).attr('content'),
+    preparationTime: $(SELECTORS.PREP_TIME).attr('content') || '',
+    cookingTime: $(SELECTORS.COOK_TIME).attr('content') || '',
     servings: Number($(SELECTORS.SERVINGS).text().replace(/\D/g, '')),
+    video: ($(SELECTORS.VIDEO).attr('src') || '').replace('//', '') || '',
   }
 }
 

+ 2 - 0
recipes/src/types/recipes.ts

@@ -18,6 +18,7 @@ export interface Author {
 
 export interface Details {
   url?: string,
+  video?: string,
   preparationTime: string,
   cookingTime: string,
   servings: number
@@ -42,6 +43,7 @@ export const _recipe: Recipe = {
   },
   details: {
     url: '',
+    video: '',
     preparationTime: '',
     cookingTime: '',
     servings: 0