Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An importer for ica.se (Swedish storechain) #715

Merged
merged 1 commit into from
Apr 20, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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