Rename plurals
This commit is contained in:
parent
ebab422869
commit
9e03f707dc
12 changed files with 28 additions and 28 deletions
6
db.py
6
db.py
|
|
@ -4,14 +4,14 @@ async def connect() -> aiosqlite.Connection:
|
||||||
return await aiosqlite.connect('your_database.db')
|
return await aiosqlite.connect('your_database.db')
|
||||||
|
|
||||||
async def create():
|
async def create():
|
||||||
import product.db as product_db
|
import products.db as product_db
|
||||||
conn = await connect()
|
conn = await connect()
|
||||||
await product_db.create(conn)
|
await product_db.create(conn)
|
||||||
|
|
||||||
import recipe.db as recipe_db
|
import recipes.db as recipe_db
|
||||||
await recipe_db.create(conn)
|
await recipe_db.create(conn)
|
||||||
|
|
||||||
import person.db as person_db
|
import persons.db as person_db
|
||||||
await person_db.create(conn)
|
await person_db.create(conn)
|
||||||
|
|
||||||
import meals.db as meals_db
|
import meals.db as meals_db
|
||||||
|
|
|
||||||
32
main.py
32
main.py
|
|
@ -1,5 +1,5 @@
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import product, recipe, db, meals
|
import products, recipes, db, meals
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
@ -28,8 +28,8 @@ async def get_db():
|
||||||
await sql_db.close()
|
await sql_db.close()
|
||||||
|
|
||||||
@app.get("/recipes/parse")
|
@app.get("/recipes/parse")
|
||||||
async def parse_recipe_handler(url: str, conn: sqlite3.Connection = Depends(get_db)) -> recipe.Recipe:
|
async def parse_recipe_handler(url: str, conn: sqlite3.Connection = Depends(get_db)) -> recipes.Recipe:
|
||||||
parsed = await recipe.parse_recipe(conn, url)
|
parsed = await recipes.parse_recipe(conn, url)
|
||||||
if not parsed:
|
if not parsed:
|
||||||
return JSONResponse(status_code=400, content={'message': 'Recipe not found'})
|
return JSONResponse(status_code=400, content={'message': 'Recipe not found'})
|
||||||
return parsed
|
return parsed
|
||||||
|
|
@ -39,9 +39,9 @@ async def parse_ingredients(lines: Annotated[
|
||||||
List[str],
|
List[str],
|
||||||
Query(alias="ingredients",
|
Query(alias="ingredients",
|
||||||
title="Array of ingredients to parse")],
|
title="Array of ingredients to parse")],
|
||||||
conn: sqlite3.Connection = Depends(get_db)) -> List[recipe.Ingredient]:
|
conn: sqlite3.Connection = Depends(get_db)) -> List[recipes.Ingredient]:
|
||||||
ingredients = recipe.parse_ingredient_from_nlp(lines)
|
ingredients = recipes.parse_ingredient_from_nlp(lines)
|
||||||
recipe.match_existing_products(conn, ingredients)
|
recipes.match_existing_products(conn, ingredients)
|
||||||
return ingredients
|
return ingredients
|
||||||
|
|
||||||
class ProductUrl(BaseModel):
|
class ProductUrl(BaseModel):
|
||||||
|
|
@ -49,23 +49,23 @@ class ProductUrl(BaseModel):
|
||||||
tags: List[str] = []
|
tags: List[str] = []
|
||||||
|
|
||||||
@app.post("/products/")
|
@app.post("/products/")
|
||||||
async def create_product(url: ProductUrl, conn: sqlite3.Connection = Depends(get_db)) -> product.Product:
|
async def create_product(url: ProductUrl, conn: sqlite3.Connection = Depends(get_db)) -> products.Product:
|
||||||
return await product.get_or_create(conn, url.url, url.tags)
|
return await products.get_or_create(conn, url.url, url.tags)
|
||||||
|
|
||||||
async def load_full_recipe(conn: sqlite3.Connection, id: int) -> recipe.Recipe:
|
async def load_full_recipe(conn: sqlite3.Connection, id: int) -> recipes.Recipe:
|
||||||
r = await recipe.find_recipe_by_id(conn, id)
|
r = await recipes.find_recipe_by_id(conn, id)
|
||||||
if not r:
|
if not r:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
r.ingredients = []
|
r.ingredients = []
|
||||||
async for ingredient in recipe.find_ingredients_by_recipe_id(conn, id):
|
async for ingredient in recipes.find_ingredients_by_recipe_id(conn, id):
|
||||||
ingredient.product = await product.find_product_by_id(conn, ingredient.product_id)
|
ingredient.product = await products.find_product_by_id(conn, ingredient.product_id)
|
||||||
r.ingredients.append(ingredient)
|
r.ingredients.append(ingredient)
|
||||||
|
|
||||||
return r
|
return r
|
||||||
|
|
||||||
@app.get("/recipes/{recipe_id}")
|
@app.get("/recipes/{recipe_id}")
|
||||||
async def get_recipe(recipe_id: int, conn: sqlite3.Connection = Depends(get_db)) -> recipe.Recipe:
|
async def get_recipe(recipe_id: int, conn: sqlite3.Connection = Depends(get_db)) -> recipes.Recipe:
|
||||||
r = await load_full_recipe(conn, recipe_id)
|
r = await load_full_recipe(conn, recipe_id)
|
||||||
if not r:
|
if not r:
|
||||||
return JSONResponse(status_code=404, content={'message': 'Recipe not found'})
|
return JSONResponse(status_code=404, content={'message': 'Recipe not found'})
|
||||||
|
|
@ -73,7 +73,7 @@ async def get_recipe(recipe_id: int, conn: sqlite3.Connection = Depends(get_db))
|
||||||
return r
|
return r
|
||||||
|
|
||||||
@app.post('/recipes/')
|
@app.post('/recipes/')
|
||||||
async def create_recipe(item: recipe.Recipe, conn: sqlite3.Connection = Depends(get_db)) -> recipe.Recipe:
|
async def create_recipe(item: recipes.Recipe, conn: sqlite3.Connection = Depends(get_db)) -> recipes.Recipe:
|
||||||
if not item.ingredients:
|
if not item.ingredients:
|
||||||
return JSONResponse(status_code=400, content={'message': 'Recipe must have at least one ingredient'})
|
return JSONResponse(status_code=400, content={'message': 'Recipe must have at least one ingredient'})
|
||||||
|
|
||||||
|
|
@ -81,11 +81,11 @@ async def create_recipe(item: recipe.Recipe, conn: sqlite3.Connection = Depends(
|
||||||
if not ingredient.product:
|
if not ingredient.product:
|
||||||
return JSONResponse(status_code=400, content={'message': 'Ingredient must have a product'})
|
return JSONResponse(status_code=400, content={'message': 'Ingredient must have a product'})
|
||||||
|
|
||||||
await recipe.insert_recipe(conn, item)
|
await recipes.insert_recipe(conn, item)
|
||||||
for ingredient in item.ingredients:
|
for ingredient in item.ingredients:
|
||||||
ingredient.recipe_id = item.id
|
ingredient.recipe_id = item.id
|
||||||
ingredient.product_id = ingredient.product.id
|
ingredient.product_id = ingredient.product.id
|
||||||
await recipe.insert_ingredient(conn, ingredient)
|
await recipes.insert_ingredient(conn, ingredient)
|
||||||
await conn.commit()
|
await conn.commit()
|
||||||
|
|
||||||
return item
|
return item
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
from typing import List, ClassVar
|
from typing import List, ClassVar
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from person import Person
|
from persons import Person
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
from person.db import Person
|
|
||||||
1
persons/__init__.py
Normal file
1
persons/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
from persons.db import Person
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from product.db import Product, find_product_by_tag, find_product_by_product_id, insert_product, get_tags, add_tag, find_product_by_id
|
from products.db import Product, find_product_by_tag, find_product_by_product_id, insert_product, get_tags, add_tag, find_product_by_id
|
||||||
from product.scraping import scrape_woolies_data, get_product_id, get_product_details_url
|
from products.scraping import scrape_woolies_data, get_product_id, get_product_details_url
|
||||||
|
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
from product import Product
|
from products import Product
|
||||||
from recipe.db import Recipe, Ingredient, insert_recipe, insert_ingredient, find_recipe_by_id, find_ingredients_by_recipe_id
|
from recipes.db import Recipe, Ingredient, insert_recipe, insert_ingredient, find_recipe_by_id, find_ingredients_by_recipe_id
|
||||||
from recipe.scraping import scrape_recipe
|
from recipes.scraping import scrape_recipe
|
||||||
|
|
||||||
from ingredient_parser import parse_multiple_ingredients
|
from ingredient_parser import parse_multiple_ingredients
|
||||||
from typing import List
|
from typing import List
|
||||||
from product import find_product_by_tag
|
from products import find_product_by_tag
|
||||||
|
|
||||||
import json, units
|
import json, units
|
||||||
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import aiosqlite
|
import aiosqlite
|
||||||
|
|
||||||
from product import Product
|
from products import Product
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from typing import List, ClassVar, Optional
|
from typing import List, ClassVar, Optional
|
||||||
Loading…
Reference in a new issue