python 定时任务发送
from apscheduler.schedulers.blocking import BlockingScheduler from datetime import datetime,timedelta,date import requests import os def check_related_phone(): lastday_count = """ **** """ total = conn_alg.search(lastday_count) alg_pids = int(total[0]['total']) if len(total) > 0 else 0 if alg_pids == 0: data = { "msgtype": "markdown", "markdown": { "content": """@所有人,<font color=\"info\">中文\n快中文</font>""", } } r = requests.post(url, headers=headers, json=data) url = "https://*******************" headers = {"Content-Type": "text/plain"} scheduler = BlockingScheduler() scheduler.add_job(check_zjk_project_id, 'cron', day_of_week='0-4',hour='*/2') scheduler.add_job(check_related_phone, 'cron', hour=10, minute=0) print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C')) try: scheduler.start() except (KeyboardInterrupt, SystemExit): pass