from quart import Quart, request, render_template, redirect
|
|
import ebay
|
|
|
|
app = Quart(__name__)
|
|
|
|
@app.route("/", methods=["GET", "POST"])
|
|
async def main():
|
|
locale = request.args.get('locale')
|
|
if not locale:
|
|
locale = "com"
|
|
|
|
|
|
if request.method == "POST":
|
|
query = (await request.form)["search"]
|
|
# NOTE: technically unnecessary redirect for the sake of having the search string shown inside the url
|
|
return redirect("/?q=" + query + "&locale=" + locale)
|
|
else:
|
|
query = request.args.get("q")
|
|
|
|
|
|
if query != None:
|
|
results = ebay.search(query, 1, locale)
|
|
return await render_template("results.html", results=results, query=query)
|
|
|
|
return await render_template("index.html")
|
|
|
|
|
|
@app.route("/itm/<string:identifier>/<string:rest>/")
|
|
async def article(identifier, rest):
|
|
locale = request.args.get('locale')
|
|
if not locale:
|
|
locale = "com"
|
|
|
|
return await render_template(
|
|
"article.html", article=ebay.article(identifier + "/" + rest, locale)
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app.run()
|