Skip to content

Commit

Permalink
Merge pull request #12 from RyanNoelk/dev
Browse files Browse the repository at this point in the history
Dev to master
  • Loading branch information
RyanNoelk authored Jun 3, 2017
2 parents 311fa6b + 9a74346 commit 59caac4
Show file tree
Hide file tree
Showing 33 changed files with 232 additions and 1,259 deletions.
18 changes: 4 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
A simple web scraping tool for recipe sites I use in a project of mine that makes sense to live as
a separate package.

pip install git+git://github.com/RyanNoelk/[email protected].3
pip install git+git://github.com/RyanNoelk/[email protected].5

then:

Expand Down Expand Up @@ -34,16 +34,6 @@ If you are programmer PRs with fixes are warmly welcomed and acknowledged with a
### Scrapers available for:

- [http://allrecipes.com/](http://allrecipes.com/)
- [http://bonappetit.com/](http://bonappetit.com/)
- [http://cookstr.com/](http://cookstr.com/)
- [http://epicurious.com/](http://epicurious.com/)
- [http://finedininglovers.com/](https://www.finedininglovers.com/)
- [http://foodrepublic.com/](http://foodrepublic.com)
- [http://jamieoliver.com/](http://www.jamieoliver.com/)
- [http://mybakingaddiction.com/](http://mybakingaddiction.com/)
- [http://simplyrecipes.com/](http://www.simplyrecipes.com)
- [http://steamykitchen.com/](http://steamykitchen.com/)
- [http://tastykitchen.com/](http://tastykitchen.com/)
- [http://thevintagemixer.com/](http://www.thevintagemixer.com/)
- [http://twopeasandtheirpod.com/](http://twopeasandtheirpod.com/)
- [http://whatsgabycooking.com/](http://whatsgabycooking.com/)
- [http://budgetbytes.com/](http://budgetbytes.com/)
- [http://pamperedchef.com/](http://pamperedchef.com/)
- [http://tasteofhome.com/](http://tasteofhome.com/)
17 changes: 16 additions & 1 deletion recipe_scrapers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/usr/bin/env python
# encoding: utf-8
import re
import datetime

from .allrecipes import AllRecipes
from .bonappetit import BonAppetit
from .budgetbytes import BudgetBytes
from .budgetbytesv2 import BudgetBytesv2
from .cookstr import Cookstr
from .epicurious import Epicurious
from .finedininglovers import FineDiningLovers
Expand All @@ -23,6 +25,7 @@
AllRecipes.host(): AllRecipes,
# BonAppetit.host(): BonAppetit,
BudgetBytes.host(): BudgetBytes,
BudgetBytesv2.host(): BudgetBytesv2,
# Cookstr.host(): Cookstr,
# Epicurious.host(): Epicurious,
# FineDiningLovers.host(): FineDiningLovers,
Expand Down Expand Up @@ -55,9 +58,21 @@ def url_path_to_dict(path):
return url_dict


def get_version(url_dict):
if url_dict['host'] == 'budgetbytes.com':
path = url_dict.get('path').split('/')
current_time = datetime.datetime.strptime(path[1] + '-' + path[2], '%Y-%m')
compare_time = datetime.datetime.strptime('2017-04', '%Y-%m')
if current_time > compare_time:
return url_dict['host'] + '-v2'
return url_dict['host']


def scrap_me(url_path):
url_path = url_path.replace('://www.', '://')
return SCRAPERS[url_path_to_dict(url_path)['host']](url_path)
url_dict = url_path_to_dict(url_path)
url_dict['host'] = get_version(url_dict)
return SCRAPERS[url_dict['host']](url_path)


__all__ = ['scrap_me']
33 changes: 0 additions & 33 deletions recipe_scrapers/bonappetit.py

This file was deleted.

2 changes: 1 addition & 1 deletion recipe_scrapers/budgetbytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def instructions(self):
]

def description(self):
li = self.soup.find('div', {'class': 'entry-content'}).findAll('p')
li = self.soup.find('article', {'class': 'post'}).findAll('p')
return li[0].get_text()

def image(self):
Expand Down
82 changes: 82 additions & 0 deletions recipe_scrapers/budgetbytesv2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env python
# encoding: utf-8

from fractions import Fraction
from ._abstract import AbstractScraper
from ._utils import normalize_string


class BudgetBytesv2(AbstractScraper):

@classmethod
def host(self):
return 'budgetbytes.com-v2'

def title(self):
return self.soup.find('h1').get_text()

def total_time(self):
return {
'prep-time': self.soup.find(
'span',
{'class': 'wprm-recipe-prep_time-minutes'}
).get_text(),
'cook-time': self.soup.find(
'span',
{'class': 'wprm-recipe-cook_time-minutes'}
).get_text()
}

def servings(self):
return self.soup.find('span', {'itemprop': 'recipeYield'}).get_text().split(' ', 1)[0]

def ingredients(self):
ingredients_html = self.soup.findAll('li', {'class': 'wprm-recipe-ingredient'})
ingredients = []

for ingredient in ingredients_html:
try:
ingredient_dict = {
'quantity': round(float(sum(Fraction(s) for s in ingredient.find(
'span',
{'class': 'wprm-recipe-ingredient-amount'}
).get_text().split())), 3),
'measurement': ingredient.find(
'span',
{'class': 'wprm-recipe-ingredient-unit'}
).get_text(),
'title': ingredient.find(
'span',
{'class': 'wprm-recipe-ingredient-name'}
).get_text()
}
except AttributeError:
ingredient_dict = {
'title': ingredient.find(
'span',
{'class': 'wprm-recipe-ingredient-name'}
).get_text()
}
except:
ingredient_dict = {
'title': ingredient
}

ingredients.append(ingredient_dict)

return ingredients

def instructions(self):
instructions_html = self.soup.findAll('li', {'class': 'wprm-recipe-instruction'})

return [
normalize_string(instruction.get_text())
for instruction in instructions_html
]

def description(self):
li = self.soup.find('article', {'class': 'post'}).findAll('p')
return li[0].get_text()

def image(self):
return self.soup.find('img', {'class': 'alignnone'})["src"]
35 changes: 0 additions & 35 deletions recipe_scrapers/cookstr.py

This file was deleted.

33 changes: 0 additions & 33 deletions recipe_scrapers/epicurious.py

This file was deleted.

33 changes: 0 additions & 33 deletions recipe_scrapers/finedininglovers.py

This file was deleted.

34 changes: 0 additions & 34 deletions recipe_scrapers/foodrepublic.py

This file was deleted.

30 changes: 0 additions & 30 deletions recipe_scrapers/jamieoliver.py

This file was deleted.

Loading

0 comments on commit 59caac4

Please sign in to comment.