From b57063e99c31b2131edd09379cc6ee0ed6cf45fb Mon Sep 17 00:00:00 2001 From: Navan Chauhan Date: Sun, 29 Dec 2019 00:11:35 +0530 Subject: Added Files --- README.md | 37 +++++++ assets/ss1.png | Bin 0 -> 268128 bytes assets/ss2.png | Bin 0 -> 2365698 bytes assets/ss3.png | Bin 0 -> 980807 bytes html/template.html | 296 +++++++++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 2 + simple.html | 55 ++++++++++ stylized.html | 296 +++++++++++++++++++++++++++++++++++++++++++++++++++++ web2recipe.py | 92 +++++++++++++++++ 9 files changed, 778 insertions(+) create mode 100644 README.md create mode 100644 assets/ss1.png create mode 100644 assets/ss2.png create mode 100644 assets/ss3.png create mode 100644 html/template.html create mode 100644 requirements.txt create mode 100644 simple.html create mode 100644 stylized.html create mode 100644 web2recipe.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..45a6ced --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +# Web2Recipe + +This is a simple Python script to scrap recipes from websites and then generate stylized/non-stylized (no-extra-crap) single page HTML pages + +``` +usage: web2recipe.py [-h] [-S] [-V] [-U URL] + +This program takes the URL of a website with the target recipe, scraps it and +stylises it. If the stylized argument is not passed, then it generates a +vanilla HTML file + +optional arguments: + -h, --help show this help message and exit + -S, --stylized generate stylized html + -V, --version show program version + -U URL, --url URL input url +``` + +### Screenshots + +#### Simple + +![non-stylized](./assets/ss1.png, "Non-Stylised") + +![stylized](./assets/ss2.png, "Stylised") + +![stylized-mobile](./assets/ss3.png, "Stylised (Mobile)") + +### Requirements + +* BeutifulSoup4 +* Markdown2 + +### Acknowledgemnts + +* Zack Schollz Github: schollz - Ingredients API +* CodePen: oliviale - Recipe Layout CSS \ No newline at end of file diff --git a/assets/ss1.png b/assets/ss1.png new file mode 100644 index 0000000..8c7295e Binary files /dev/null and b/assets/ss1.png differ diff --git a/assets/ss2.png b/assets/ss2.png new file mode 100644 index 0000000..2b011d0 Binary files /dev/null and b/assets/ss2.png differ diff --git a/assets/ss3.png b/assets/ss3.png new file mode 100644 index 0000000..60690fa Binary files /dev/null and b/assets/ss3.png differ diff --git a/html/template.html b/html/template.html new file mode 100644 index 0000000..0ea8a81 --- /dev/null +++ b/html/template.html @@ -0,0 +1,296 @@ + + + + + Recipe (Web2Recipe) + + + + + + + +
+ +
+
+
+
REPLACE-RECIPE-TITLE
+
+
+

Ingredients

+ REPLACE-INGREDIENTS +
+
+
Instructions
+ REPLACE-INSTRUCTIONS +
+
+ + + + \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..bb7a149 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +bs4 +markdown2 \ No newline at end of file diff --git a/simple.html b/simple.html new file mode 100644 index 0000000..046e0b9 --- /dev/null +++ b/simple.html @@ -0,0 +1,55 @@ +

Masala Dosa

+

Ingredients

+ + + + + + + + + + + + + + + + + +

Instructions

+
  1. soak 3 to 4 dry kashmiri red chilies (kashmiri lal mirch) in warm water for 30 to 40 minutes - add the number of chilies as per your taste preferences and depending on the type of chilies - whether they are less hot or too pungent.
  2. for a spicy taste in the chutney add 4 to 5 dry kashmiri red chilies. later drain all the water. break the chilies and add in a small grinder jar.
  3. also add 2 tablespoons roasted chana dal (roasted bengal gram or bhuna chana dal), 4 to 5 garlic cloves, 1 teaspoon seedlees tamarind and ¼ cup chopped onions. also add salt as required.
  4. if you do not like the raw taste of onions or garlic, then just sauté both in some oil for a few minutes and then add before grinding.
  5. now add water as required and grind all the ingredients till smooth. grind the chutney to a slightly thick or medium consistency and not to a thin consistency.
  6. remove the red dosa chutney in a bowl.
  7. spread this red chutney after dosa becomes golden and crisp. then spread the potato masala. fold and serve mysore masala dosa.
  8. this red chutney stays well in the refrigerator for 1 to 2 days. this red chutney recipe yields a small bowl of chutney which can be spread on 8 to 9 dosas.
\ No newline at end of file diff --git a/stylized.html b/stylized.html new file mode 100644 index 0000000..f816bed --- /dev/null +++ b/stylized.html @@ -0,0 +1,296 @@ + + + + + Recipe (Web2Recipe) + + + + + + + +
+ +
+
+
+
Masala Dosa
+
+
+

Ingredients

+
  • 20 whole seeds
  • 1 cup water
  • 2 cups water
  • 1 cup water
  • 0.5 cup water
  • 0.5 teaspoon salt (rock)
  • 2 tablespoons oil
  • 0.5 teaspoon mustard seeds
  • 1 whole inch ginger
  • 18 whole curry
  • 3 whole green
  • 0.25 teaspoon turmeric
  • 1 whole asafoetida
  • 0.5 cup water
  • 3 tablespoons coriander (chopped)
  • 18 whole cashews
  • 0.25 teaspoon sugar
  • +
+
+
Instructions
+
soak 3 to 4 dry kashmiri red chilies (kashmiri lal mirch) in warm water for 30 to 40 minutes - add the number of chilies as per your taste preferences and depending on the type of chilies - whether they are less hot or too pungent.

for a spicy taste in the chutney add 4 to 5 dry kashmiri red chilies. later drain all the water. break the chilies and add in a small grinder jar.

also add 2 tablespoons roasted chana dal (roasted bengal gram or bhuna chana dal), 4 to 5 garlic cloves, 1 teaspoon seedlees tamarind and ¼ cup chopped onions. also add salt as required.

if you do not like the raw taste of onions or garlic, then just sauté both in some oil for a few minutes and then add before grinding.

now add water as required and grind all the ingredients till smooth. grind the chutney to a slightly thick or medium consistency and not to a thin consistency.

remove the red dosa chutney in a bowl.

spread this red chutney after dosa becomes golden and crisp. then spread the potato masala. fold and serve mysore masala dosa.

this red chutney stays well in the refrigerator for 1 to 2 days. this red chutney recipe yields a small bowl of chutney which can be spread on 8 to 9 dosas.

+
+
+ + + + \ No newline at end of file diff --git a/web2recipe.py b/web2recipe.py new file mode 100644 index 0000000..26dbcd3 --- /dev/null +++ b/web2recipe.py @@ -0,0 +1,92 @@ +import argparse + +import requests +from bs4 import BeautifulSoup as Soup +from markdown2 import Markdown + +version = 1.0 +style = False + +text = 'This program takes the URL of a website with the target recipe, scraps it and stylises it. If the stylized argument is not passed, then it generates a vanilla HTML file' + +parser = argparse.ArgumentParser(description = text) +parser.add_argument("-S", "--stylized", help="generate stylized html", action="store_true") +parser.add_argument("-V", "--version", help="show program version", action="store_true") +parser.add_argument("-U", "--url", help="input url") + +args = parser.parse_args() + +if args.version: + print("Web2Recipe Version", version) + exit +if args.stylized: + style = True +if args.url: + url = args.url +else: + url = input("Enter Recipe Website URL: ") + + +markdowner = Markdown() + +params = (('url', url),) +response = requests.get('https://ingredients.schollz.now.sh/', params=params) + +json = response.json() +title = json["title"] +ingredients = [] + +def comment(x): + try: + c = "(" + str(x["comment"]) + ")" + return c + except: + return "" + +for x in json["ingredients"]: + i = x["measure"]["amount"], x["measure"]["name"], x["name"], comment(x) + ingredients.append(i) + +def genSimpleHTML(): + html = markdowner.convert("#" + title) + markdowner.convert("## Ingredients") + for x in ingredients: + s = "* " + for i in x: + s = s + str(i) + " " + html = html + markdowner.convert(s) + html = html + markdowner.convert('## Instructions') + html = html + "
    " + for x in json["instructions"]: + html = html + "
  1. " + x + "
  2. " + html = html + "
" + f = open("./simple.html", "w") + f.write(html) + f.close() + print("Succesfuly generated file for the recipe: ", title) + +def stylized(): + ing = "
    " + for x in ingredients: + s = "
  • " + for i in x: + s = s + str(i) + " " + ing = ing + s + ing = ing + "
  • " + ins = "" + for x in json["instructions"]: + ins = ins + "
    " + x + "

    " + f = open("html/template.html", "r") + template = str(f.read()) + template = template.replace("REPLACE-RECIPE-TITLE",title) + template = template.replace("REPLACE-INGREDIENTS",ing) + template = template.replace("REPLACE-INSTRUCTIONS",ins) + template = template.replace("REPLACE-IMG", json["image"]) + f = open("./stylized.html", "w") + f.write(template) + f.close() + print("Succesfuly generated stylized file for the recipe: ", title) + +if style: + stylized() +else: + genSimpleHTML() -- cgit v1.2.3