recettetek importer
This commit is contained in:
@ -109,29 +109,37 @@ class Integration:
|
||||
import_zip = ZipFile(f['file'])
|
||||
for z in import_zip.filelist:
|
||||
if self.import_file_name_filter(z):
|
||||
try:
|
||||
recipe = self.get_recipe_from_file(BytesIO(import_zip.read(z.filename)))
|
||||
recipe.keywords.add(self.keyword)
|
||||
il.msg += f'{recipe.pk} - {recipe.name} \n'
|
||||
self.handle_duplicates(recipe, import_duplicates)
|
||||
|
||||
except Exception as e:
|
||||
il.msg += f'-------------------- \n ERROR \n{e}\n--------------------\n'
|
||||
import_zip.close()
|
||||
elif '.json' in f['name'] or '.txt' in f['name']:
|
||||
data_list = self.split_recipe_file(f['file'])
|
||||
for d in data_list:
|
||||
try:
|
||||
recipe = self.get_recipe_from_file(d)
|
||||
recipe.keywords.add(self.keyword)
|
||||
il.msg += f'{recipe.pk} - {recipe.name} \n'
|
||||
self.handle_duplicates(recipe, import_duplicates)
|
||||
except Exception as e:
|
||||
il.msg += f'-------------------- \n ERROR \n{e}\n--------------------\n'
|
||||
elif '.rtk' in f['name']:
|
||||
import_zip = ZipFile(f['file'])
|
||||
for z in import_zip.filelist:
|
||||
if self.import_file_name_filter(z):
|
||||
data_list = self.split_recipe_file(import_zip.read(z.filename).decode('utf-8'))
|
||||
for d in data_list:
|
||||
try:
|
||||
recipe = self.get_recipe_from_file(d)
|
||||
recipe.keywords.add(self.keyword)
|
||||
il.msg += f'{recipe.pk} - {recipe.name} \n'
|
||||
self.handle_duplicates(recipe, import_duplicates)
|
||||
except Exception as e:
|
||||
il.msg += f'-------------------- \n ERROR \n{e}\n--------------------\n'
|
||||
import_zip.close()
|
||||
else:
|
||||
recipe = self.get_recipe_from_file(f['file'])
|
||||
|
@ -16,7 +16,7 @@ class RecetteTek(Integration):
|
||||
|
||||
def import_file_name_filter(self, zip_info_object):
|
||||
print("testing", zip_info_object.filename)
|
||||
return re.match(r'^recipes_0.json$', zip_info_object.filename)
|
||||
return re.match(r'^recipes_0.json$', zip_info_object.filename) or re.match(r'^recipes.json$', zip_info_object.filename)
|
||||
|
||||
def split_recipe_file(self, file):
|
||||
|
||||
@ -40,7 +40,11 @@ class RecetteTek(Integration):
|
||||
except Exception as e:
|
||||
print(recipe.name, ': failed to parse recipe description ', str(e))
|
||||
|
||||
step = Step.objects.create(instruction=file['instructions'])
|
||||
instructions = file['instructions']
|
||||
if not instructions:
|
||||
instructions = ''
|
||||
|
||||
step = Step.objects.create(instruction=instructions)
|
||||
|
||||
# Append the original import url to the step (if it exists)
|
||||
try:
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -101,6 +101,9 @@
|
||||
<label class="btn btn-outline-info btn-sm" @click="recipe_app='REZKONV'">
|
||||
<input type="radio" autocomplete="off"> Rezkonv
|
||||
</label>
|
||||
<label class="btn btn-outline-info btn-sm" @click="recipe_app='RECETTETEK'">
|
||||
<input type="radio" autocomplete="off"> RecetteTek
|
||||
</label>
|
||||
|
||||
</div>
|
||||
<b-form-file
|
||||
|
Reference in New Issue
Block a user