增加spider脚本,每5小时爬取一次数据

This commit is contained in:
YYL469
2024-07-03 21:55:16 +08:00
parent cfe1fdc882
commit c0686430de
7 changed files with 61 additions and 45 deletions
+18 -1
View File
@@ -1,5 +1,10 @@
from flask import Flask,session,request,redirect,render_template
import re
from apscheduler.schedulers.background import BackgroundScheduler
import subprocess
import os
from pytz import utc
app = Flask(__name__)
app.secret_key = 'this is secret_key you know ?'
@@ -24,5 +29,17 @@ def before_reuqest():
def catch_all(path):
return render_template('404.html')
def run_spider_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])
if __name__ == '__main__':
app.run()
scheduler = BackgroundScheduler(timezone=utc)
scheduler.add_job(run_spider_script, 'interval', hours=5)
scheduler.start()
try:
app.run()
finally:
scheduler.shutdown()