mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 14:33:33 -07:00
convert keywords to tags
This commit is contained in:
parent
423e8af8d2
commit
0c6a009f45
1 changed files with 12 additions and 12 deletions
|
@ -7,8 +7,8 @@ from pathlib import Path
|
||||||
from mealie.core.config import app_dirs
|
from mealie.core.config import app_dirs
|
||||||
from mealie.db.database import db
|
from mealie.db.database import db
|
||||||
from mealie.schema.recipe import Recipe
|
from mealie.schema.recipe import Recipe
|
||||||
from mealie.services.scraper.cleaner import Cleaner
|
|
||||||
from mealie.services.image import minify
|
from mealie.services.image import minify
|
||||||
|
from mealie.services.scraper.cleaner import Cleaner
|
||||||
|
|
||||||
|
|
||||||
def process_selection(selection: Path) -> Path:
|
def process_selection(selection: Path) -> Path:
|
||||||
|
@ -24,6 +24,13 @@ def process_selection(selection: Path) -> Path:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def clean_nextcloud_tags(nextcloud_tags: str):
|
||||||
|
if not isinstance(nextcloud_tags, str):
|
||||||
|
return None
|
||||||
|
|
||||||
|
return [x.title().lstrip() for x in nextcloud_tags.split(",") if x != ""]
|
||||||
|
|
||||||
|
|
||||||
def import_recipes(recipe_dir: Path) -> Recipe:
|
def import_recipes(recipe_dir: Path) -> Recipe:
|
||||||
image = False
|
image = False
|
||||||
for file in recipe_dir.glob("full.*"):
|
for file in recipe_dir.glob("full.*"):
|
||||||
|
@ -37,12 +44,8 @@ def import_recipes(recipe_dir: Path) -> Recipe:
|
||||||
|
|
||||||
recipe_data = Cleaner.clean(recipe_dict)
|
recipe_data = Cleaner.clean(recipe_dict)
|
||||||
|
|
||||||
image_name = None
|
image_name = recipe_data["slug"]
|
||||||
if image:
|
recipe_data["tags"] = clean_nextcloud_tags(recipe_data.get("keywords"))
|
||||||
image_name = recipe_data["slug"] + image.suffix
|
|
||||||
recipe_data["image"] = image_name
|
|
||||||
else:
|
|
||||||
recipe_data["image"] = "none"
|
|
||||||
|
|
||||||
recipe = Recipe(**recipe_data)
|
recipe = Recipe(**recipe_data)
|
||||||
|
|
||||||
|
@ -53,10 +56,7 @@ def import_recipes(recipe_dir: Path) -> Recipe:
|
||||||
|
|
||||||
|
|
||||||
def prep():
|
def prep():
|
||||||
try:
|
shutil.rmtree(app_dirs.TEMP_DIR, ignore_errors=True)
|
||||||
shutil.rmtree(app_dirs.TEMP_DIR)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
app_dirs.TEMP_DIR.mkdir(exist_ok=True, parents=True)
|
app_dirs.TEMP_DIR.mkdir(exist_ok=True, parents=True)
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ def migrate(session, selection: str):
|
||||||
db.recipes.create(session, recipe.dict())
|
db.recipes.create(session, recipe.dict())
|
||||||
|
|
||||||
successful_imports.append(recipe.name)
|
successful_imports.append(recipe.name)
|
||||||
except:
|
except Exception:
|
||||||
session.rollback()
|
session.rollback()
|
||||||
logging.error(f"Failed Nextcloud Import: {dir.name}")
|
logging.error(f"Failed Nextcloud Import: {dir.name}")
|
||||||
logging.exception("")
|
logging.exception("")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue