shit and i'm lazy

This commit is contained in:
Jurn Wubben 2025-06-22 19:42:20 +02:00
parent 1f269afce5
commit 5dafe72895
14 changed files with 367 additions and 109 deletions

View file

@ -1,4 +1,5 @@
from flask import url_for, redirect, render_template, abort
import json
from flask import request, url_for, redirect, render_template, abort
from app import app, db
from app.forms import (
NewWishlist,
@ -12,6 +13,9 @@ from app.forms import (
)
from app.models import Wishlist, Item
from uuid import UUID, uuid4 as uuid
from json import JSONEncoder
from app.scrapers import scrapeSite
@app.route("/")
@ -22,16 +26,25 @@ def index():
@app.route("/new", methods=["GET", "POST"])
def new():
form = NewWishlist()
if form.validate_on_submit():
wishlist = Wishlist(str(form.title.data), str(form.description.data))
db.session.add(wishlist)
db.session.commit()
return redirect(url_for("view", id=wishlist.viewId))
return redirect(
url_for("postNew", viewId=wishlist.viewId, editId=wishlist.editId)
)
return render_template("new.html", form=form)
@app.route("/post_new/<viewId>/<editId>")
def postNew(viewId: str, editId: str):
return render_template("post_new.html", viewId=viewId, editId=editId)
@app.route("/edit/<id>", methods=["GET", "POST"])
def edit(id: str):
wishlist: Wishlist = db.one_or_404(
@ -74,7 +87,7 @@ def edit(id: str):
item = Item(
str(
f.title.data,
f.it_new_title.data,
),
str(
f.description.data,
@ -118,6 +131,7 @@ def view(id: str):
db.select(Wishlist).filter_by(viewId=UUID(id)),
description="Failed to get wishlist. Are you sure this is the correct url?",
)
checkform = CheckItem()
checkform.num
if checkform.validate_on_submit():
@ -131,3 +145,16 @@ def view(id: str):
return redirect(url_for("view", id=id))
return render_template("view.html", wishlist=wishlist, form=checkform)
@app.route("/scrape", methods=["GET"])
def scrape():
url = request.args.get("url")
if url is None:
abort(400)
scraped = scrapeSite(url)
if scraped is None:
abort(404)
return json.dumps(scraped.__dict__)