Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fitness tracker bot #228

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions fitness_tracker_bot/fitness_tracker_bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from telegram import Update
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackContext


TELEGRAM_TOKEN = 'YourTelegramBotToken'


user_workouts = {}


def start(update: Update, context: CallbackContext) -> None:
update.message.reply_text("Welcome to Fitness Tracker Bot! Use /log to log your workouts.")
def log_workout(update: Update, context: CallbackContext) -> None:
user_id = update.message.from_user.id
if user_id not in user_workouts:
user_workouts[user_id] = []

workout = update.message.text.replace('/log', '').strip()
user_workouts[user_id].append(workout)

update.message.reply_text(f"Workout logged: {workout}")


def view_workouts(update: Update, context: CallbackContext) -> None:
user_id = update.message.from_user.id
workouts = user_workouts.get(user_id, [])

if workouts:
message = "Your logged workouts:\n" + "\n".join(workouts)
else:
message = "No workouts logged yet."

update.message.reply_text(message)


def handle_text(update: Update, context: CallbackContext) -> None:
update.message.reply_text("I'm a fitness tracker bot. Use /log to log your workouts.")

def main() -> None:
updater = Updater(TELEGRAM_TOKEN)

dp = updater.dispatcher

dp.add_handler(CommandHandler("start", start))
dp.add_handler(CommandHandler("log", log_workout))
dp.add_handler(CommandHandler("view", view_workouts))
dp.add_handler(MessageHandler(Filters.text & ~Filters.command, handle_text))

updater.start_polling()

updater.idle()

if __name__ == '__main__':
main()
28 changes: 28 additions & 0 deletions fitness_tracker_bot/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Fitness Tracker Bot

Welcome to the Fitness Tracker Bot! This bot helps you log and view your workouts. Follow the instructions below to get started.

## How to Use

1. **Start the Bot:**
- Start a chat with the Fitness Tracker Bot on Telegram.

2. **Log a Workout:**
- Use the `/log` command followed by your workout details. For example:
```
/log Ran 5 km
```

3. **View Logged Workouts:**
- Use the `/view` command to see your logged workouts.

## Commands:

- `/start`: Start the bot and get a welcome message.
- `/log [Workout Details]`: Log a workout. Replace `[Workout Details]` with the actual details of your workout.
- `/view`: View your logged workouts.

## Example:

1. Start the bot.
2. Log a workout:
Loading