Spaces:
Running
Running
Create webui.py
Browse files
webui.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, render_template, request
|
2 |
+
import threading
|
3 |
+
import time
|
4 |
+
from main import run_backup
|
5 |
+
|
6 |
+
app = Flask(__name__)
|
7 |
+
|
8 |
+
last_backup_time = "Never"
|
9 |
+
schedule_interval = 0
|
10 |
+
running_thread = None
|
11 |
+
|
12 |
+
|
13 |
+
def schedule_loop():
|
14 |
+
global last_backup_time
|
15 |
+
while True:
|
16 |
+
if schedule_interval > 0:
|
17 |
+
run_backup()
|
18 |
+
last_backup_time = time.ctime()
|
19 |
+
time.sleep(schedule_interval * 60)
|
20 |
+
else:
|
21 |
+
time.sleep(10)
|
22 |
+
|
23 |
+
|
24 |
+
@app.route("/", methods=["GET", "POST"])
|
25 |
+
def index():
|
26 |
+
global schedule_interval, last_backup_time
|
27 |
+
if request.method == "POST":
|
28 |
+
if request.form.get("manual_run"):
|
29 |
+
last_backup_time = time.ctime()
|
30 |
+
result = run_backup()
|
31 |
+
else:
|
32 |
+
schedule_interval = int(request.form.get("interval", 0))
|
33 |
+
result = f"Timer set for every {schedule_interval} min"
|
34 |
+
else:
|
35 |
+
result = ""
|
36 |
+
return render_template("index.html", last_run=last_backup_time, result=result, interval=schedule_interval)
|
37 |
+
|
38 |
+
|
39 |
+
if __name__ == "__main__":
|
40 |
+
running_thread = threading.Thread(target=schedule_loop, daemon=True)
|
41 |
+
running_thread.start()
|
42 |
+
app.run(host="0.0.0.0", port=7860)
|