소스 검색

Get recipe instructions from LitK recipes

Tati 7 년 전
부모
커밋
f9f7ee3bd9
2개의 변경된 파일10개의 추가작업 그리고 2개의 파일을 삭제
  1. 4 2
      ktchn/src/recipes/index.ts
  2. 6 0
      ktchn/src/recipes/scrape.ts

+ 4 - 2
ktchn/src/recipes/index.ts

@@ -43,15 +43,17 @@ export class Recipe {
   tags!: string[];
   ingredients!: ComposedIngredients[];
   details!: RecipeDetails;
-  directions!: string[];
+  instructions!: string[];
 
   constructor(
     name: string,
     details?: RecipeDetails,
-    ingredients?: ComposedIngredients[]
+    ingredients?: ComposedIngredients[],
+    instructions?: string[],
   ) {
     this.name = name;
     this.details = details || new RecipeDetails();
     this.ingredients = ingredients || [];
+    this.instructions = instructions || [];
   }
 }

+ 6 - 0
ktchn/src/recipes/scrape.ts

@@ -90,11 +90,17 @@ function getRecipeName($:CheerioSelector): string {
   return $('.cs-page-title>h1').text().trim();
 }
 
+function getInstructions($:CheerioSelector): string[] {
+  const data = $('#recipe-process').find('ul').text();
+  return data.split('\n').filter(s => s !== '').map(s => s.trim().replace(/^\d\)\s*/, ''));
+}
+
 function lauraInTheKitchen($:CheerioSelector):Recipe {
   let recipe = new Recipe(
     getRecipeName($),
     getRecipeDetails($),
     getIngredients($),
+    getInstructions($),
   );
   return recipe;
 }