You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.4 KiB
56 lines
1.4 KiB
# ============================================
|
|
# File: bookscraper/app.py
|
|
# ============================================
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv()
|
|
|
|
print(">>> [WEB] Importing celery_app …")
|
|
from celery_app import celery_app # <<< MOET BOVEN TASK IMPORTS
|
|
|
|
from scraper.logger import log_debug
|
|
from flask import Flask, render_template, request
|
|
|
|
# Task imports komen pas na celery_app:
|
|
print(">>> [WEB] Importing tasks …")
|
|
from scraper.tasks.scraping import start_scrape_book
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
@app.route("/", methods=["GET"])
|
|
def index():
|
|
return render_template("index.html")
|
|
|
|
|
|
@app.route("/start", methods=["POST"])
|
|
def start_scraping():
|
|
url = request.form.get("url", "").strip()
|
|
|
|
if not url:
|
|
return render_template("result.html", error="Geen URL opgegeven.")
|
|
|
|
log_debug(f"[WEB] Scrape request for: {url}")
|
|
|
|
# Belangrijk: start_scrape_book komt uit DEZELFDE celery_app nu
|
|
result = start_scrape_book.delay(url)
|
|
|
|
return render_template(
|
|
"result.html",
|
|
message="Scraping gestart.",
|
|
task_id=result.id,
|
|
url=url,
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import os
|
|
|
|
debug = os.getenv("FLASK_DEBUG", "0") == "1"
|
|
host = os.getenv("HOST", "0.0.0.0")
|
|
port = int(os.getenv("PORT", "5000"))
|
|
|
|
log_debug(f"[WEB] Starting Flask server on {host}:{port}, debug={debug}")
|
|
app.run(host=host, port=port, debug=debug)
|