Exemplo n.º 1
0
def get_vali_code(phone):
    print_time()
    print "in get_vali_code"
    url = "https://hongbao.xiaojukeji.com/hongbao/send/code?phone=" + phone
    res = get_html_by_requests(url)
    if res.find("10000") != -1:
        return "已发送"
    elif res.find("30003") != -1:  # 1分钟只能接受一次验证码
        return "请稍后刷新重试"
    else:                          # 每天最多发5条短信
        return "今日次数达上限"
Exemplo n.º 2
0
def login():
    print_time()
    print "\nroot: login\n"
    form = LoginForm()
    if form.validate_on_submit():
        user_name = form.username.data
        pass_word = form.password.data
        print "账号密码:", user_name, pass_word
        user = User(user_name)
        if user.verify_password(pass_word):
            login_user(user)
            return redirect(
                request.args.get('next') or url_for('myblueprint.add'))
    return render_template('login.html', form=form)
Exemplo n.º 3
0
def get():
    print_time()
    print "\nroot: get\n"
    s = request.args.get("id", "0")
    level, status = get_level_status_by_id(s)
    uid = get_uid_by_id(s)
    print "\n此id的level和status:", level, status, "\n"
    if level in legal_level:
        if status == 1:
            return render_template('get.html', id=s, level=level, uid=uid)
        else:
            phone, amount = get_phone_amount_by_id(s)
            return render_template('received.html', phone=phone, amount=amount)
    else:
        return u"非法链接"
Exemplo n.º 4
0
def addlink():
    print_time()
    print "\nroot: addlink\n"
    link = request.args.get("link", "")
    level = int(request.args.get("level", "0"))
    uid = current_user.get_id()
    if level not in legal_level:
        return "红包档次输入错误"
    if check_link_exist(link):
        return "重复入库"
    res = insert_link_to_db(link, level, uid)
    if res:
        return "入库成功"
    else:
        return "入库失败"
Exemplo n.º 5
0
def createlink():
    print_time()
    print "\nroot: createlink\n"
    level = int(request.args.get("level", "0"))
    uid = current_user.get_id()
    if level not in legal_level:
        return "红包档次输入错误"
    res = insert_id_to_db(level, uid)
    if res and len(res) > 0:
        head = "http://toolazy.site/vali?id=" if level in vali_level else "http://toolazy.site/get?id="
        links = ""
        for s in res:
            links += str(level) + " : " + (head + s + '\n')
        return links
    else:
        return "链接生成错误"
Exemplo n.º 6
0
def get(target_mid):
    feed = Feed(target_mid, last_score=None)
    while True:
        feed_list, request_time, decode_time = feed.get_next_feed_list()
        if not feed_list:
            break
        save_time_start = time.time()
        success, failed = db.save_thread(feed_list, target_mid)
        save_time = time.time() - save_time_start
        last_time = tools.print_time(feed_list[-1])
        print(
            '最后一条的时间: %s, 版块: %s, 成功: %s, 失败: %s, 请求耗时 %.3f 秒, 解析耗时 %.3f 秒, 保存耗时 %.3f 秒'
            % (last_time, config.mid_name_map[target_mid], success, failed,
               request_time, decode_time, save_time / len(feed_list)))
    print('版块: %s 已完成' % config.mid_name_map[target_mid])
Exemplo n.º 7
0
				cost, grad_norm = update_grads(x, xmask, y, ymask, MRTLoss)
			elif config['semi_learning']:
				cost, grad_norm = update_grads(x, xmask, y, ymask, y, ymask, x, xmask, valid)
			elif config['PR']:
				cost, grad_norm = update_grads(x, xmask, y, ymask, features, ans)
			else:
				cost, grad_norm = update_grads(x, xmask, y, ymask)
			# NaN processing
			if numpy.isinf(cost.mean()) or numpy.isnan(cost.mean()):
				logging.warning('There is an NaN!')
			update_params()
			ed = time.time()
			data.time += ed - st
			data.updatetime += ed - upst

			data.train_cost.append(cost.mean())
			logging.debug('iteration %d: cost = %.4f, grad_norm = %.3e,' % (data.num_iter, cost.mean(), grad_norm)+
			' iter_time =  %.3f, total_time: %s' % (ed - st, tools.print_time(data.time)))
		except KeyboardInterrupt:
			logging.info('\nStop training by keyboard interruption.')
			break

	# save checkpoint
	s = signal.signal(signal.SIGINT, signal.SIG_IGN)
	logging.info('Saving model and status\n')
	model.save(config['checkpoint_model'], data = data, mapping = mapping)
	data.save_status(config['checkpoint_status'])
	logging.info('The training is completed.\n')
	signal.signal(signal.SIGINT, s)

Exemplo n.º 8
0
                cost, grad_norm = update_grads(x, xmask, y, ymask, y, ymask, x,
                                               xmask, valid)
            else:
                #print y_parent_t
                cost, grad_norm = update_grads(x, xmask, y_rule_idx,
                                               y_parent_t, ymask)
            # NaN process
            if numpy.isinf(cost.mean()) or numpy.isnan(cost.mean()):
                logging.warning('nan while training')
            update_params()
            ed = time.time()
            data.time += ed - st
            data.updatetime += ed - upst

            data.train_cost.append(cost.mean())
            logging.debug('iter: %d; cost: %.4f; grad_norm: %.3e;' %
                          (data.num_iter, cost.mean(), grad_norm) +
                          'iter time: %.3f sec; total time: %s' %
                          (ed - st, tools.print_time(data.time)))
        except KeyboardInterrupt:
            logging.info('stop training on keyboard interrupt')
            break

    #save checkpoint
    s = signal.signal(signal.SIGINT, signal.SIG_IGN)
    logging.info('saving model and status...')
    model.save(config['checkpoint_model'], data=data, mapping=mapping)
    data.save_status(config['checkpoint_status'])
    logging.info('Done')
    signal.signal(signal.SIGINT, s)
Exemplo n.º 9
0
def create():
    print_time()
    print "\nroot: create\n"
    form = LogoutForm()
    return render_template('create.html', form=form)
Exemplo n.º 10
0
def logout():
    print_time()
    print "\nroot: logout\n"
    logout_user()
    return redirect(url_for('myblueprint.login'))
Exemplo n.º 11
0
def add():
    print_time()
    print "\nroot: add\n"
    form = LogoutForm()
    return render_template('add.html', form=form)
Exemplo n.º 12
0
def getvalicode():
    print_time()
    print "\nroot: getvalicode\n"
    phone = request.args.get("phone")
    res = get_vali_code(phone)
    return res