An advanced Telegram bot that tracks product prices on Trendyol and sends smart notifications when prices change. Designed for efficiency and reliability with enhanced user experience.
- 🔗 Universal Link Support: Works with Trendyol.com, ty.gl (shortened), tyml.gl, and trendyol-milla.com links
- ➕ Easy Product Addition: Use
/eklecommand or simply send a Trendyol link - ➖ Product Management: Remove products with
/silcommand - 📋 Smart Listing: View all tracked products with price trends using
/listele - 🔄 Automated Price Monitoring: Configurable interval-based price checking
- 🎯 Smart Notifications:
- 📈 "Price Increased" notifications with red indicator
- 📉 "Price Decreased" notifications with green indicator
- Detailed price difference and percentage change
- 🔔 Customizable notification threshold per chat
- 🔄 Manual Refresh: Use
/yenilecommand to instantly check all product prices
- 🛒 Sold-Out Product Tracking:
- Automatic detection of out-of-stock products
- Special notifications when products go out of stock
- Back-in-stock alerts when products become available again
- ⚙️ Dynamic Price Threshold:
- Set custom price change threshold per chat with
/thresholdcommand - Only get notified when price changes exceed your threshold
- Prevents notification spam for minor price fluctuations
- Set custom price change threshold per chat with
- 🏠 Multi-Group Support: Restrict bot access to specific Telegram groups
- 🚨 Advanced Error Handling & Monitoring:
- Automatic admin notifications for critical errors
- Categorized error messages with suggested solutions
- High error rate detection and alerts
- Detailed logging for debugging
- ⚡ Optimized Performance: Lightweight code perfect for Raspberry Pi and low-power devices
- 🎨 Rich Formatting: HTML-formatted messages with clickable links
- 🔄 Smart Retry Strategy: Automatic retry with exponential backoff on failures
- ⏱️ Random Request Delays: Anti-bot protection with randomized delays between requests
- 🔌 Connection Pooling: Efficient HTTP session management with connection reuse
- 🎯 Multiple Scraping Methods: 7 different fallback methods for price detection
- 📊 JSON-LD Support: Extract prices from structured data when available
- 🧩 JavaScript Parsing: Can extract prices from JavaScript variables when needed
- Python 3.6+ (Recommended: Python 3.8 or newer)
- pip (Python package manager)
- Telegram Bot Token (obtainable from @BotFather)
- Telegram Group ID(s) for access control
- Clone the repository:
git clone https://github.com/furkandlkdr/telegram-trendyol-bot.git
cd telegram-trendyol-bot- Create and activate virtual environment:
# Windows
python -m venv venv
venv\Scripts\activate
# Linux/macOS
python3 -m venv venv
source venv/bin/activate- Install dependencies:
pip install -r requirements.txt- Configure environment variables:
- Copy
.env.exampleto.env - Edit
.envwith your settings:
- Copy
# Telegram Bot Token from @BotFather
TELEGRAM_BOT_TOKEN=1234567890:ABCdefGHIjklMNOpqrsTUVwxyz
# Price check interval in minutes (default: 30)
CHECK_INTERVAL=30
# Comma-separated list of allowed Telegram group IDs
ALLOWED_GROUP_IDS=-1001234567890,-1009876543210- Start the bot:
python main.pyTo find your Telegram group ID:
- Add the bot to your group
- Send any message in the group
- Visit:
https://api.telegram.org/bot{YOUR_BOT_TOKEN}/getUpdates - Look for
"chat":{"id": -1001234567890}in the JSON response - Copy the negative number (including the minus sign)
| Command | Description | Example |
|---|---|---|
/start |
Initialize bot and show help | /start |
/ekle [URL] |
Add product to tracking | /ekle https://www.trendyol.com/... |
/sil [URL] |
Remove product from tracking | /sil https://www.trendyol.com/... |
/listele |
List all tracked products | /listele |
/yenile |
Manual refresh - Check all product prices instantly | /yenile |
/threshold [%] |
Set price change notification threshold | /threshold 10 |
Method 1: Command
/ekle https://www.trendyol.com/product-link
Method 2: Direct Link Simply paste any Trendyol link in the group:
https://www.trendyol.com/your-product-link
https://ty.gl/shortened-link
The /listele command shows:
- 📈 Price increased from initial price
- 📉 Price decreased from initial price
- ➡️ No change in price
- Direct links to products
- Current vs initial price comparison
Use /yenile command to instantly check all tracked product prices:
- 🔄 Instant Check: Immediately checks all products without waiting for scheduled interval
- 📊 Summary Report: Shows how many products were checked and how many prices changed
- 🔔 Immediate Notifications: Sends instant notifications for any price changes found
- ⚡ Safe Operation: Uses the same functions as automatic checking, no system conflicts
Control when you get notified with /threshold command:
- 📊 Custom Threshold: Set different thresholds for each chat/group
- 🎯 Percentage-Based: Configure threshold as percentage (e.g., 5% = only notify if price changes by more than 5%)
- 📉 Reduce Noise: Avoid notifications for minor price fluctuations
- 💾 Persistent: Threshold is saved and remembered for your chat
- 📝 View Current: Use
/thresholdwithout parameters to see current setting
Example Usage:
/threshold 10 # Only notify if price changes by more than 10%
/threshold 0 # Get notified on any price change
/threshold # View current threshold
The bot automatically detects and tracks product availability:
- 🚫 Out-of-Stock Detection: Automatically detects when products become unavailable
- 📱 Sold-Out Notifications: Get notified immediately when tracked products go out of stock
- 🟢 Back-in-Stock Alerts: Receive notification when sold-out products become available again
- 💾 State Preservation: Product tracking continues even when out of stock
- 🔄 Automatic Updates: Monitors stock status during every price check
What Happens:
- Product goes out of stock → You get a "Product Sold Out" notification
- Bot continues monitoring the product
- Product comes back in stock → You get a "Back in Stock" notification with new price
- Product Addition: Bot scrapes product name and current price using multiple fallback methods
- Data Storage: Information saved in
tracked_products.jsonwith initial and current prices - Scheduled Checks: Bot checks prices every X minutes (configurable via CHECK_INTERVAL)
- Manual Checks: Use
/yenilecommand for instant price checking - Smart Notifications: Only sends alerts when prices change beyond configured threshold
- Price Updates: Database automatically updates with new prices
- Stock Monitoring: Continuously monitors product availability and sends stock status alerts
- Error Handling: Automatic retry with exponential backoff on network failures
- Admin Alerts: Critical errors and high error rates trigger admin notifications
Create a systemd service for automatic startup:
sudo nano /etc/systemd/system/trendyol-bot.serviceService configuration (adjust paths for your setup):
[Unit]
Description=Trendyol Price Tracking Bot
After=network.target
[Service]
User=pi
WorkingDirectory=/home/pi/telegram-trendyol-bot
ExecStart=/home/pi/telegram-trendyol-bot/venv/bin/python main.py
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.targetEnable and start:
sudo systemctl enable trendyol-bot.service
sudo systemctl start trendyol-bot.serviceCheck status:
sudo systemctl status trendyol-bot.servicetelegram-trendyol-bot/
├── main.py # 🤖 Main bot logic and Telegram handlers
├── scraper.py # 🕷️ Trendyol web scraping functionality
├── data_manager.py # 💾 JSON data management (CRUD operations)
├── config.py # ⚙️ Configuration and environment variables
├── requirements.txt # 📦 Python dependencies
├── .env.example # 📋 Environment variables template
├── .env # 🔐 Your actual environment variables (create this)
├── tracked_products.json # 🗃️ Product database (auto-generated with bot)
└── README.md # 📖 This documentation
| File | Purpose | Key Functions |
|---|---|---|
main.py |
Bot orchestration | Command handlers, price checking, notifications |
scraper.py |
Web scraping | Product info extraction, price parsing |
data_manager.py |
Data persistence | Add/remove products, price updates |
config.py |
Configuration | Environment variables, settings |
- python-telegram-bot 13.15: Telegram Bot API wrapper
- requests 2.31.0: HTTP requests for web scraping
- beautifulsoup4 4.12.2: HTML parsing
- lxml 4.9.3: Fast XML/HTML parser
- schedule 1.2.0: Job scheduling
- python-dotenv 1.0.0: Environment variable management
- Advanced Price Detection: 7 different fallback methods for robust price extraction:
- New Trendyol structure with data-testid attributes
- price-price class search
- Legacy campaign-price and prc-dsc classes
- JSON-LD structured data extraction
- JavaScript variable parsing (winnerVariant, productDetail)
- General TL/₺ symbol search
- Multiple price container strategies
- Intelligent Stock Detection: Multiple methods for accurate stock status:
- Add-to-cart button presence and text analysis
- Buy-now button detection
- Disabled button state checking
- Out-of-stock message scanning
- URL Validation: Supports trendyol.com, ty.gl, tyml.gl, and trendyol-milla.com
- Retry Strategy: HTTP requests with exponential backoff (max 3 retries)
- Anti-Bot Protection:
- Random delays (1-3 seconds) between requests
- Realistic user-agent headers
- Session-based connection pooling
- Error Recovery: Comprehensive error handling with categorization and logging
- Memory Efficient: Minimal resource usage, ideal for 24/7 operation on Raspberry Pi
- Thread Safety: Proper threading for scheduler and bot operations
- Admin Monitoring: Automatic error notifications with diagnostic information
Bot not responding:
- Check if
TELEGRAM_BOT_TOKENis correct - Verify group ID is in
ALLOWED_GROUP_IDS - Ensure bot has proper permissions in the group
Price not detected:
- Trendyol may have changed their HTML structure
- Bot uses 7 different detection methods - if all fail, site structure changed significantly
- Check logs for scraping errors
- Try with different products
- Consider updating the scraper.py with new selectors
Duplicate notifications:
- Fixed with improved scheduler management
- Restart the bot if still occurring
Memory issues on Raspberry Pi:
- Reduce
CHECK_INTERVALto check less frequently - Consider using swap if needed
Bot logs important events. Check console output for:
- Product addition/removal confirmations
- Price check results with detailed scraping attempts
- Error details with categorization (Network, Timeout, Connection, etc.)
- Notification sending status
- Stock status changes (sold-out, back-in-stock)
- Retry attempts and backoff delays
- HTTP request/response information
- Threshold updates and trigger events
Debug Levels:
INFO: Normal operations (price checks, notifications sent)WARNING: Recoverable issues (retries, minor errors)ERROR: Serious problems (scraping failures, notification errors)DEBUG: Detailed technical information (HTML parsing, price extraction)
- Personal Use: This bot is designed for personal/small group use
- Rate Limiting: Trendyol may implement anti-bot measures
- Legal Compliance: Ensure compliance with Trendyol's terms of service
- Reliability: While robust, web scraping can break if sites change structure
- Privacy: All data is stored locally in JSON format
Contributions are welcome! Please feel free to submit pull requests or open issues for:
- Bug fixes
- New features
- Documentation improvements
- Performance optimizations
- Telegram Bot API Documentation
- BotFather - Create your bot token
- Trendyol - Supported e-commerce platform
Trendyol'daki ürün fiyatlarını takip eden ve fiyat değişikliklerinde akıllı bildirimler gönderen gelişmiş Telegram botu. Verimlilik ve güvenilirlik odaklı, geliştirilmiş kullanıcı deneyimi ile tasarlanmıştır.
- 🔗 Evrensel Link Desteği: Trendyol.com, ty.gl (kısaltılmış), tyml.gl ve trendyol-milla.com linkleriyle çalışır
- ➕ Kolay Ürün Ekleme:
/eklekomutu kullanın veya direkt Trendyol linki gönderin-paylaşın - ➖ Ürün Yönetimi:
/silkomutu ile ürünleri kaldırın - 📋 Akıllı Listeleme:
/listeleile fiyat trendleriyle birlikte tüm takip edilen ürünleri görün - 🔄 Otomatik Fiyat İzleme: Yapılandırılabilir aralıklarla fiyat kontrolü
- 🎯 Akıllı Bildirimler:
- 📈 Kırmızı gösterge ile "Fiyat Yükseldi" bildirimleri
- 📉 Yeşil gösterge ile "Fiyat Düştü" bildirimleri
- Detaylı fiyat farkı ve yüzde değişim bilgisi
- 🔔 Her sohbet için özelleştirilebilir bildirim eşiği
- 🔄 Manuel Yenileme:
/yenilekomutu ile tüm ürün fiyatlarını anında kontrol edin
- 🛒 Tükenen Ürün Takibi:
- Stokta olmayan ürünlerin otomatik tespiti
- Ürünler tükendiğinde özel bildirimler
- Ürünler tekrar stokta olduğunda geri geldi uyarıları
- ⚙️ Dinamik Fiyat Eşiği:
/thresholdkomutu ile her sohbet için özel fiyat değişim eşiği belirleyin- Sadece eşiği aşan fiyat değişikliklerinde bildirim alın
- Küçük fiyat dalgalanmalarında bildirim spamını önleyin
- 🏠 Çoklu Grup Desteği: Bot erişimini belirli Telegram gruplarıyla sınırlayın
- 🚨 Gelişmiş Hata Yönetimi ve İzleme:
- Kritik hatalar için otomatik admin bildirimleri
- Önerilen çözümlerle kategorize edilmiş hata mesajları
- Yüksek hata oranı tespiti ve uyarıları
- Hata ayıklama için detaylı loglama
- ⚡ Optimize Edilmiş Performans: Raspberry Pi ve düşük güçlü cihazlar için mükemmel hafif kod
- 🎨 Zengin Formatlama: Tıklanabilir linklerle HTML formatlı mesajlar
- 🔄 Akıllı Yeniden Deneme Stratejisi: Hatalarda üstel geri çekilme ile otomatik yeniden deneme
- ⏱️ Rastgele İstek Gecikmeleri: İstekler arasında rastgele gecikmelerle anti-bot koruması
- 🔌 Bağlantı Havuzu: Bağlantı yeniden kullanımı ile verimli HTTP oturum yönetimi
- 🎯 Çoklu Kazıma Yöntemleri: Fiyat tespiti için 7 farklı yedek yöntem
- 📊 JSON-LD Desteği: Mevcut olduğunda yapılandırılmış verilerden fiyat çıkarımı
- 🧩 JavaScript Ayrıştırma: Gerektiğinde JavaScript değişkenlerinden fiyat çıkarabilir
- Python 3.6+ (Önerilen: Python 3.8 veya daha yeni)
- pip (Python paket yöneticisi)
- Telegram Bot Token (@BotFather üzerinden alınabilir)
- Telegram Grup ID(leri) erişim kontrolü için
- Repoyu klonlayın:
git clone https://github.com/furkandlkdr/telegram-trendyol-bot.git
cd telegram-trendyol-bot- Sanal ortam oluşturun ve etkinleştirin:
# Windows
python -m venv venv
venv\Scripts\activate
# Linux/macOS
python3 -m venv venv
source venv/bin/activate- Bağımlılıkları yükleyin:
pip install -r requirements.txt- Çevre değişkenlerini yapılandırın:
.env.exampledosyasını.envolarak kopyalayın.envdosyasını ayarlarınızla düzenleyin:
# @BotFather'dan alınan Telegram Bot Token
TELEGRAM_BOT_TOKEN=1234567890:ABCdefGHIjklMNOpqrsTUVwxyz
# Dakika cinsinden fiyat kontrol aralığı (varsayılan: 30)
CHECK_INTERVAL=30
# İzin verilen Telegram grup ID'lerinin virgülle ayrılmış listesi
ALLOWED_GROUP_IDS=-1001234567890,-1009876543210- Botu başlatın:
python main.pyTelegram grup ID'nizi bulmak için:
- Botu grubunuza ekleyin
- Grupta herhangi bir mesaj gönderin
- Şu adresi ziyaret edin:
https://api.telegram.org/bot{BOT_TOKEN_INIIZ}/getUpdates - JSON yanıtında
"chat":{"id": -1001234567890}bölümünü arayın - Negatif sayıyı (eksi işaretiyle birlikte) kopyalayın
| Komut | Açıklama | Örnek |
|---|---|---|
/start |
Botu başlat ve yardımı göster | /start |
/ekle [URL] |
Ürünü takibe ekle | /ekle https://www.trendyol.com/... |
/sil [URL] |
Ürünü takipten çıkar | /sil https://www.trendyol.com/... |
/listele |
Tüm takip edilen ürünleri listele | /listele |
/yenile |
Manuel yenileme - Tüm ürün fiyatlarını anında kontrol et | /yenile |
/threshold [%] |
Fiyat değişim bildirim eşiğini ayarla | /threshold 10 |
Yöntem 1: Komut
/ekle https://www.trendyol.com/urun-linki
Yöntem 2: Direkt Link Herhangi bir Trendyol linkini gruba yapıştırın:
https://www.trendyol.com/urun-linkiniz
https://ty.gl/kisaltilmis-link
/listele komutu şunları gösterir:
- 📈 Başlangıç fiyatından artış
- 📉 Başlangıç fiyatından düşüş
- ➡️ Fiyatta değişiklik yok
- Ürünlere direkt linkler
- Güncel ve başlangıç fiyat karşılaştırması
/yenile komutu ile tüm takip edilen ürün fiyatlarını anında kontrol edin:
- 🔄 Anında Kontrol: Zamanlanmış aralığı beklemeden tüm ürünleri hemen kontrol eder
- 📊 Özet Rapor: Kaç ürün kontrol edildiğini ve kaç tanesinde fiyat değiştiğini gösterir
- 🔔 Anında Bildirimler: Bulunan fiyat değişiklikleri için anında bildirim gönderir
- ⚡ Güvenli İşlem: Otomatik kontrolle aynı fonksiyonları kullanır, sistem çakışması yaşanmaz
/threshold komutu ile ne zaman bildirim alacağınızı kontrol edin:
- 📊 Özel Eşik: Her sohbet/grup için farklı eşikler belirleyin
- 🎯 Yüzde Tabanlı: Eşiği yüzde olarak yapılandırın (örn: %5 = sadece fiyat %5'ten fazla değişirse bildir)
- 📉 Gürültüyü Azalt: Küçük fiyat dalgalanmaları için bildirim almayın
- 💾 Kalıcı: Eşik kaydedilir ve sohbetiniz için hatırlanır
- 📝 Mevcut Değeri Gör: Parametresiz
/thresholdkullanarak mevcut ayarı görün
Kullanım Örnekleri:
/threshold 10 # Sadece fiyat %10'dan fazla değişirse bildir
/threshold 0 # Her fiyat değişikliğinde bildir
/threshold # Mevcut eşiği görüntüle
Bot otomatik olarak ürün bulunabilirliğini tespit eder ve takip eder:
- 🚫 Stokta Yok Tespiti: Ürünler stokta kalmadığında otomatik tespit
- 📱 Tükendi Bildirimleri: Takip edilen ürünler tükendiğinde anında bildirim
- 🟢 Stokta Geri Geldi Uyarıları: Tükenen ürünler tekrar satışa çıktığında bildirim
- 💾 Durum Koruma: Ürün takibi stokta olmasa bile devam eder
- 🔄 Otomatik Güncellemeler: Her fiyat kontrolünde stok durumunu izler
Nasıl Çalışır:
- Ürün stoktan tükenir → "Ürün Tükendi" bildirimi alırsınız
- Bot ürünü izlemeye devam eder
- Ürün tekrar stokta olur → Yeni fiyatıyla "Stokta Geri Geldi" bildirimi alırsınız
- Ürün Ekleme: Bot çoklu yedek yöntemler kullanarak ürün adını ve güncel fiyatı çeker
- Veri Saklama: Bilgiler
tracked_products.jsondosyasında başlangıç ve güncel fiyatlarla saklanır - Zamanlanmış Kontroller: Bot her X dakikada bir fiyatları kontrol eder (CHECK_INTERVAL ile yapılandırılabilir)
- Manuel Kontroller:
/yenilekomutu ile anında fiyat kontrolü yapın - Akıllı Bildirimler: Sadece fiyatlar yapılandırılan eşiğin üzerinde değiştiğinde uyarı gönderir
- Fiyat Güncellemeleri: Veritabanı otomatik olarak yeni fiyatlarla güncellenir
- Stok İzleme: Ürün bulunabilirliğini sürekli izler ve stok durumu uyarıları gönderir
- Hata Yönetimi: Ağ hatalarında üstel geri çekilme ile otomatik yeniden deneme
- Admin Uyarıları: Kritik hatalar ve yüksek hata oranları admin bildirimlerini tetikler
Otomatik başlatma için systemd servisi oluşturun:
sudo nano /etc/systemd/system/trendyol-bot.serviceServis yapılandırması (yolları kendi kurulumunuza göre ayarlayın):
[Unit]
Description=Trendyol Fiyat Takip Botu
After=network.target
[Service]
User=pi
WorkingDirectory=/home/pi/telegram-trendyol-bot
ExecStart=/home/pi/telegram-trendyol-bot/venv/bin/python main.py
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.targetEtkinleştirin ve başlatın:
sudo systemctl enable trendyol-bot.service
sudo systemctl start trendyol-bot.serviceDurumu kontrol edin:
sudo systemctl status trendyol-bot.servicetelegram-trendyol-bot/
├── main.py # 🤖 Ana bot mantığı ve Telegram işleyicileri
├── scraper.py # 🕷️ Trendyol web kazıma işlevselliği
├── data_manager.py # 💾 JSON veri yönetimi (CRUD işlemleri)
├── config.py # ⚙️ Yapılandırma ve çevre değişkenleri
├── requirements.txt # 📦 Python bağımlılıkları
├── .env.example # 📋 Çevre değişkenleri şablonu
├── .env # 🔐 Gerçek çevre değişkenleriniz (bunu oluşturun)
├── tracked_products.json # 🗃️ Ürün veritabanı (bot tarafından otomatik oluşturulur)
└── README.md # 📖 Bu dokümantasyon
| Dosya | Amaç | Ana Fonksiyonlar |
|---|---|---|
main.py |
Bot orkestras | Komut işleyicileri, fiyat kontrolü, bildirimler |
scraper.py |
Web kazıma | Ürün bilgisi çıkarma, fiyat ayrıştırma |
data_manager.py |
Veri kalıcılığı | Ürün ekleme/çıkarma, fiyat güncellemeleri |
config.py |
Yapılandırma | Çevre değişkenleri, ayarlar |
- python-telegram-bot 13.15: Telegram Bot API sarmalayıcısı
- requests 2.31.0: Web kazıma için HTTP istekleri
- beautifulsoup4 4.12.2: HTML ayrıştırma
- lxml 4.9.3: Hızlı XML/HTML ayrıştırıcısı
- schedule 1.2.0: İş zamanlama
- python-dotenv 1.0.0: Çevre değişkeni yönetimi
- Gelişmiş Fiyat Tespiti: Sağlam fiyat çıkarma için 7 farklı yedek yöntem:
- Yeni Trendyol yapısı (data-testid özellikleri)
- price-price sınıf araması
- Eski campaign-price ve prc-dsc sınıfları
- JSON-LD yapılandırılmış veri çıkarımı
- JavaScript değişken ayrıştırma (winnerVariant, productDetail)
- Genel TL/₺ sembol araması
- Çoklu fiyat konteyner stratejileri
- Akıllı Stok Tespiti: Doğru stok durumu için çoklu yöntemler:
- Sepete ekle butonu varlığı ve metin analizi
- Hemen al butonu tespiti
- Devre dışı buton durum kontrolü
- Stokta yok mesaj taraması
- URL Doğrulama: trendyol.com, ty.gl, tyml.gl ve trendyol-milla.com destekler
- Yeniden Deneme Stratejisi: Üstel geri çekilme ile HTTP istekleri (maks 3 deneme)
- Anti-Bot Koruması:
- İstekler arası rastgele gecikmeler (1-3 saniye)
- Gerçekçi kullanıcı-agent başlıkları
- Oturum tabanlı bağlantı havuzu
- Hata Kurtarma: Kategorilendirme ve loglama ile kapsamlı hata yönetimi
- Bellek Verimli: Minimal kaynak kullanımı, Raspberry Pi'de 7/24 işletim için ideal
- Thread Güvenliği: Zamanlayıcı ve bot işlemleri için uygun threading
- Admin İzleme: Tanı bilgileri ile otomatik hata bildirimleri
The bot uses a sophisticated waterfall approach to extract prices, trying 7 different methods in order:
-
Modern Trendyol Structure (Primary)
- Searches for
data-testid="price"containers - Looks for discounted prices first, then original prices
- Handles multiple price display formats
- Searches for
-
Class-Based Search (Secondary)
price-priceclass divscampaign-priceparagraphsprc-dscspan elements
-
Structured Data (Tertiary)
- Parses JSON-LD schema.org markup
- Extracts from
offers.pricefields - Handles both single and array offers
-
JavaScript Variables (Quaternary)
- Searches for
winnerVariantobject - Looks for
productDetaildata - Extracts from various price field names
- Searches for
-
Symbol Search (Last Resort)
- General TL/₺ symbol search
- Price range validation (0.01-100,000 TL)
- Filters out IDs and non-price numbers
Multiple methods ensure accurate stock detection:
- Button Analysis: Checks add-to-cart and buy-now button presence and text
- Disabled State: Detects disabled purchase buttons
- Text Scanning: Searches for out-of-stock messages in visible elements
- Context Filtering: Ignores JavaScript code and metadata to avoid false positives
- Random Delays: 1-3 second randomized delays between requests
- Retry with Backoff: Exponential backoff (2^attempt + random)
- Session Pooling: Reuses HTTP connections for efficiency
- Realistic Headers: Browser-like user agent and accept headers
- Error Recovery: Graceful degradation on failures
Bot fiyatları çıkarmak için sofistike bir şelale yaklaşımı kullanır, 7 farklı yöntemi sırayla dener:
-
Modern Trendyol Yapısı (Birincil)
data-testid="price"konteynerlerini arar- Önce indirimli fiyatlara, sonra orijinal fiyatlara bakar
- Çoklu fiyat gösterim formatlarını işler
-
Sınıf Tabanlı Arama (İkincil)
price-pricesınıf divlericampaign-priceparagraflarıprc-dscspan elementleri
-
Yapılandırılmış Veri (Üçüncül)
- JSON-LD schema.org işaretlemesini ayrıştırır
offers.pricealanlarından çıkarır- Hem tekli hem dizi tekliflerini işler
-
JavaScript Değişkenleri (Dörtüncül)
winnerVariantobjesini ararproductDetailverisine bakar- Çeşitli fiyat alan adlarından çıkarır
-
Sembol Araması (Son Çare)
- Genel TL/₺ sembol araması
- Fiyat aralığı doğrulaması (0.01-100.000 TL)
- ID'leri ve fiyat olmayan sayıları filtreler
Doğru stok tespiti için çoklu yöntemler:
- Buton Analizi: Sepete ekle ve hemen al butonlarının varlığını ve metnini kontrol eder
- Devre Dışı Durum: Devre dışı satın alma butonlarını tespit eder
- Metin Tarama: Görünür elementlerde stokta yok mesajlarını arar
- Bağlam Filtreleme: Yanlış pozitifleri önlemek için JavaScript kodu ve metadatayı yok sayar
- Rastgele Gecikmeler: İstekler arası 1-3 saniye rastgele gecikmeler
- Geri Çekilme ile Yeniden Deneme: Üstel geri çekilme (2^deneme + rastgele)
- Oturum Havuzu: Verimlilik için HTTP bağlantılarını yeniden kullanır
- Gerçekçi Başlıklar: Tarayıcı benzeri kullanıcı aracı ve kabul başlıkları
- Hata Kurtarma: Hatalarda zarif düşüş
Bot yanıt vermiyor:
TELEGRAM_BOT_TOKEN'ın doğru olduğunu kontrol edin- Grup ID'sinin
ALLOWED_GROUP_IDS'te olduğunu doğrulayın - Botun grupta uygun izinlere sahip olduğundan emin olun
Fiyat tespit edilmiyor:
- Trendyol HTML yapısını değiştirmiş olabilir
- Bot 7 farklı tespit yöntemi kullanır - hepsi başarısız olursa site yapısı önemli ölçüde değişmiş
- Kazıma hatalarını kontrol etmek için logları inceleyin
- Farklı ürünlerle deneyin
- Yeni seçicilerle scraper.py'yi güncellemeyi düşünün
Çift bildirim:
- Geliştirilmiş zamanlayıcı yönetimiyle düzeltildi
- Hala oluşuyorsa botu yeniden başlatın
Raspberry Pi'de bellek sorunları:
- Daha az sıklıkta kontrol için
CHECK_INTERVAL'ı artırın - Gerekirse swap kullanmayı düşünün
Bot önemli olayları loglar. Konsol çıktısında şunları kontrol edin:
- Ürün ekleme/çıkarma onayları
- Detaylı kazıma denemeleriyle fiyat kontrol sonuçları
- Kategorilendirme ile hata detayları (Ağ, Zaman Aşımı, Bağlantı, vb.)
- Bildirim gönderme durumu
- Stok durumu değişiklikleri (tükendi, stokta geri geldi)
- Yeniden deneme girişimleri ve geri çekilme gecikmeleri
- HTTP istek/yanıt bilgileri
- Eşik güncellemeleri ve tetikleme olayları
Hata Seviyeleri:
INFO: Normal işlemler (fiyat kontrolleri, bildirim gönderildi)WARNING: Kurtarılabilir sorunlar (yeniden denemeler, küçük hatalar)ERROR: Ciddi problemler (kazıma hataları, bildirim hataları)DEBUG: Detaylı teknik bilgiler (HTML ayrıştırma, fiyat çıkarımı)
- Kişisel Kullanım: Bu bot kişisel/küçük grup kullanımı için tasarlanmıştır
- Hız Sınırlaması: Trendyol anti-bot önlemleri uygulayabilir
- Yasal Uyumluluk: Trendyol'un kullanım şartlarına uygunluğu sağlayın
- Güvenilirlik: Sağlam olmasına rağmen, siteler yapı değiştirirse web kazıma bozulabilir
- Gizlilik: Tüm veriler yerel olarak JSON formatında saklanır
Bot artık hataları otomatik olarak admin'e bildirir:
- 🚨 Kritik Hatalar: Bot çöktüğünde anında bildirim
⚠️ Scraping Hataları: Çok sayıda scraping hatası durumunda uyarı- 📊 Watchdog Raporları: Bot durumu hakkında düzenli bilgiler
.env dosyanıza admin chat ID'nizi ekleyin:
ADMIN_CHAT_ID=123456789Chat ID'nizi bulmak için:
- Bot'unuza
/startmesajı gönderin https://api.telegram.org/bot{BOT_TOKEN}/getUpdatesadresini ziyaret edin"from":{"id": 123456789}değerini kopyalayın
Watchdog scripti botunuzu sürekli izler:
- ✅ Process İzleme: Bot çalışıp çalışmadığını kontrol eder
- 🔄 Otomatik Restart: Bot durduğunda otomatik yeniden başlatır
- 📱 Telegram Bildirimleri: Tüm olaylar için bildirim gönderir
- 📝 Detaylı Loglama: Tüm aktiviteler loglanır
# Projeyi klonlayın
git clone https://github.com/furkandlkdr/telegram-trendyol-bot.git
cd telegram-trendyol-bot
# Kurulum scriptini çalıştırın
chmod +x install_raspberry.sh
./install_raspberry.sh1. Sistem hazırlığı:
sudo apt update && sudo apt upgrade -y
sudo apt install -y python3 python3-pip python3-venv git curl2. Proje kurulumu:
git clone https://github.com/furkandlkdr/telegram-trendyol-bot.git
cd telegram-trendyol-bot
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt3. Çevre değişkenleri:
cp .env.example .env
nano .env # Ayarlarınızı girin4. Systemd servisleri:
sudo cp systemd/trendyol-bot.service /etc/systemd/system/
sudo cp systemd/trendyol-watchdog.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable trendyol-bot.service
sudo systemctl enable trendyol-watchdog.service5. Servisleri başlatın:
sudo systemctl start trendyol-bot.service
sudo systemctl start trendyol-watchdog.serviceServis durumu:
sudo systemctl status trendyol-bot.service
sudo systemctl status trendyol-watchdog.serviceCanlı loglar:
sudo journalctl -u trendyol-bot.service -f
sudo journalctl -u trendyol-watchdog.service -fServis yönetimi:
sudo systemctl restart trendyol-bot.service
sudo systemctl stop trendyol-bot.service
sudo systemctl start trendyol-bot.serviceSistem kaynaklarını izleme:
htop # CPU ve RAM kullanımı
df -h # Disk kullanımı
free -h # Bellek durumu
journalctl --disk-usage # Log disk kullanımıBellek optimizasyonu:
# Swap dosyası oluştur (isteğe bağlı)
sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
# /etc/fstab'a ekle
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstabLog döngüsü:
# Log boyutunu sınırla
sudo nano /etc/systemd/journald.conf
# Şu satırları uncomment edin:
# SystemMaxUse=50M
# MaxRetentionSec=1week
sudo systemctl restart systemd-journaldBot başlamıyor:
# Detaylı log kontrol
sudo journalctl -u trendyol-bot.service --no-pager
# Manuel test
cd /home/pi/telegram-trendyol-bot
source venv/bin/activate
python main.pyWatchdog çalışmıyor:
# Process kontrolü
ps aux | grep python
ps aux | grep watchdog
# Manuel watchdog testi
cd /home/pi/telegram-trendyol-bot
source venv/bin/activate
python watchdog.pyBellek sorunu:
# Bellek kullanımını kontrol et
free -h
sudo systemctl status
# Gereksiz servisleri durdur
sudo systemctl disable bluetooth.service
sudo systemctl disable hciuart.serviceKatkılar memnuniyetle karşılanır! Lütfen şunlar için pull request gönderin veya issue açın:
- Hata düzeltmeleri
- Yeni özellikler
- Dokümantasyon iyileştirmeleri
- Performans optimizasyonları
Bu proje açık kaynaklıdır ve MIT Lisansı altında mevcuttur.
- Telegram Bot API Dokümantasyonu
- BotFather - Bot token'ınızı oluşturun
- Trendyol - Desteklenen e-ticaret platformu