56 lines
2.2 KiB
Python
56 lines
2.2 KiB
Python
from flask import Flask, render_template_string, request, redirect, url_for
|
|
from selenium import webdriver
|
|
from selenium.webdriver.chrome.options import Options
|
|
import threading
|
|
|
|
app = Flask(__name__)
|
|
|
|
# Start browser in kiosk mode at server startup
|
|
chrome_options = Options()
|
|
chrome_options.add_argument("--kiosk") # Fullscreen, good for TV
|
|
chrome_options.add_argument("--disable-blink-features=AutomationControlled")
|
|
# chrome_options.add_experimental_option("detach", True) # Prevents Chrome from closing when script ends
|
|
|
|
# Store the browser globally
|
|
browser = webdriver.Chrome(options=chrome_options)
|
|
browser.get("about:blank")
|
|
|
|
@app.route("/", methods=["GET", "POST"])
|
|
def index():
|
|
if request.method == "POST":
|
|
url = request.form.get("url")
|
|
if url:
|
|
# Ensure URL has a protocol
|
|
if not url.startswith(("http://", "https://")):
|
|
url = "http://" + url
|
|
# Use Selenium to navigate current tab to new URL
|
|
browser.get(url)
|
|
return redirect(url_for("index"))
|
|
|
|
# Render a minimalist HTML page
|
|
return render_template_string("""
|
|
<html>
|
|
<head>
|
|
<title>KPR Media Naranja</title>
|
|
<style>
|
|
body { font-family: sans-serif; margin: 2em; background: #222; color: #fff; }
|
|
form { display: flex; gap: 1em; }
|
|
input[type=text] { flex: 1; padding: 0.5em; font-size: 1.2em; border-radius: 8px; border: none;}
|
|
button { padding: 0.5em 1em; font-size: 1.2em; border-radius: 8px; background: #4caf50; color: #fff; border: none; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>Alimenta una URL</h1>
|
|
<form method="post">
|
|
<input type="text" name="url" placeholder="Pon la URL justo aqui" autofocus>
|
|
<button type="submit">Send</button>
|
|
</form>
|
|
<!-- <p style="opacity:0.5;font-size:smaller;">Tip: Only one tab is open at a time. The last submitted URL takes over the screen.</p> --!>
|
|
</body>
|
|
</html>
|
|
""")
|
|
|
|
if __name__ == "__main__":
|
|
# Run Flask in a thread so Selenium's browser stays alive
|
|
threading.Thread(target=lambda: app.run(host="0.0.0.0", port=80, debug=False, use_reloader=False)).start()
|