Exemple #1
0
def command_delete(message):
	ctx.push()
	day_deep = 7 # определяет глубину записей за 7 дней от сегодня
	cid = message.chat.id
	text=message.text.replace('/','')
	user_id = OriginSystemUsers.query.filter_by(system_userid=str(cid)).first().id_users
	cur_session = check_user_seesion(user_id)
	if cur_session is not None:
		session_disabled(user_id)	
	cdo(UserSession(id_users=user_id, id_botcommand=botCommands[text]['id']))
	current_date = date.today()
	begin_date = current_date + timedelta(days = ((-1)*day_deep))
	result = user_records_format(user_records(user_id, begin_date, current_date))
	if result is None:
		bot.send_message(cid,
		 'За последние {} дней не было внесено новых данных'.format(day_deep),
		  reply_markup=keyboard_commands)
		ctx.pop()
		return 0

	message_text = 'В системе за 7 дней есть записи: \n '+result + '\n для удаления записи пришли ее ID. например, 5'

	bot.send_message(cid, message_text, reply_markup=keyboard_commands)
	
	ctx.pop()
	return 0
Exemple #2
0
def command_start(message):
	ctx.push()
	cid = message.chat.id
	usname = message.from_user.username
	text = message.text.replace('/','')
	if usname is None:
		bot.send_message(cid, "Наш бот работает c использованием Telegram username. \n Пожалуйста, заполни это поле в настройках Telegram и повторно вызови команду /start .")
		return 0


	if not User.query.filter_by(name=usname).first():  # if user hasn't used the "/start" command yet:
		cdo(User(name=usname, id_originsystem=gi(OriginSystem, messenger)))
		cdo(OriginSystemUsers(system_username=usname, system_userid=cid, id_users=gi(User, usname), id_originsystem=gi(OriginSystem, messenger)))
		#bot.send_message(cid, "Привет! Теперь мы познакомились ) \n Выбери команду внизу или нажми /help для вызова списка доступных команд", reply_markup=keyboard_commands)
		bot.send_message(cid, "Привет! Пришли имя для отображения в рейтинге (не более 30 символов)")
		ctx.pop()
		return 0
	else:
		user_info = User.query.filter_by(name=usname).first()
		if user_info.display_name == 'bot_anonymous':

			cur_session = check_user_seesion(user_info.id)
			if cur_session is not None:
				session_disabled(user_info.id)	
			cdo(UserSession(id_users=user_info.id, id_botcommand=botCommands[text]['id']))
			bot.send_message(cid, "Привет! Пришли имя для отображения в рейтинге (не более 30 символов)")
			ctx.pop()
			return 0
		bot.send_message(cid,
			"Привет, {}! \n Выбери команду внизу или нажми /help для вызова списка доступных команд.".format(user_info.display_name),
		 reply_markup=keyboard_commands)
		ctx.pop()
		return 0
Exemple #3
0
def signup():
    form = SignUpForm(request.form)

    if form.validate_on_submit() and not current_user.is_authenticated:

        username = form.username.data
        password = form.password.data
        user = UserSession(username=username)
        user.set_password(password)

        db.session.add(user)
        db.session.commit()
        login_user(user)

        return redirect('/assessment')

    return render_template('sign_up.html', title='Sign Up', form=form)
Exemple #4
0
def command_new(message):
    cid = message.chat.id
    user_id = OriginSystemUsers.query.filter_by(system_userid=str(cid)).first().id_users
    cur_session = check_user_seesion(user_id)
    if cur_session is not None:
    	session_disabled(user_id)
    cdo(UserSession(id_users=user_id, id_botcommand=botCommands[message.text]['id']))
    bot.send_message(cid, 'Пришли мне, пожалуйста, название нового вида спорта')
    return 0
Exemple #5
0
def command_add(message):
	ctx.push()
	cid = message.chat.id
	text=message.text.replace('/','')
	user_id = OriginSystemUsers.query.filter_by(system_userid=str(cid)).first().id_users
	cur_session = check_user_seesion(user_id)
	if cur_session is not None:
		session_disabled(user_id)	
	cdo(UserSession(id_users=user_id, id_botcommand=botCommands[text]['id']))
	bot.send_message(cid, sports_gr_commands, reply_markup=keyboard_commands)
	
	ctx.pop()
	return 0
Exemple #6
0
def register_action(request):
    session = request.session
    if 'active' not in session:
        new_session = UserSession()
        db_session = Session()
        db_session.add(new_session)
        db_session.commit()
        session['id'] = new_session.id
        session['active'] = True
        db_session.close()
    new_action = Action(session_id=session['id'], url=request.url)
    db_session = Session()
    db_session.add(new_action)
    db_session.commit()
    db_session.close()