-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #715 from MrShark/master
An importer for ica.se (Swedish storechain)
- Loading branch information
Showing
2 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
4 changes: 3 additions & 1 deletion
4
gourmet/plugins/import_export/website_import_plugins/__init__.py
This file contains 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
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, | ||
] |
50 changes: 50 additions & 0 deletions
50
gourmet/plugins/import_export/website_import_plugins/ica_se_plugin.py
This file contains 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
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 | ||
|