Python Bots for Personal Use | Generated by AI

Home PDF

Creating a bot can be a fun and practical way to automate tasks, aggregate information, or interact with users. Based on the two Telegram bots you’ve shared (one for scraping and sending news summaries and another for sending reminders or fetching chat IDs), here are some ideas for other bots you could develop, tailored to different use cases and interests. Each idea includes a brief description, potential features, and a simple code structure to get you started. I’ll assume you’re comfortable with Python, requests, and the Telegram Bot API, as shown in your examples.

1. Weather Forecast Bot

Description: A bot that sends daily or on-demand weather updates for a specified location, pulling data from a weather API like OpenWeatherMap.

Features:

Use Case: Useful for personal reminders or for users in a group chat who want weather updates.

Basic Code Structure:

import requests
from dotenv import load_dotenv
import os
import schedule
import time

load_dotenv()

TELEGRAM_BOT_TOKEN = os.environ.get("TELEGRAM_BOT_API_KEY")
TELEGRAM_CHAT_ID = os.environ.get("TELEGRAM_CHAT_ID")
OPENWEATHER_API_KEY = os.environ.get("OPENWEATHER_API_KEY")

def send_telegram_message(message):
    url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage"
    params = {"chat_id": TELEGRAM_CHAT_ID, "text": message, "parse_mode": "Markdown"}
    requests.post(url, params=params).raise_for_status()

def get_weather(city="New York"):
    url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={OPENWEATHER_API_KEY}&units=metric"
    response = requests.get(url).json()
    if response.get("cod") != 200:
        return f"Error fetching weather for {city}."
    weather = response["weather"][0]["description"]
    temp = response["main"]["temp"]
    return f"Weather in {city}: {weather}, {temp}°C"

def daily_weather():
    weather_report = get_weather()
    send_telegram_message(weather_report)

# Schedule daily weather update
schedule.every().day.at("08:00").do(daily_weather)

def handle_updates():
    # Add logic to poll for /weather commands via getUpdates
    pass

if __name__ == "__main__":
    while True:
        schedule.run_pending()
        time.sleep(60)

Next Steps:


2. Task Management Bot

Description: A bot to manage personal or group tasks, allowing users to add, list, complete, or delete tasks via Telegram commands.

Features:

Use Case: Great for personal productivity or team coordination.

Basic Code Structure:

import requests
import json
import os
from dotenv import load_dotenv

load_dotenv()

TELEGRAM_BOT_TOKEN = os.environ.get("TELEGRAM_BOT_API_KEY")
TASKS_FILE = "tasks.json"

def send_telegram_message(chat_id, message):
    url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage"
    params = {"chat_id": chat_id, "text": message}
    requests.post(url, params=params)

def load_tasks():
    try:
        with open(TASKS_FILE, "r") as f:
            return json.load(f)
    except FileNotFoundError:
        return {}

def save_tasks(tasks):
    with open(TASKS_FILE, "w") as f:
        json.dump(tasks, f, indent=4)

def handle_updates():
    url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/getUpdates"
    response = requests.get(url).json()
    if not response["result"]:
        return
    for update in response["result"]:
        chat_id = update["message"]["chat"]["id"]
        text = update["message"]["text"]
        tasks = load_tasks()
        if text.startswith("/add"):
            task = text.replace("/add ", "")
            tasks[str(len(tasks) + 1)] = {"task": task, "status": "pending"}
            save_tasks(tasks)
            send_telegram_message(chat_id, f"Added task: {task}")
        elif text == "/list":
            task_list = "\n".join([f"{k}: {v['task']} ({v['status']})" for k, v in tasks.items()])
            send_telegram_message(chat_id, task_list or "No tasks.")

if __name__ == "__main__":
    while True:
        handle_updates()
        time.sleep(5)

Next Steps:


3. Stock Market Bot

Description: A bot that tracks stock prices or market news, sending updates for specific stocks or indices.

Features:

Use Case: Useful for investors or anyone interested in financial markets.

Basic Code Structure:

import requests
from dotenv import load_dotenv
import os

load_dotenv()

TELEGRAM_BOT_TOKEN = os.environ.get("TELEGRAM_BOT_API_KEY")
ALPHA_VANTAGE_API_KEY = os.environ.get("ALPHA_VANTAGE_API_KEY")

def send_telegram_message(chat_id, message):
    url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage"
    params = {"chat_id": chat_id, "text": message}
    requests.post(url, params=params)

def get_stock_price(ticker):
    url = f"https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol={ticker}&apikey={ALPHA_VANTAGE_API_KEY}"
    response = requests.get(url).json()
    if "Global Quote" in response:
        price = response["Global Quote"]["05. price"]
        return f"{ticker}: ${price}"
    return f"Error fetching price for {ticker}."

def handle_updates():
    url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/getUpdates"
    response = requests.get(url).json()
    for update in response["result"]:
        chat_id = update["message"]["chat"]["id"]
        text = update["message"]["text"]
        if text.startswith("/stock"):
            ticker = text.replace "stock ", "")
            price = get_stock_price(ticker)
            send_telegram_message(chat_id, price)

if __name__ == "__main__":
    while True:
        handle_updates()
        time.sleep(5)

Next Steps:


4. RSS Feed Bot

Description: A bot that monitors RSS feeds (e.g., blogs, news sites, or podcasts) and sends new posts to Telegram.

Features:

Use Case: Stay updated on niche blogs or podcasts without checking multiple sites.

Basic Code Structure:

import requests
import feedparser
from dotenv import load_dotenv
import os
import json

load_dotenv()

TELEGRAM_BOT_TOKEN = os.environ.get("TELEGRAM_BOT_API_KEY")
FEEDS_FILE = "feeds.json"

def send_telegram_message(chat_id, message):
    url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage"
    params = {"chat_id": chat_id, "text": message, "parse_mode": "Markdown"}
    requests.post(url, params=params)

def load_feeds():
    try:
        with open(FEEDS_FILE, "r") as f:
            return json.load(f)
    except FileNotFoundError:
        return {"feeds": [], "last_entries": {}}

def save_feeds(feeds):
    with open(FEEDS_FILE, "w") as f:
        json.dump(feeds, f, indent=4)

def check_feeds():
    feeds = load_feeds()
    for feed_url in feeds["feeds"]:
        feed = feedparser.parse(feed_url)
        latest_entry = feed.entries[0]["link"] if feed.entries else None
        if latest_entry and latest_entry != feeds["last_entries"].get(feed_url):
            feeds["last_entries"][feed_url] = latest_entry
            send_telegram_message(TELEGRAM_CHAT_ID, f"New post: {feed.entries[0]['title']} ({latest_entry})")
    save_feeds(feeds)

if __name__ == "__main__":
    while True:
        check_feeds()
        time.sleep(600)  # Check every 10 minutes

Next Steps:


5. Meme Generator Bot

Description: A bot that generates or fetches memes, either randomly or based on user input, using an API like Imgflip or a custom meme generator.

Features:

Use Case: Fun for group chats or personal entertainment.

Basic Code Structure:

import requests
from dotenv import load_dotenv
import os

load_dotenv()

TELEGRAM_BOT_TOKEN = os.environ.get("TELEGRAM_BOT_API_KEY")
IMGFLIP_USERNAME = os.environ.get("IMGFLIP_USERNAME")
IMGFLIP_PASSWORD = os.environ.get("IMGFLIP_PASSWORD")

def send_telegram_photo(chat_id, photo_url, caption=""):
    url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendPhoto"
    params = {"chat_id": chat_id, "photo": photo_url, "caption": caption}
    requests.post(url, params=params)

def generate_meme(template_id, text0, text1):
    url = "https://api.imgflip.com/caption_image"
    params = {
        "template_id": template_id,  # e.g., 181913649 for Drake meme
        "username": IMGFLIP_USERNAME,
        "password": IMGFLIP_PASSWORD,
        "text0": text0,
        "text1": text1
    }
    response = requests.post(url, data=params).json()
    if response["success"]:
        return response["data"]["url"]
    return None

def handle_updates():
    url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/getUpdates"
    response = requests.get(url).json()
    for update in response["result"]:
        chat_id = update["message"]["chat"]["id"]
        text = update["message"]["text"]
        if text.startswith("/meme"):
            parts = text.split(" ", 2)
            if len(parts) == 3:
                meme_url = generate_meme("181913649", parts[1], parts[2])
                if meme_url:
                    send_telegram_photo(chat_id, meme_url, "Here's your meme!")
                else:
                    send_telegram_photo(chat_id, "", "Failed to generate meme.")

if __name__ == "__main__":
    while True:
        handle_updates()
        time.sleep(5)

Next Steps:


General Tips for Building Bots

Choosing a Bot

System: Based on the code and ideas provided, here are a few additional bot ideas that could complement the existing news aggregator and reminder bots, tailored to different interests or needs:

6. Personal Finance Tracker Bot

Description: A bot to track expenses, income, or budget goals, allowing users to log transactions and receive summaries or alerts.

Features:

Use Case: Helps manage personal or household finances.

Basic Code Structure:

import requests
import json
import os
from dotenv import load_dotenv
import datetime

load_dotenv()

TELEGRAM_BOT_TOKEN = os.environ.get("TELEGRAM_BOT_API_KEY")
FINANCE_FILE = "finance.json"

def send_telegram_message(chat_id, message):
    url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage"
    params = {"chat_id": chat_id, "text": message, "parse_mode": "Markdown"}
    requests.post(url, params=params)

def load_finance_data():
    try:
        with open(FINANCE_FILE, "r") as f:
            return json.load(f)
    except FileNotFoundError:
        return {"transactions": [], "budget": 0}

def save_finance_data(data):
    with open(FINANCE_FILE, "w") as f:
        json.dump(data, f, indent=4)

def generate_summary(data):
    total_expenses = sum(t["amount"] for t in data["transactions"] if t["type"] == "expense")
    total_income = sum(t["amount"] for t in data["transactions"] if t["type"] == "income")
    return f"Summary:\nTotal Income: ${total_income}\nTotal Expenses: ${total_expenses}\nBalance: ${total_income - total_expenses}"

def handle_updates():
    url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/getUpdates"
    response = requests.get(url).json()
    if not response["result"]:
        return
    data = load_finance_data()
    for update in response["result"]:
        chat_id = update["message"]["chat"]["id"]
        text = update["message"]["text"]
        if text.startswith("/addexpense"):
            try:
                amount, category = text.replace("/addexpense ", "").split(" ")
                data["transactions"].append({"type": "expense", "amount": float(amount), "category": category, "date": str(datetime.datetime.now())})
                save_finance_data(data)
                send_telegram_message(chat_id, f"Added expense: ${amount} ({category})")
            except ValueError:
                send_telegram_message(chat_id, "Usage: /addexpense <amount> <category>")
        elif text == "/summary":
            summary = generate_summary(data)
            send_telegram_message(chat_id, summary)

if __name__ == "__main__":
    while True:
        handle_updates()
        time.sleep(5)

Next Steps:


7. Fitness Tracker Bot

Description: A bot to log workouts, track fitness goals, or send motivational reminders.

Features:

Use Case: Ideal for fitness enthusiasts or those starting a health journey.

Basic Code Structure:

import requests
import json
import os
from dotenv import load_dotenv
import schedule
import time

load_dotenv()

TELEGRAM_BOT_TOKEN = os.environ.get("TELEGRAM_BOT_API_KEY")
FITNESS_FILE = "fitness.json"

def send_telegram_message(chat_id, message):
    url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage"
    params = {"chat_id": chat_id, "text": message}
    requests.post(url, params=params)

def load_fitness_data():
    try:
        with open(FITNESS_FILE, "r") as f:
            return json.load(f)
    except FileNotFoundError:
        return {"workouts": [], "goals": {}}

def save_fitness_data(data):
    with open(FITNESS_FILE, "w") as f:
        json.dump(data, f, indent=4)

def daily_reminder():
    send_telegram_message(TELEGRAM_CHAT_ID, "Time for your daily workout! 💪")

def handle_updates():
    url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/getUpdates"
    response = requests.get(url).json()
    if not response["result"]:
        return
    data = load_fitness_data()
    for update in response["result"]:
        chat_id = update["message"]["chat"]["id"]
        text = update["message"]["text"]
        if text.startswith("/logworkout"):
            try:
                workout_type, duration = text.replace("/logworkout ", "").split(" ")
                data["workouts"].append({"type": workout_type, "duration": int(duration)})
                save_fitness_data(data)
                send_telegram_message(chat_id, f"Logged {workout_type} for {duration} minutes.")
            except ValueError:
                send_telegram_message(chat_id, "Usage: /logworkout <type> <duration>")
        elif text == "/progress":
            total_minutes = sum(w["duration"] for w in data["workouts"])
            send_telegram_message(chat_id, f"Total workout time: {total_minutes} minutes")

schedule.every().day.at("07:00").do(daily_reminder)

if __name__ == "__main__":
    while True:
        schedule.run_pending()
        handle_updates()
        time.sleep(5)

Next Steps:


8. Learning Reminder Bot

Description: A bot to support learning goals by sending study reminders, flashcards, or tracking progress.

Features:

Use Case: Perfect for students or lifelong learners.

Basic Code Structure:

import requests
import json
import os
from dotenv import load_dotenv
import random
import schedule
import time

load_dotenv()

TELEGRAM_BOT_TOKEN = os.environ.get("TELEGRAM_BOT_API_KEY")
FLASHCARDS_FILE = "flashcards.json"

def send_telegram_message(chat_id, message):
    url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage"
    params = {"chat_id": chat_id, "text": message}
    requests.post(url, params=params)

def load_flashcards():
    try:
        with open(FLASHCARDS_FILE, "r") as f:
            return json.load(f)
    except FileNotFoundError:
        return []

def save_flashcards(flashcards):
    with open(FLASHCARDS_FILE, "w") as f:
        json.dump(flashcards, f, indent=4)

def daily_study_reminder():
    send_telegram_message(TELEGRAM_CHAT_ID, "Time to study! Try /quiz for a flashcard.")

def handle_updates():
    url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/getUpdates"
    response = requests.get(url).json()
    if not response["result"]:
        return
    flashcards = load_flashcards()
    for update in response["result"]:
        chat_id = update["message"]["chat"]["id"]
        text = update["message"]["text"]
        if text.startswith("/addflashcard"):
            try:
                question, answer = text.replace("/addflashcard ", "").split("|")
                flashcards.append({"question": question.strip(), "answer": answer.strip()})
                save_flashcards(flashcards)
                send_telegram_message(chat_id, f"Added flashcard: {question}")
            except ValueError:
                send_telegram_message(chat_id, "Usage: /addflashcard <question>|<answer>")
        elif text == "/quiz":
            if flashcards:
                card = random.choice(flashcards)
                send_telegram_message(chat_id, f"Question: {card['question']}\nReply with the answer!")
                # Store chat_id and question for answer verification
            else:
                send_telegram_message(chat_id, "No flashcards available. Add some with /addflashcard!")

schedule.every().day.at("18:00").do(daily_study_reminder)

if __name__ == "__main__":
    while True:
        schedule.run_pending()
        handle_updates()
        time.sleep(5)

Next Steps:


Choosing the Right Bot

Technical Recommendations

If you’d like a more detailed implementation for any of these bots or help integrating specific APIs, let me know! You can also specify if you want a bot tailored to a particular interest or task.


Back 2025.06.06 Donate