File size: 808 Bytes
e96a62a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from flask import Flask
from apscheduler.schedulers.background import BackgroundScheduler
import subprocess

app = Flask(__name__)

def run_cli_script():
    """Function to execute the python cli.py command"""
    print("Running cli.py script...")
    try:
        result = subprocess.run(["python", "cli.py"], check=True, capture_output=True, text=True)
        print("Script output:", result.stdout)
    except subprocess.CalledProcessError as e:
        print("Error running script:", e.stderr)

# Configure the scheduler
scheduler = BackgroundScheduler()
scheduler.add_job(run_cli_script, 'interval', hours=3)
scheduler.start()

@app.route('/')
def home():
    return "Scheduler is running! The cli.py script will execute every 3 hours."

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=7860)