40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
import logging
|
|
from flask import Flask, render_template, Response, request
|
|
from main import yoink, process
|
|
|
|
app = Flask(__name__, static_folder="website/static", template_folder="website")
|
|
|
|
# Configure logging
|
|
logging.basicConfig(
|
|
filename='./logs/app.log',
|
|
level=logging.INFO,
|
|
format='%(asctime)s %(levelname)s: %(message)s',
|
|
datefmt='%Y-%m-%d %H:%M:%S'
|
|
)
|
|
|
|
@app.route('/')
|
|
def home():
|
|
logging.info("Home page accessed.")
|
|
return render_template('index.html')
|
|
|
|
@app.route('/process_url', methods=['POST'])
|
|
def process_url():
|
|
global most_recent_thread
|
|
url = request.form['url']
|
|
logging.info(f"Received URL for processing: {url}")
|
|
success, msg, status_code, most_recent_thread = process(url)
|
|
if success:
|
|
logging.info("Processing started successfully.")
|
|
return Response("Processing started. Check /stream_output for updates.", content_type='text/plain', status=200)
|
|
else:
|
|
logging.error(f"Processing failed: {msg}")
|
|
return Response(msg, content_type='text/plain', status=status_code)
|
|
|
|
@app.route('/stream_output')
|
|
def stream_output():
|
|
logging.info("Streaming output requested.")
|
|
return Response(yoink(most_recent_thread), content_type='text/plain', status=200)
|
|
|
|
if __name__ == '__main__':
|
|
logging.info("Starting Flask application.")
|
|
app.run(debug=True) |