Spaces:
Running
Running
File size: 1,669 Bytes
cdd0183 ec825bc 81b147a ec825bc cdd0183 aebe763 cdd0183 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
from flask import Flask, render_template_string
import subprocess
import threading
import time
import webbrowser
import platform
app = Flask(__name__)
# HTML Template
html_template = """
<!DOCTYPE html>
<html>
<head>
<title>Background Bash & Website Trigger</title>
</head>
<body>
<h2>Flask App is Running!</h2>
<p>Bash command ran at startup.</p>
<p>Website will open every 2 hours for 10 seconds.</p>
</body>
</html>
"""
@app.route("/")
def home():
return render_template_string(html_template)
def run_bash_command():
try:
subprocess.run(["chmod", "+x", "startup"], check=True)
subprocess.run(["bash", "-c", "./startup &"], check=True)
print("✅ 'startup' script launched in background.")
except subprocess.CalledProcessError as e:
print(f"❌ Error running 'startup': {e}")
def open_website_every_2_hours():
url = "https://mega345evolutions-unknowned.hf.space" # replace with your target URL
while True:
print("Opening browser to visit site...")
try:
# Open website in the default browser
webbrowser.open(url)
except Exception as e:
print(f"Error opening browser: {e}")
time.sleep(10) # Keep site open for 10 sec
print("Sleeping for 2 hours...")
time.sleep(2 * 60 * 60) # Sleep for 2 hours
if __name__ == "__main__":
# Start bash command in background
threading.Thread(target=run_bash_command, daemon=True).start()
# Start 2hr website opener thread
threading.Thread(target=open_website_every_2_hours, daemon=True).start()
# Start Flask server
app.run(host="0.0.0.0", port=7860)
|