def register(): form = RegistrationForm() if form.validate_on_submit(): student = Student( index=form.index.data, name=form.name.data, surname=form.surname.data, faculty=form.faculty.data, major=form.major.data, year=form.year.data, group=form.group.data, ) user = User(username=form.username.data, email=form.email.data, password=form.password.data, confirmed=False, admin=False) db.session.add(user) db.session.add(student) db.session.commit() token = generate_confirmation_token(user.email) confirm_url = url_for('confirm_email', token=token, _external=True) html = render_template('user/activate.html', confirm_url=confirm_url) subject = "Please confirm your email" send_email(user.email, subject, html) login_user(user) flash('A confirmation email has been sent via email.', 'success') return redirect('/unconfirmed') return render_template('user/register.html', form=form)
def mcmc_run(self, pvals, ndim=23, nwalkers=50, nsteps=10000, f_name='None'): """ ndim = 23 # number of parameters in the model nwalkers = 50 # number of MCMC walkers nburn = 1000 # "burn-in" period to let chains stabilize nsteps = 10000 # number of MCMC steps to take """ sampler = emcee.EnsembleSampler(nwalkers, ndim, self.log_posterior) sampler.run_mcmc(pvals, nsteps) if f_name != 'None': my_email.send_email(sampler, f_name) return sampler
def find_min_tnc_cvt(self, pvals, f_name='None', email=0, bnds='strict', dispp=5, maxits=2000, mini=0, f_tol=1e-4): """ Function which minimizes 4DVAR cost fn. Takes an initial state (pvals). :param pvals: parameter values for which to optimize as recorded array witht parameter names in dtype :param bnds: bounds for assimilation as tuple :param dispp: info to display in assimilation :param maxits: maximum number of iterations to perform before stopping optimization :param mini: estimated minimum of cost fn :param f_tol: difference in cost fn value tolerance :return: optimsier output, xa value, full xa including unoptimized parameters """ p = np.array(pvals.tolist()[0], dtype=np.float) self.xb = p self.names = pvals.dtype.names if bnds == 'strict': opt_bnds = self.opt_bnds(self.dC.bnds_tst) bnds = self.zvalbnds(opt_bnds) else: bnds = bnds zvals = self.pvals2zvals(p) find_min = spop.fmin_tnc(self.cost_cvt, zvals, fprime=self.gradcost2_cvt, bounds=bnds, disp=dispp, fmin=mini, maxfun=maxits, ftol=f_tol) xa = self.zvals2pvals(find_min[0]) xa_full = np.array(self.create_ordered_lst(xa)) if f_name != 'None': if email == 0: self.pickle_exp(pvals, find_min, xa, f_name) elif email == 1: exp = self.exp_dict(pvals, find_min, xa) my_email.send_email(exp, f_name) return find_min, xa, xa_full
def register(): if request.method == 'GET': return render_template('register.html') user = User(request.form['email'], request.form['password']) role = Role.query.filter(Role.name == 'user') role = role.first() user_datastore.add_role_to_user(user, role) db.session.add(user) db.session.commit() token = generate_confirmation_token(user.email) confirm_url = url_for('confirm_email', token=token, _external=True) html = render_template('act.html', confirm_url=confirm_url) subject = "Please confirm your email" send_email(request.form['email'], subject, html) #login_user(user) flash('A confirmation email has been sent via email.', 'success') confirm_email(token) return redirect(url_for('unconfirmed'))
def findminglob(self, pvals, f_name='None', email=0, meth='TNC', bnds='strict', it=300, stpsize=0.5, temp=1., displ=True, maxits=3000): """Function which minimizes 4DVAR cost fn. Takes an initial state (pvals), an obs dictionary, an obs error dictionary, a dataClass and a start and finish time step. """ p = np.array(pvals.tolist()[0], dtype=np.float) self.xb = p self.names = pvals.dtype.names if bnds == 'strict': bnds = self.opt_bnds(self.dC.bnds) else: bnds = bnds findmin = spop.basinhopping(self.cost, p, niter=it, minimizer_kwargs={ 'method': meth, 'bounds': bnds, 'jac': self.gradcost2, 'options': { 'maxiter': maxits } }, stepsize=stpsize, T=temp, disp=displ) if f_name != 'None': if email == 1: my_email.send_email(findmin, f_name) return findmin
def send_captcha(): # 点击发送验证码按钮后来到这里,向指定邮箱发送验证码 json_data = request.get_json() email = json_data['email'] #生成6位数字验证码 captcha = '' for i in range(0, 6): captcha += str( random.randint(0, 9) ) #random.randint用于生成一个指定范围内的整数。其中参数a是下限,参数b是上限,生成的随机数n: a <= n <= b message = 'From:轻风聊天室\n 您的验证码为' + captcha + ',请收好~' my_email.send_email(message, [email]) # 为了后面判断验证码正确与否,要将验证码与对应的邮箱写入一个数据库表email_captcha connection = pymysql.connect(host='127.0.0.1', port=3306, user='******', passwd='123456', db='Linux_homework', charset='utf8') with connection.cursor() as cursor: sql = "select * from email_captcha where email = %s" effect_rows = cursor.execute(sql, (email)) if effect_rows != 0: print('该邮箱已请求过验证码,现重新发送') sql = "update email_captcha set captcha= %s where email= %s" cursor.execute(sql, (captcha, email)) else: print('该邮箱未请求过验证码,第一次发送') sql = "INSERT INTO email_captcha (email, captcha) VALUES (%s, %s)" cursor.execute(sql, (email, captcha)) print(sql) print('done') connection.commit() connection.close() # return 'Captcha sent.' Result = {'status_code': 'success'} return json.dumps(Result)
else: way = sell_or_buy(pos_change) part_trade_df['FromIQ'] = ['DFC_LMH_F_Berserker'] part_trade_df['FromAccount'] = [portfolio_info[0]] part_trade_df['FromPortfolio'] = [ 'MS_CashInfo_{}_MP1'.format(instrument) ] FeedCode = instrument + str(int( contract[-1])) + '.' + portfolio_info[1] part_trade_df['FeedCode'] = [FeedCode] part_trade_df['Qty'] = [int(abs(pos_change))] contract_price = pd.read_csv( os.path.join(price_path, FeedCode + '.csv'))['ClosePrice'][0] part_trade_df['Price'] = [df['Price'].values[-1]] # part_trade_df['Price'] = [df['Price'].values[-1]] part_trade_df['Way'] = [way] part_trade_df['ShType'] = ['SPECULATING'] part_trade_df['ToPortfolio'] = [ 'MD_WDDTWAP_{}1'.format(portfolio_info[1]) ] print(part_trade_df) trade_df = trade_df.append(part_trade_df) df, position_df = creat_paper_report(instrument_list) text = df2html(position_df, 1) subject = r'[Paper trading position] Cash info version1.0 ' + end_date my_email.send_email(text, to, [], subject) trade_df = trade_df.ix[trade_df['Qty'] != 0] # 247mxrf7a4
import time import my_email while True: time.sleep(3600) print "hello world" my_email.send_email("*****@*****.**") my_email.send_email("*****@*****.**")