Skip to content

A telegram bot that scrape Flipkart, Amazon url and keep track of price changes, also alerts the user when there is a price change

License

Notifications You must be signed in to change notification settings

vishwa2k/PriceTrackerBot

 
 

Repository files navigation

Price Tracker Bot

A Telegram bot that tracks product prices from Flipkart and Amazon, using SQLite for data storage.

Features

  • Track product prices from Flipkart and Amazon
  • Get notifications when prices change
  • View price history and statistics
  • Restricted access to trusted users (by ID or username)
  • Price checks every hour
  • Easy to deploy and maintain with SQLite

Download and Installation

Option 1: Download Release Zip

  1. Run the create_release.py script to generate a release zip:
python create_release.py

This will create a zip file named pricetracker_v1_TIMESTAMP.zip containing all necessary source files.

  1. Extract the zip file:
unzip pricetracker_v1_*.zip

Option 2: Clone Repository

git clone <repository-url>

Setup

  1. Install dependencies:
pip install -r requirements.txt
  1. Create .env file:

    • Copy .env_example to .env
    • Fill in your Telegram API credentials
    • Add trusted users (comma-separated Telegram user IDs and usernames)
    # You can use both user IDs and usernames
    TRUSTED_USERS=123456789,@john_doe,987654321,@jane_smith
  2. The SQLite database will be automatically created when you first run the bot

Security

  • Access control by both Telegram user IDs and usernames
  • Users can be trusted by either:
    • Their numeric Telegram ID (e.g., 123456789)
    • Their Telegram username (e.g., @username)
  • Non-trusted users receive a clear message to contact the administrator
  • All bot commands and features are protected by the trusted user filter
  • Usernames are case-insensitive for better usability

Commands

  • /start - Start the bot and get welcome message
  • /help - View available commands and usage
  • /my_trackings - View all products you're tracking
  • /product <id> - Get detailed information about a product
  • /stop <id> - Stop tracking a product

Database Structure

The bot uses SQLite with the following tables:

Products Table

  • Stores global product information
  • Tracks current, previous, and historical prices
  • Maintains price bounds (upper/lower)

User Products Table

  • Maps users to their tracked products
  • Stores Telegram chat IDs for notifications
  • Ensures unique user-product combinations

Telegram Users Table

  • Stores user information
  • Tracks user activity and preferences
  • Manages notification settings

Price Tracking

The bot checks prices every hour and will notify trusted users of any changes. Price history is maintained in the SQLite database, allowing for historical price analysis.

Project Structure

pricetracker/
├── main.py              # Main bot file
├── database.py          # SQLite database operations
├── helpers.py           # Helper functions
├── scheduler.py         # Price check scheduler
├── scraper.py          # Web scraping functionality
├── regex_patterns.py    # URL patterns
├── requirements.txt     # Dependencies
├── .env_example        # Environment variables template
└── create_release.py   # Script to create release zip

File Descriptions

  • main.py: Main bot logic and command handlers
  • database.py: SQLite database management
  • helpers.py: Helper functions for bot operations
  • scheduler.py: Price checking scheduler
  • scraper.py: Web scraping functions
  • regex_patterns.py: URL validation patterns
  • create_release.py: Creates a zip file containing all source code
  • .env_example: Template for configuration

Creating a Release

To create a zip file containing all necessary source code:

  1. Run create_release.py:
python create_release.py
  1. The script will:
    • Create a timestamped zip file
    • Include all necessary source files
    • Exclude unnecessary files (.env, pycache, etc.)
    • Print a list of included files

The generated zip file can be easily shared and deployed on other systems.

Error Handling

  • All database operations include proper error handling
  • Failed operations are logged for debugging
  • Users are notified of any issues through the bot

Dependencies

Main dependencies:

  • pyrogram - Telegram bot framework
  • aiosqlite - Async SQLite support
  • schedule - Task scheduling
  • beautifulsoup4 - Web scraping
  • python-dotenv - Environment configuration

See requirements.txt for complete list.

Contributing

Feel free to open issues or submit pull requests for any improvements.

About

A telegram bot that scrape Flipkart, Amazon url and keep track of price changes, also alerts the user when there is a price change

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%