Skip to content

Commit

Permalink
Merge pull request #715 from MrShark/master
Browse files Browse the repository at this point in the history
An importer for ica.se (Swedish storechain)
  • Loading branch information
ockham committed Apr 20, 2013
2 parents aa284f0 + dfc7427 commit 228706e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import about_dot_com_plugin
import foodnetwork_plugin
import allrecipes_plugin
import ica_se_plugin
plugins = [about_dot_com_plugin.AboutDotComPlugin,
foodnetwork_plugin.FoodNetworkPlugin,
allrecipes_plugin.AllRecipesPlugin
allrecipes_plugin.AllRecipesPlugin,
ica_se_plugin.IcaSePlugin,
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""
A plugin that tries to import recipes from the ica.se site
"""
from gourmet.plugin import PluginPlugin
import re

class Excluder(object):
def __init__(self, url):
self.url=url
def search(self, other_url):
return not (other_url.endswith(self.url))


class IcaSePlugin (PluginPlugin):

target_pluggable = 'webimport_plugin'

def test_url (self, url, data):
"Is this url from ica.se"
if 'ica.se' in url:
return 5

def get_importer (self, webpage_importer):

class IcaSeParser (webpage_importer.WebParser):

imageexcluders = []

def preparse (self):
self.preparsed_elements = []
for tag in self.soup.findAll(itemprop=True):
itemprop = tag.attrMap["itemprop"]
if itemprop == "name":
self.preparsed_elements.append((tag,'recipe'))
elif itemprop == "totalTime":
self.preparsed_elements.append((tag,'cooktime'))
elif itemprop == "ingredients":
self.preparsed_elements.append((tag,'ingredients'))
elif itemprop == "recipeInstructions":
self.preparsed_elements.append((tag,'instructions'))
elif itemprop == "image":
self.imageexcluders.append(Excluder(tag.attrMap["src"]))

if self.preparsed_elements:
self.ignore_unparsed = True
else:
webpage_importer.WebParser.preparse(self)

return IcaSeParser

0 comments on commit 228706e

Please sign in to comment.