Showing
1 changed file
with
19 additions
and
3 deletions
| @@ -29,14 +29,30 @@ def before_reuqest(): | @@ -29,14 +29,30 @@ def before_reuqest(): | ||
| 29 | def catch_all(path): | 29 | def catch_all(path): |
| 30 | return render_template('404.html') | 30 | return render_template('404.html') |
| 31 | 31 | ||
| 32 | -def run_spider_script(): | 32 | +def run_script(): |
| 33 | current_dir = os.path.dirname(os.path.abspath(__file__)) | 33 | current_dir = os.path.dirname(os.path.abspath(__file__)) |
| 34 | spider_script = os.path.join(current_dir, 'spider', 'main.py') | 34 | spider_script = os.path.join(current_dir, 'spider', 'main.py') |
| 35 | - subprocess.run(['python', spider_script]) | 35 | + cutComments_script = os.path.join(current_dir, 'utils', 'cutComments.py') |
| 36 | + cipingTotal_script = os.path.join(current_dir, 'utils', 'cipingTotal.py') | ||
| 37 | + | ||
| 38 | + scripts = [ | ||
| 39 | + ("Spider Script", spider_script), | ||
| 40 | + ("Cut Comments Script", cutComments_script), | ||
| 41 | + ("Ciping Total Script", cipingTotal_script) | ||
| 42 | + ] | ||
| 43 | + | ||
| 44 | + for script_name, script_path in scripts: | ||
| 45 | + try: | ||
| 46 | + print(f"Running {script_name}...") | ||
| 47 | + result = subprocess.run(['python', script_path], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
| 48 | + print(f"{script_name} finished successfully. Output:\n{result.stdout.decode()}") | ||
| 49 | + except subprocess.CalledProcessError as e: | ||
| 50 | + print(f"An error occurred while running {script_name}: {e.stderr.decode()}") | ||
| 51 | + | ||
| 36 | 52 | ||
| 37 | if __name__ == '__main__': | 53 | if __name__ == '__main__': |
| 38 | scheduler = BackgroundScheduler(timezone=utc) | 54 | scheduler = BackgroundScheduler(timezone=utc) |
| 39 | - scheduler.add_job(run_spider_script, 'interval', hours=5) | 55 | + scheduler.add_job(run_script, 'interval', hours=5) |
| 40 | scheduler.start() | 56 | scheduler.start() |
| 41 | 57 | ||
| 42 | try: | 58 | try: |
-
Please register or login to post a comment