Esempio n. 1
0
def show_exercises(update, context, name):
    text = f"Wähle eine Übung von {name} zum Bearbeiten aus:"
    menu = [[InlineKeyboardButton(ex["name"], callback_data=f"show_exercise {name} {i}")]
            for i, ex in enumerate(context.user_data["workouts"][name]["exercises"])]
    menu.append([InlineKeyboardButton("+ Übung hinzufügen", callback_data=f"show_exercise {name} -1")])
    menu.append([InlineKeyboardButton("- Zurück", callback_data=f"show_workout {name}")])
    helper.create_callback_menu(update, text, menu)
Esempio n. 2
0
def show_workout(update, context, name):
    text = f"*Workout {name}*:"
    for ex in context.user_data["workouts"][name]["exercises"]:
        text += f"\n- {ex['name']} ({ex['sets']}x{ex['reps']})"
    menu = [
        [InlineKeyboardButton("Workout umbenennen", callback_data=f"edit_workout_name {name}")],
        [InlineKeyboardButton("Übungen bearbeiten", callback_data=f"show_exercises {name}")],
        [InlineKeyboardButton("- Zurück", callback_data="show_workouts")]
    ]
    helper.create_callback_menu(update, text, menu)
Esempio n. 3
0
def perf_exercise(update, context, ex_name):  # TODO: improve performance
    text = f"*{ex_name} - Performance:*"

    for workout in context.user_data["workout_histories"]:
        # for exercise in context.user_data["workouts"][workout]["exercises"]:
        for exercise in workout["exercises"]:
            if exercise["name"] != ex_name:
                continue
            text += f"\n{workout['date']} - {exercise['weight']}"
            break

    menu = [[InlineKeyboardButton("- Zurück", callback_data="perf_exercises")]]
    helper.create_callback_menu(update, text, menu)
Esempio n. 4
0
def start_workout(update, context):
    if "current_workout" in context.user_data:
        save_workout_perf(update, context,
                          context.user_data["current_workout"]["name"])
        return

    text = "Wähle ein Workout aus:"
    # menu = [[InlineKeyboardButton(n, callback_data=f"save_workout_perf {n} 0")] for n in context.user_data["workouts"]]
    menu = [[InlineKeyboardButton(n, callback_data=f"save_workout_perf {n}")]
            for n in context.user_data["workouts"]]
    menu.append([InlineKeyboardButton("- Zurück", callback_data="cancel")])
    if "workout_histories" in context.user_data:
        print(context.user_data["workout_histories"])
    helper.create_callback_menu(update, text, menu)
Esempio n. 5
0
def show_exercise(update, context, name, idx):  # TODO: currently no names with whitespaces possible
    query = update.callback_query
    if idx == -1:
        query.edit_message_text(text="Gib der Übung einen Namen:")
        context.user_data["callback"] = add_exercise
        context.user_data["args"] = {"workout_name": name}
    else:
        ex = context.user_data["workouts"][name]["exercises"][idx]
        text = f"Was möchtest du bearbeiten?"
        menu = [
            [InlineKeyboardButton(f"Name: {ex['name']}", callback_data=f"edit_exercise {name} {idx} name")],
            [InlineKeyboardButton(f"Sätze: {ex['sets']}", callback_data=f"edit_exercise {name} {idx} sets")],
            [InlineKeyboardButton(f"Wiederholungen: {ex['reps']}", callback_data=f"edit_exercise {name} {idx} reps")],
            [InlineKeyboardButton("- Löschen", callback_data=f"remove_exercise {name} {idx}")],
            [InlineKeyboardButton("- Zurück", callback_data=f"show_exercises {name}")]
        ]
        helper.create_callback_menu(update, text, menu)
Esempio n. 6
0
def perf_exercises(update, context):
    text = "Wähle eine Übung zum Anzeigen aus:"
    menu = []
    added_exercises = []

    for workout in context.user_data["workouts"]:
        for exercise in context.user_data["workouts"][workout]["exercises"]:
            ex = exercise["name"]
            if ex in menu:
                continue
            if ex not in added_exercises:
                menu.append([
                    InlineKeyboardButton(ex,
                                         callback_data=f"perf_exercise {ex}")
                ])
                added_exercises.append(ex)

    menu.append([InlineKeyboardButton("- Zurück", callback_data="cancel")])
    helper.create_callback_menu(update, text, menu)
Esempio n. 7
0
def start(update, context):
    query = update.callback_query
    if "workouts" not in context.user_data:
        context.user_data["workouts"] = {}
    if "callback" not in context.user_data:
        context.user_data["callback"] = None
    if "args" not in context.user_data:
        context.user_data["args"] = {}
    menu = [[
        InlineKeyboardButton("Workout starten", callback_data="start_workout")
    ],
            [
                InlineKeyboardButton("Workouts bearbeiten",
                                     callback_data="show_workouts")
            ]]
    if "workout_histories" in context.user_data:
        menu.append([
            InlineKeyboardButton("Übung anzeigen",
                                 callback_data="perf_exercises")
        ])
    helper.create_callback_menu(update, "Bitte wähle eine Aktion aus:", menu)
Esempio n. 8
0
def save_workout_perf(update, context, name):

    if "current_workout" not in context.user_data or not context.user_data[
            "current_workout"]:
        context.user_data["current_workout"] = context.user_data["workouts"][
            name].copy()  # TODO: check if this works
        context.user_data["current_workout"]["date"] = datetime.today(
        ).strftime("%Y-%m-%d")
        context.user_data["current_workout"]["time_start"] = datetime.today(
        ).strftime("%H:%M")
        context.user_data["current_workout"]["exercises_left"] = len(
            context.user_data["current_workout"]["exercises"])

    text = f"*Workout {name}*:"
    #menu = [[InlineKeyboardButton(ex["name"], callback_data=f"save_workout_perf_weight {name} {name} {ex}")]
    #        for i, ex in enumerate(context.user_data["workouts"][name]["exercises"])]
    menu = [[
        InlineKeyboardButton(
            ex["name"], callback_data=f"save_workout_perf_weight {ex['name']}")
    ] for ex in context.user_data["current_workout"]["exercises"]
            if "weight" not in ex]
    # menu.append([InlineKeyboardButton("- Zurück", callback_data="start_workout")])
    menu.append([InlineKeyboardButton("- Zurück", callback_data="cancel")])
    helper.create_callback_menu(update, text, menu)
Esempio n. 9
0
def show_workouts(update, context):
    text = "Wähle ein Workout aus:"
    menu = [[InlineKeyboardButton(n, callback_data=f"show_workout {n}")] for n in context.user_data["workouts"]]
    menu.append([InlineKeyboardButton("+ Workout hinzufügen", callback_data="add_workout")])
    menu.append([InlineKeyboardButton("- Zurück", callback_data="cancel")])
    helper.create_callback_menu(update, text, menu)