mega345evolutions commited on
Commit
cdd0183
·
verified ·
1 Parent(s): 9cca6dc

Create app.py

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