refactor/ remove old code

This commit is contained in:
hayden 2021-02-02 20:43:36 -09:00
commit c8e239bd81
4 changed files with 18 additions and 22 deletions

View file

@ -10,6 +10,7 @@ from routes import (
migration_routes,
setting_routes,
static_routes,
theme_routes,
user_routes,
)
from routes.recipe import (
@ -30,10 +31,11 @@ TODO:
- [x] Category Endpoints
- [ ] Endpoint Tests
- [ ] Finish Frontend Category Management
- [ ] Delete Category / Tags
- [x] Delete Category
- [ ] Sort Sidebar A-Z
- [ ] Ingredient Drag-Drop / Reorder
- [ ] Refactor Endpoints
- [x] Ingredient Drag-Drop / Reorder
- [x] Refactor Endpoints
- [ ] Refactor Test Endpoints - Abstract to fixture?
"""
@ -57,13 +59,14 @@ def start_scheduler():
def api_routers():
# Recipes
app.include_router(all_recipe_routes.router)
app.include_router(recipe_crud_routes.router)
app.include_router(category_routes.router)
app.include_router(tag_routes.router)
app.include_router(recipe_crud_routes.router)
# Meal Routes
app.include_router(meal_routes.router)
# Settings Routes
app.include_router(setting_routes.router)
app.include_router(theme_routes.router)
# Backups/Imports Routes
app.include_router(backup_routes.router)
# User Routes

View file

@ -1,4 +1,3 @@
from sqlalchemy.orm import load_only
from sqlalchemy.orm.session import Session
from db.db_base import BaseDocument

View file

@ -1,13 +0,0 @@
from typing import List
from db.database import db
def get_all_categories(session) -> List[str]:
categories = db.categories.get_all_primary_keys(session)
return categories
def get_recipes_by_category(session):
pass

View file

@ -1,6 +1,6 @@
import html
import json
from pathlib import Path
import re
from typing import List, Tuple
import extruct
@ -14,10 +14,15 @@ from w3lib.html import get_base_url
from services.image_services import scrape_image
from services.recipe_services import Recipe
CWD = Path(__file__).parent
TEMP_FILE = DEBUG_DIR.joinpath("last_recipe.json")
def cleanhtml(raw_html):
cleanr = re.compile("<.*?>")
cleantext = re.sub(cleanr, "", raw_html)
return cleantext
def normalize_image_url(image) -> str:
if type(image) == list:
return image[0]
@ -55,7 +60,7 @@ def normalize_instructions(instructions) -> List[dict]:
def normalize_instruction(line) -> str:
l = line.strip()
l = cleanhtml(line.strip())
# Some sites erroneously escape their strings on multiple levels
while not l == (l := html.unescape(l)):
pass
@ -63,7 +68,8 @@ def normalize_instruction(line) -> str:
def normalize_ingredient(ingredients: list) -> str:
return [html.unescape(ing) for ing in ingredients]
return [cleanhtml(html.unescape(ing)) for ing in ingredients]
def normalize_yield(yld) -> str:
@ -82,6 +88,7 @@ def normalize_time(time_entry) -> str:
def normalize_data(recipe_data: dict) -> dict:
recipe_data["totalTime"] = normalize_time(recipe_data.get("totalTime"))
recipe_data["description"] = cleanhtml(recipe_data.get("description"))
recipe_data["prepTime"] = normalize_time(recipe_data.get("prepTime"))
recipe_data["performTime"] = normalize_time(recipe_data.get("performTime"))
recipe_data["recipeYield"] = normalize_yield(recipe_data.get("recipeYield"))