From e6008ed0fbf7ed2dc17b73ba6e3ad463a0d2d65d Mon Sep 17 00:00:00 2001 From: redhongx <1144981128@qq.com> Date: Thu, 4 Jul 2024 14:03:26 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90app.py=E3=80=91=E8=B0=83=E5=BA=A6?= =?UTF-8?q?=E5=99=A8=E8=B0=83=E5=BA=A6cutComments.py=E5=92=8CcipingTotal.p?= =?UTF-8?q?y?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index 3c1c876..f54b7a2 100644 --- a/app.py +++ b/app.py @@ -29,14 +29,30 @@ def before_reuqest(): def catch_all(path): return render_template('404.html') -def run_spider_script(): +def run_script(): current_dir = os.path.dirname(os.path.abspath(__file__)) spider_script = os.path.join(current_dir, 'spider', 'main.py') - subprocess.run(['python', spider_script]) + cutComments_script = os.path.join(current_dir, 'utils', 'cutComments.py') + cipingTotal_script = os.path.join(current_dir, 'utils', 'cipingTotal.py') + + scripts = [ + ("Spider Script", spider_script), + ("Cut Comments Script", cutComments_script), + ("Ciping Total Script", cipingTotal_script) + ] + + for script_name, script_path in scripts: + try: + print(f"Running {script_name}...") + result = subprocess.run(['python', script_path], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + print(f"{script_name} finished successfully. Output:\n{result.stdout.decode()}") + except subprocess.CalledProcessError as e: + print(f"An error occurred while running {script_name}: {e.stderr.decode()}") + if __name__ == '__main__': scheduler = BackgroundScheduler(timezone=utc) - scheduler.add_job(run_spider_script, 'interval', hours=5) + scheduler.add_job(run_script, 'interval', hours=5) scheduler.start() try: