How duckll/pchome_onsale_bot works
Project type and purpose
• This is an open-source Python “monitor and notify” Telegram bot.
• Purpose: users paste PChome product URLs; the service stores them, fetches prices hourly, and notifies via Telegram only on price drops.
File structure
• Top-level:
• Pipfile, Pipfile.lock – Python dependency management
• docker-compose.yml – orchestrates containers
• README.md, LICENSE, .gitignore
• app/ directory contains:
• bot.py – handles incoming Telegram messages (list, delete, add)
• monitor.py – runs the hourly price-check loop
• index.py – likely the webhook or entrypoint for incoming requests
• crontab – cron schedule definition
• init.sh – container startup script (sets up cron + launches services)
• utils.py – HTTP fetching and parsing of PChome pages
• requirements.txt – pinned Python dependencies for the app
Key insights from README
• Core features: add via URL, list/delete, hourly fetch, notify on price drops only.
• No database folder—persistence may be a flat file, in-memory, or simple key-value store.
Main components
a. External Users/Clients
– Telegram User (mobile/desktop client)
– Telegram Bot API (external service)
– PChome Web Server (for price scraping)
b. Internal Services
– Bot Service Container
• bot.py & index.py: receives Telegram commands via polling or webhook
• utils.py: request/parse product pages
• local store (flat file or in-container DB) for user subscriptions
– Scheduler/Monitor Container (could be the same container with cron)
• cron daemon (defined in app/crontab + init.sh)
• monitor.py: hourly price checks, logic to compare old vs new prices
• triggers notifications via the Bot Service
c. Infrastructure
– Docker Compose: defines and links the bot + scheduler service(s)
– (Optional) Volume or persistent storage for subscription data
Relationships & interactions
• User → Telegram Bot API → Bot Service: “/add <URL>”, “/list”, “/delete”
• Bot Service → local storage: save/delete subscription entries
• Cron daemon → Monitor Service: triggers monitor.py hourly
• Monitor Service → PChome Web Server: HTTP GET requests for product pages
• Monitor Service → comparison logic → if price_drop → send message via Bot Service
• Bot Service → Telegram Bot API → User: price-drop notification
Architectural patterns & design principles
• Modular separation: one module for command handling (bot.py), one for monitoring (monitor.py), a shared util layer (utils.py).
• Scheduler pattern: cron-based periodic execution.
• Single-responsibility: each script does one job.
• Containerization: environment consistency via Docker + Docker Compose.
• Clear callouts for technologies: Python, Docker, Docker Compose, Cron, Telegram Bot API, HTTP scraping