def start_jobs_scheduler(): scheduler = Process( target=_run_forever, args=(run_scheduler, ), ) scheduler.start() return scheduler
def main(): itchat.auto_login(True) scheduler = BlockingScheduler() ask_birthday(scheduler) scheduler.add_job(send_yuandan, 'date', run_date=datetime(2020, 1, 1)) scheduler.add_job(send_chuxi, 'date', run_date=datetime(2020, 1, 24)) scheduler.add_job(send_duanwu, 'date', run_date=datetime(2020, 6, 25)) scheduler.add_job(send_zhongqiu, 'date', run_date=datetime(2020, 10, 1)) scheduler.start()
def get_data(): time.sleep(2) get_supertopic.get_supertopic() # 定时任务,更新情感为中性的微博情感 # @register_job(scheduler, 'interval' , minutes=10, id='分析帖子情感', replace_existing=True) # def get_sentiment(): # extract_blog_sentiment() # 定时任务3,更新超话用户帖子总数、比较消极帖子数、非常消极贴子数及个人情感 # @register_job(scheduler, "cron", hour=20,minute=30,id='计算超话粉丝情感倾向及发帖次数', replace_existing=True) # def get_creator_sentiment(): # cul_creator_sentiment() register_events(scheduler) # 监控任务 scheduler.start() # 调度器开始 except Exception as e: print(e) scheduler.shutdown() pass def extract_blog_sentiment(): '''提取关键情感词''' file_nocut = 'E:\\Sentiment\\sentiment\\dataset\\nocut.txt' jieba.load_userdict(file_nocut) df = pd.read_table("E:\\Sentiment\\sentiment\\dataset\\情感词.txt", sep='\n', header=None, encoding='gbk') df.columns = ['key']
from apscheduler.executors.pool import ThreadPoolExecutor, ProcessPoolExecutor from sched import scheduler import time jobstores = {'default': MemoryJobStore()} executors = { 'default': ThreadPoolExecutor(20), 'processpool': ProcessPoolExecutor(5) } job_defaults = {'coalesce': False, 'max_instances': 1} scheduler = BackgroundScheduler(jobstores=jobstores, executors=executors, job_defaults=job_defaults, timezone=utc) scheduler.start() def sampleFunc(): print("called: %s" % time.ctime()) scheduler.add_job(sampleFunc, 'interval', seconds=10) from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello, World!'