add paprika import image support
This commit is contained in:
parent
5d1d6d4248
commit
58c5b2c301
@ -3,18 +3,14 @@ import re
|
|||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
|
|
||||||
from rest_framework.renderers import JSONRenderer
|
|
||||||
|
|
||||||
from cookbook.helper.ingredient_parser import parse
|
from cookbook.helper.ingredient_parser import parse
|
||||||
from cookbook.integration.integration import Integration
|
from cookbook.integration.integration import Integration
|
||||||
from cookbook.models import Recipe, Step, Food, Unit, Ingredient
|
from cookbook.models import Recipe, Step, Food, Unit, Ingredient
|
||||||
from cookbook.serializer import RecipeExportSerializer
|
|
||||||
|
|
||||||
|
|
||||||
class Mealie(Integration):
|
class Mealie(Integration):
|
||||||
|
|
||||||
def import_file_name_filter(self, zip_info_object):
|
def import_file_name_filter(self, zip_info_object):
|
||||||
print("testing", zip_info_object.filename)
|
|
||||||
return re.match(r'^recipes/([A-Za-z\d-])+.json$', zip_info_object.filename)
|
return re.match(r'^recipes/([A-Za-z\d-])+.json$', zip_info_object.filename)
|
||||||
|
|
||||||
def get_recipe_from_file(self, file):
|
def get_recipe_from_file(self, file):
|
||||||
|
@ -3,18 +3,14 @@ import re
|
|||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
|
|
||||||
from rest_framework.renderers import JSONRenderer
|
|
||||||
|
|
||||||
from cookbook.helper.ingredient_parser import parse
|
from cookbook.helper.ingredient_parser import parse
|
||||||
from cookbook.integration.integration import Integration
|
from cookbook.integration.integration import Integration
|
||||||
from cookbook.models import Recipe, Step, Food, Unit, Ingredient
|
from cookbook.models import Recipe, Step, Food, Unit, Ingredient
|
||||||
from cookbook.serializer import RecipeExportSerializer
|
|
||||||
|
|
||||||
|
|
||||||
class NextcloudCookbook(Integration):
|
class NextcloudCookbook(Integration):
|
||||||
|
|
||||||
def import_file_name_filter(self, zip_info_object):
|
def import_file_name_filter(self, zip_info_object):
|
||||||
print("testing", zip_info_object.filename)
|
|
||||||
return re.match(r'^Recipes/([A-Za-z\d\s])+/recipe.json$', zip_info_object.filename)
|
return re.match(r'^Recipes/([A-Za-z\d\s])+/recipe.json$', zip_info_object.filename)
|
||||||
|
|
||||||
def get_recipe_from_file(self, file):
|
def get_recipe_from_file(self, file):
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
import json
|
import json
|
||||||
|
import re
|
||||||
|
from io import BytesIO
|
||||||
|
from zipfile import ZipFile
|
||||||
|
|
||||||
import microdata
|
import microdata
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
from cookbook.helper.recipe_url_import import find_recipe_json
|
from cookbook.helper.recipe_url_import import find_recipe_json
|
||||||
from cookbook.integration.integration import Integration
|
from cookbook.integration.integration import Integration
|
||||||
@ -9,6 +13,10 @@ from cookbook.models import Recipe, Step, Food, Ingredient, Unit
|
|||||||
|
|
||||||
class Paprika(Integration):
|
class Paprika(Integration):
|
||||||
|
|
||||||
|
def import_file_name_filter(self, zip_info_object):
|
||||||
|
print("testing", zip_info_object.filename)
|
||||||
|
return re.match(r'^Recipes/([A-Za-z\s])+.html$', zip_info_object.filename)
|
||||||
|
|
||||||
def get_file_from_recipe(self, recipe):
|
def get_file_from_recipe(self, recipe):
|
||||||
raise NotImplementedError('Method not implemented in storage integration')
|
raise NotImplementedError('Method not implemented in storage integration')
|
||||||
|
|
||||||
@ -33,4 +41,16 @@ class Paprika(Integration):
|
|||||||
))
|
))
|
||||||
|
|
||||||
recipe.steps.add(step)
|
recipe.steps.add(step)
|
||||||
|
|
||||||
|
soup = BeautifulSoup(html_text, "html.parser")
|
||||||
|
image = soup.find('img')
|
||||||
|
image_name = image.attrs['src'].strip().replace('Images/', '')
|
||||||
|
|
||||||
|
for f in self.files:
|
||||||
|
if '.zip' in f.name:
|
||||||
|
import_zip = ZipFile(f.file)
|
||||||
|
for z in import_zip.filelist:
|
||||||
|
if re.match(f'^Recipes/Images/{image_name}$', z.filename):
|
||||||
|
self.import_recipe_image(recipe, BytesIO(import_zip.read(z.filename)))
|
||||||
|
|
||||||
return recipe
|
return recipe
|
||||||
|
@ -61,7 +61,19 @@ To migrate your recipes
|
|||||||
Paprika can create two types of export. The first is a proprietary `.paprikarecipes` file in some kind of binarized format.
|
Paprika can create two types of export. The first is a proprietary `.paprikarecipes` file in some kind of binarized format.
|
||||||
The second one is HTML files containing at least a bit of microdata.
|
The second one is HTML files containing at least a bit of microdata.
|
||||||
|
|
||||||
If you want to import your Paprika recipes create a html export. Then import the individual recipes HTML files.
|
If you want to import your Paprika recipes follow these steps
|
||||||
Due to the lack of structure not all fields can be imported.
|
|
||||||
Even tough images are present in the export they cannot be imported atm. This is technically possible and might be
|
1. create a html export
|
||||||
added in the future.
|
2. Create a `.zip` file from the `Recipes` folder (next to the `index.html`) the structure should look like this
|
||||||
|
```
|
||||||
|
Recipes.zip/
|
||||||
|
└── Recipes/
|
||||||
|
├── recipe one.html
|
||||||
|
├── recipe two.thml
|
||||||
|
└── Images/
|
||||||
|
├── 5D5E09CD-8F88-4F61-8121-0727DD3E0E89/
|
||||||
|
│ └── 5D5E09CD-8F88-4F61-8121-0727DD3E0E89.jpg
|
||||||
|
└── 7CEE2AC6-DF60-4464-9B61-4F5E347EB90C/
|
||||||
|
└── 7CEE2AC6-DF60-4464-9B61-4F5E347EB90C.jpg
|
||||||
|
```
|
||||||
|
3. Upload the zip file in the import module and import it
|
Loading…
Reference in New Issue
Block a user