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.
53 lines
1.3 KiB
53 lines
1.3 KiB
# ============================================
|
|
# File: bookscraper/app.py
|
|
# Ensure project directory is on PYTHONPATH
|
|
# ============================================
|
|
|
|
from scraper.logger import log_debug
|
|
from scraper.download_controller import DownloadController
|
|
from flask import Flask, render_template, request
|
|
from dotenv import load_dotenv
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
# Add this directory (bookscraper/) to Python import path
|
|
PROJECT_ROOT = Path(__file__).resolve().parent
|
|
sys.path.insert(0, str(PROJECT_ROOT))
|
|
|
|
# Load .env BEFORE any Celery app is imported
|
|
load_dotenv()
|
|
|
|
|
|
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.")
|
|
|
|
try:
|
|
log_debug(f"[WEB] Start scraping: {url}")
|
|
|
|
ctl = DownloadController(url)
|
|
result = ctl.start()
|
|
|
|
return render_template("result.html", result=result, url=url)
|
|
|
|
except Exception as e:
|
|
log_debug(f"[WEB] ERROR: {e}")
|
|
return render_template("result.html", error=str(e), url=url)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import os
|
|
debug = os.getenv("FLASK_DEBUG", "0") == "1"
|
|
app.run(host="0.0.0.0", port=5000, debug=debug)
|