-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathupdate.py
More file actions
37 lines (29 loc) · 1.1 KB
/
update.py
File metadata and controls
37 lines (29 loc) · 1.1 KB
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
from flask import Flask, jsonify
from daemonize import Daemonize
import os
import time
app = Flask(__name__)
# Dosya yolu ve script
timestamp_file = "/data/data/com.termux/files/home/last_check_timestamp.txt"
script_to_run = "/data/data/com.termux/files/home/update_script.py"
pid_file = "/data/data/com.termux/files/home/flask_daemon.pid"
@app.route('/')
def index():
current_time = time.time()
if os.path.exists(timestamp_file):
with open(timestamp_file, 'r') as file:
last_check_time = float(file.read().strip())
else:
last_check_time = 0
if (current_time - last_check_time) >= 172800: # 2 gün = 172800 saniye
os.system(f"python3 {script_to_run}")
with open(timestamp_file, 'w') as file:
file.write(str(current_time))
return jsonify({'status': 'Script executed'})
else:
return jsonify({'status': 'No need to execute script'})
def main():
app.run(host='0.0.0.0', port=5000)
# Daemonize ile Flask uygulamasını arka planda çalıştır
daemon = Daemonize(app="flask_daemon", pid=pid_file, action=main)
daemon.start()