def show_earnings_options(message): StepModel.set_chat_step(chat_id=message.chat.id, step=const.Steps.earnings_list) bot.send_message( message.chat.id, 'О каком способе заработка вы бы хотели узнать подробнее?', reply_markup=generate_link_providers_keyboard())
def handle_begin_order_input(message): if message.text == const.ORDER_BUTTON_TEXT: bot.send_message(message.chat.id, 'Введите ваше имя') StepModel.set_chat_step(message.chat.id, const.Steps.order_input_name) else: bot.send_message(message.chat.id, 'Подтвердите, что хотите оставить заявку') show_order_description(message)
def handle_order_input_tm(message): if message.text: user_input = UserDetails.get_current_user_input( chat_id=message.chat.id, user=message.from_user) user_input.tm_name = message.text user_input.save() StepModel.set_chat_step(message.chat.id, const.Steps.order_input_email) bot.send_message(message.chat.id, 'Введите ваш email') else: bot.send_message(message.chat.id, 'Не понял. Введите ваш @TM')
def handle_order_input_name(message): if message.text: user_input = UserDetails.get_current_user_input( chat_id=message.chat.id, user=message.from_user) user_input.name = message.text user_input.save() StepModel.set_chat_step(message.chat.id, const.Steps.order_input_phone) bot.send_message(message.chat.id, 'Введите ваш телефон') else: bot.send_message(message.chat.id, 'Не понял. Введите ваше имя')
def addPas(): nbPas = int(request.args.get("pas", "")) idPers = int(request.args.get("id", "")) day = int(request.args.get("jour", "")) month = int(request.args.get("mois", "")) date = datetime.datetime(2015, month, day) try: if nbPas >= 0: person = Person.query.filter_by(id=idPers).first() fitnessInfo = FitnessInfo.query.filter_by(person_id=idPers).first() stepsSumTotal = fitnessInfo.stepSum stepsForDay = Steps.query.filter_by(date=date, person_id=idPers).first() # List is not empty = that person has already entered steps once if stepsForDay: # I have to update with the new Number previousSteps = stepsForDay.stepnumber stepsToSum = previousSteps - nbPas stepsForDay.stepnumber = nbPas stepsSumTotal = stepsSumTotal - stepsToSum else: # List is empty -> New data steps = Steps() steps.person_id = idPers steps.date = date steps.stepnumber = nbPas db.session.add(steps) stepsSumTotal = stepsSumTotal + nbPas fitnessInfo.stepSum = stepsSumTotal personsTeam = Person.query.filter_by(group_id=person.group_id) teamSteps = 0 for pers in personsTeam: teamSteps = teamSteps + FitnessInfo.query.filter_by(person_id=pers.id).first().stepSum group = Group.query.filter_by(id=person.group_id).first() group.stepSum = teamSteps db.session.commit() return "Added " + str(nbPas) + " steps to " + person.nickname else: error = u"Une des valeurs rentrée est inférieure à 0." return error except ValueError: error = u"Une des valeurs rentrée n'est pas numérique." return error
def addSteps(): content = request.get_json() recipe_id = content.pop(len(content) - 1) for i in range(0, len(content), 1): info = content[i] try: steps = Steps( recipe_id=recipe_id, step_num=i+1, info=info ) db.session.add(steps) db.session.commit() except Exception as e: return str(e) return "steps added"
def updateSteps(recipe_id): content = request.get_json() try: Steps.query.filter_by(recipe_id=recipe_id).delete() db.session.commit() except Exception as e: return str(e) for i in range(0, len(content), 1): info = content[i] try: steps = Steps( recipe_id=recipe_id, step_num=i+1, info=info ) db.session.add(steps) db.session.commit() except Exception as e: return str(e) return "steps added"
def home(): print(request.form) user: User = current_user weights = user.weights_dict() steps = user.steps_dict() today = datetime.today() points = [] message = "You can still log your current weight and steps to gain points, make over 10000 steps to make even more points." for weight in weights: if (today.strftime("%m/%d/%y") in weight.values()): points.append(40) message = "Try to make more then 10000 steps tommorow to gain the last 20 points." break for step in steps: if (today.strftime("%m/%d/%y") in step.values()): points.append(40) message = "Try to make more then 10000 steps tommorow to gain the last 20 points." if (step['series'] > 10000): points.append(20) message = "You've done everything for today. A full one hundred points, be proud!!" break le_form = LogExerciseForm(prefix='exercise') le_form.exercise.choices = [(e.id, e.name) for e in Exercise.query.all()] lf_form = LogFoodForm(prefix='food') lf_form.ingredient.choices = [(i.id, i.name) for i in Ingredient.query.all()] w_form = AddWeightForm(prefix='weight') s_form = AddStepsForm(prefix='steps') if lf_form.ingredient.data and lf_form.validate_on_submit(): food_log = FoodLog(grams=lf_form.grams.data) food_log.user = current_user food_log.ingredient_id = lf_form.ingredient.data db.session.add(food_log) db.session.commit() flash('Food added!') return redirect(url_for('home')) if le_form.exercise.data and le_form.validate_on_submit(): exercise_log = ExerciseLog(amount=le_form.reps.data) exercise_log.user = current_user exercise_log.exercise_id = le_form.exercise.data db.session.add(exercise_log) db.session.commit() flash('Exercise added!') return redirect(url_for('home')) if w_form.weight.data and w_form.validate_on_submit(): weight = Weight(w_form.weight.data) weight.user = current_user db.session.add(weight) db.session.commit() flash('Weight added!') return redirect(url_for('home')) if s_form.steps.data and s_form.validate_on_submit(): steps = Steps(s_form.steps.data) steps.user = current_user db.session.add(steps) db.session.commit() flash('Steps added!') return redirect(url_for('home')) return render_template('home.html', e_form=le_form, f_form=lf_form, s_form=s_form, w_form=w_form, weights=weights, steps=steps, points=points, message=message)
def import_data(): if Path('db/app.db').exists(): click.confirm('app.db already exist, want to remove it?', abort=True) Path('db/app.db').unlink() upgrade() user = create_user() with open("data/steps.csv", 'r') as f: reader = DictReader(f) for line in reader: steps = Steps(steps=line['steps']) steps.date = datetime.fromisoformat(line['datetime']) steps.user = user db.session.add(steps) db.session.commit() with open("data/weights.csv", 'r') as f: reader = DictReader(f) for line in reader: weight = Weight(weight=line['weight']) weight.date = datetime.fromisoformat(line['datetime']) weight.user = user db.session.add(weight) db.session.commit() with open("data/exercises.csv", 'r') as f: reader = DictReader(f) for line in reader: exercise = Exercise(name=line['name'], kcal_per_rep=line['kcal']) db.session.add(exercise) db.session.commit() with open("data/ingredients.csv", 'r') as f: reader = DictReader(f) for line in reader: ingredient = Ingredient(name=line['name'], kcal_per_100_gram=line['kcal']) db.session.add(ingredient) db.session.commit() with open("data/food_log.csv", 'r') as f: reader = DictReader(f) for line in reader: food_log = FoodLog() food_log.user = user food_log.ingredient_id = line['ingredient_id'] food_log.grams = line['grams'] food_log.timestamp = datetime.fromisoformat(line['datetime']) db.session.add(food_log) db.session.commit() with open("data/exercise_log.csv", 'r') as f: reader = DictReader(f) for line in reader: exercise_log = ExerciseLog() exercise_log.user = user exercise_log.exercise_id = line['exercise_id'] exercise_log.amount = line['amount'] food_log.timestamp = datetime.fromisoformat(line['datetime']) db.session.add(exercise_log) db.session.commit()
def show_order_description(message): StepModel.set_chat_step(chat_id=message.chat.id, step=const.Steps.order) bot.send_message(message.chat.id, SiteSettings.get_order_description(), reply_markup=order_keyboard)
def show_invitations_options(message): StepModel.set_chat_step(chat_id=message.chat.id, step=const.Steps.invitations_choice) bot.send_message(message.chat.id, 'Выберите один из пунктов меню', reply_markup=invitations_choices_keyboard)
def show_start_menu(chat_id): StepModel.set_chat_step(chat_id, const.Steps.start) bot.send_message(chat_id, 'Что вы хотели бы сделать?', reply_markup=initial_choices_keyboard)