Last active
January 15, 2021 15:09
-
-
Save Dagimal/17f4b98f1afcc0c99a7045630b1aa9ea to your computer and use it in GitHub Desktop.
Recipe Scrapers with paraphraser tools [only directions]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import datetime | |
| from tqdm import tqdm | |
| from recipe_scrapers import scrape_me | |
| from paraphraser import paraphrase | |
| #LineCounter | |
| number_of_lines = len(open('new.txt').readlines( )) | |
| loop = -1 | |
| pbar = tqdm(total = int(number_of_lines)) | |
| while loop <= number_of_lines: | |
| try: | |
| loop += 1 | |
| #loopAndGrab | |
| file = open("new.txt", "r") | |
| lines = file.readlines() | |
| scraper = scrape_me(lines[loop]) | |
| #GunakanBarisDibawahJikaError | |
| #scraper = scrape_me(lines[loop].replace("\n", "").replace(" ", "")) | |
| #slug | |
| originalSlug = scraper.title().replace(" ", "-") | |
| ### export | |
| f = open(str(loop) + "-" + originalSlug.lower().replace("/", "|") + ".md", "w") | |
| #frontMatter | |
| print(("---"), file=f) | |
| print("layout: recipe", file=f) | |
| print("title: " + '"' + scraper.title().replace('"', ' ').replace("'", " ") + '"', file=f) | |
| print("lead: " + '"' + scraper.title().replace('"', ' ').replace("'", " ") + '"', file=f) | |
| print("image: " + scraper.image(), file=f) | |
| print("yield: " + '"' + scraper.yields() + '"', file=f) | |
| dateString = "date: 2020-11-05" | |
| print(dateString, file=f) | |
| #date = datetime.datetime.now().replace(microsecond=0) | |
| #print(dateString + str(date), file=f) | |
| #print("authorName: " + scraper.author().replace('"', ' ').replace("'", " "), file=f) | |
| print("ingredients:", file=f) | |
| ingredient = [ingredient for ingredient in scraper.ingredients()] | |
| for i in ingredient: | |
| print('- ' + '"%s"' % i.replace('"', ' ').replace("'", " "), file=f) | |
| print("directions:", file=f) | |
| ##quoteFilter = scraper.instructions().replace('"', ' ').replace("'", " ") | |
| ##print('- ' + '"' + quoteFilter.replace('\n', '" \n- "') + '"', file=f) | |
| ##print(("---"), file=f) | |
| #paraphrase_instructions | |
| first = scraper.instructions().replace('"', ' ').replace("'", " "> | |
| after = paraphrase(first) | |
| #print('- "', file=f) | |
| print('- "' + after[1].replace(" | ", '"\n- "') + '"', file=f) | |
| print("---", file=f) | |
| pbar.update(1) | |
| except NotImplementedError: | |
| print("Page " + str(loop) + " Not Found!") | |
| continue | |
| pbar.close() | |
| #print(scraper.title()) | |
| #print(scraper.total_time()) | |
| #print(scraper.yields()) | |
| #print(scraper.ingredients()) | |
| #print(scraper.instructions()) | |
| #print(scraper.image()) | |
| #print(scraper.host()) | |
| #print(scraper.links()) | |
| #print(scraper.author()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment