def index(): # функция регистрации \ авторизации if request.method == "POST": # если что то отправляем global username username = request.form['user_name'] # pas = request.form['password'] # получение данных из полей формы email = request.form['email'] # res = username + ' ' + email + ' ' + pas res_lst = res.split() client = connect(const.conn) users = client['url-checker']['users'] if email == '': # если поле логин найдено в базе if users.find_one({'login': username}) is not None: url_db = users.find_one({"login": username})['urls'] for i in range(len(url_db)): cnt = str(i) url_in_user = url_db[i][0] inter = int(url_db[i][1]) scheduler.add_job(id=cnt, func=job_check, trigger="interval", args=(username, url_in_user), minutes=inter) scheduler.print_jobs() return redirect(url_for('str_index_ok')) else: return "<h1>Вы не зарегистированы</h1>" # return redirect(url_for('user', usr=res_lst)) else: # иначе регистрация def user_add(username, email, pas): # функция добавления пользователей в базу user = {'login': username, 'email': email, 'password': pas, 'urls': [], 'urls_light': []} response = users.insert_one(user) client.close() if base == {} or users.find_one({'email': email}) is None: user_add(res_lst[0], res_lst[1], res_lst[2]) url_db = users.find_one({"login": username})['urls'] for i in range(len(url_db)): url_in_user = url_db[i][0] inter = int(url_db[i][1]) scheduler.add_job(func=job_check, trigger="interval", args=(username, url_in_user), minutes=inter) scheduler.print_jobs() return redirect(url_for('str_index_ok')) else: return "<h1>Такой пользователь уже существует</h1>" # return render_template('/send_urls.html') # return redirect(url_for('user', usr=res_lst)) else: lst_jobs = scheduler.get_jobs() client = connect(const.conn) users = client['url-checker']['users'] cnt = 0 if lst_jobs != []: for i in range(len(base['urls'])): scheduler.remove_job(str(cnt)) cnt += 1 scheduler.print_jobs() return render_template('index.html') else: return render_template('index.html')
def execute(self, ips, delay=None): if delay is not None: delta = timedelta(seconds=delay) run_date = datetime.now() + delta print "tast run at ", run_date args = (self._obj.login_info, ips) scheduler.add_job(unblock_ips_task, 'date', args, run_date=run_date) else: for block_ip in ips: out = self._obj.send_command(self.command % block_ip)
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 ask_birthday(scheduler): global b_name b_name = raw_input("想要向哪位好友发送生日祝福:") month = raw_input("他/她的生日是几月:") day = raw_input("他/她的生日是几日:") year = 2019 now_time = datetime.now() now_hour = now_time.strftime('%H') now_sec = now_time.strftime('%M') now_sec = int(now_sec) + 2 scheduler.add_job(send_birthday, 'date', run_date=datetime(year, int(month), int(day), int(now_hour), now_sec))
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!' app.run(debug=False, host='0.0.0.0')