DEV Community

Mahdi Hasan Shuvo
Mahdi Hasan Shuvo

Posted on

Bangladesh Railway Ticket Auto-Booking Bot

πŸš† Bangladesh Railway Ticket Auto-Booking Bot


⚑ Lightning-Fast | 🧠 Smart Captcha | 🎯 Seat-Precise | πŸ” Secure OTP


An extraordinary high-performance automation engine that books
Bangladesh Railway (eticket.railway.gov.bd / Shohoz) train tickets the
instant they go on sale β€” faster than any human can blink.




πŸ’‘ "Stop fighting the clock. Stop refreshing pages at 8 AM. Let
the bot win the seat war for you."


✨ Why This Bot Is Different

Most ticket bots break the moment Cloudflare Turnstile expires their token, or they crash when the server rate-limits them. This one doesn't.

πŸ”₯ Built for the real world β€” every error message, every Cloudflare challenge, every "ticket not available" race condition has been hunted down and fixed.

🎯 Feature πŸš€ What It Means For You
Multi-threaded Turnstile Pool 3 background solvers keep 6 fresh tokens ready 24/7 β€” never wait, never expire
Per-Seat Fresh Tokens Every reservation request gets its own unexpired token β€” zero Invalid action token errors
Smart Seat Preference Engine Prioritize your favorite seat numbers, then fall back to any available seat
Parallel Seat Reservation Reserves multiple seats in parallel using a thread pool β€” wins races against human clickers
Scheduled Run Time Set it once, walk away β€” the bot wakes up at the exact second tickets open
Auto OTP Resend If you miss the SMS, the bot re-requests OTP up to 3 times automatically
Auto PDF Ticket Download After payment, your ticket PDF is downloaded and saved with a smart filename
Rate-Limit Auto-Recovery Detects "wait X minutes Y seconds" responses and politely waits β€” no IP bans
bKash / Card / Nagad Ready Whatever payment method your account uses, the bot opens the right gateway

🎬 Live Demo β€” See It In Action

πŸš€ Step 1 β€” Bot Boots & Locks Onto The Trip

The instant you launch, the bot identifies your train, route, boarding point, and counts available seats in real time.

Bot Startup


🟒 Seat class detected · Trip ID locked · Boarding point captured · 72
seats available


⚑ Step 2 β€” Parallel Seat Reservation (Faster Than Human Clicks)

The bot fires multiple reservation requests in parallel, claiming your preferred seats before anyone else can scroll.

Seats Reserved


πŸ”₯ 3 seats locked in milliseconds: KA-20,
KA-21, KA-22 β€” then waits for your
OTP


βœ… Step 3 β€” OTP Verified β†’ Ticket Booking Confirmed!

After OTP verification, the bot finalizes the booking and opens the bKash payment gateway instantly.

Booking Confirmed


πŸŽ‰ "Ticket booking is confirmed!" β€”
Auto-redirects to bKash for payment


πŸ“„ Step 4 β€” PDF Ticket Auto-Downloaded

The moment payment clears, your official ticket PDF is downloaded and saved with a smart, organized filename.

πŸ“₯ View Sample Ticket PDF


πŸ’» Terminal Output Preview

╔════════════════════════════════════════════════════════════╗
β•‘  Running from folder: AC_B-D-3                             β•‘
β•‘  Captcha Balance: 12.94 | IP: 103.137.67.242               β•‘
β•‘  Seat class: AC_B                                          β•‘
β•‘  Version: 0.0.4                                            β•‘
β•‘  Your Bot is ready to work βœ…                              β•‘
β•‘  Waiting... 14s remaining                                  β•‘
β•‘                                                            β•‘
β•‘  trip_id: 8566632  route: 57904643  boarding: 110759229    β•‘
β•‘  Eligible: 23 | Preferred: 4 | Others: 19                  β•‘
β•‘  [1] seat reserved - KHA-3                                 β•‘
β•‘  [2] seat reserved - KHA-7                                 β•‘
β•‘                                                            β•‘
β•‘  Enter your OTP (press Enter to wait): 5957                β•‘
β•‘  βœ… OTP received, stopping resend                          β•‘
β•‘  πŸ’³ Opening bKash payment gateway...                       β•‘
β•‘  πŸ“„ PDF downloaded: 16_Dec_2026_SUBORNO_AC_B_ticket.pdf    β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

🧠 How It Works (The Magic Inside)

flowchart LR
    A[⏰ Wait For Run Time] --> B[πŸ” Search Trips]
    B --> C[🎫 Get Seat Layout]
    C --> D[🧠 Solve Turnstile Captcha]
    D --> E[⚑ Reserve Seats In Parallel]
    E --> F[πŸ“± Trigger OTP]
    F --> G[βœ… Verify OTP]
    G --> H[πŸ’³ Confirm Booking + Open Payment]
    H --> I[πŸ“„ Auto Download Ticket PDF]
  1. Pre-arm phase β€” Bot launches early, builds a pool of fresh Cloudflare Turnstile tokens.
  2. Countdown phase β€” Idles until your exact scheduled run_at time.
  3. Strike phase β€” The instant tickets open, it queries seat-layout, filters by your preferences, and fires parallel reservation requests with fresh tokens.
  4. Lock phase β€” Triggers passenger-details OTP, you enter the SMS code, bot verifies.
  5. Pay phase β€” Confirms booking, opens your payment gateway, polls purchase history, and downloads the PDF the moment payment completes.

3️⃣ Configure user_data.json

{
  "token": "YOUR_RAILWAY_ACCESS_TOKEN",
  "d_ID": "YOUR_DEVICE_ID",
  "api_key": "YOUR_2CAPTCHA_API_KEY",
  "from_city": "Dhaka",
  "to_city": "Chattogram",
  "date_of_journey": "20-Dec-2026",
  "seat_class": "AC_B",
  "trip_number": "SUBORNO EXPRESS",
  "Seats_to_reserve": 2,
  "set_start": 1,
  "floor_name": "",
  "preferred_seat_numbers": ["KHA-3", "KHA-7"],
  "payment_method": 1,
  "run_at": "2026-12-15 08:00:00.000000",
  "info_user": [
    { "Name": "Your Name", "gender": "male", "passengerType": "Adult" }
  ]
}

4️⃣ Run It

python mian.py

The bot will sit quietly, top up its captcha pool, then strike at run_at time.


🎨 Smart Configuration

πŸ”‘ Key πŸ“ Description πŸ’Ž Example
from_city / to_city Origin and destination stations "Dhaka" β†’ "Chattogram"
seat_class Class to book AC_B, SNIGDHA, S_CHAIR, SHOVAN
trip_number Train name keyword (partial match OK) "SUBORNO"
Seats_to_reserve Number of seats to lock 1 to 4
preferred_seat_numbers Priority list β€” bot grabs these first ["KHA-3", "KHA-7"]
set_start Skip seat numbers below this 1
floor_name Filter coaches by floor "upper" or ""
payment_method Payment gateway selector 1 = bKash
run_at Exact strike time (microsecond precision) "2026-12-15 08:00:00.000000"

🚦 Status Codes Decoded

πŸ”΄ Error 🟒 What The Bot Does
TURNSTILE_VERIFICATION_FAILED Silently swaps in a fresh token and retries
Invalid or expired action token Auto-rotates token from the pool
Sorry! this ticket is not available Moves to the next seat instantly
Maximum 4 seats already reserved Stops gracefully (server hard limit)
Server Error 403 Backs off 2 seconds and retries
Rate limited X minutes Y seconds Counts down precisely and resumes
Invalid User Access Token Halts and asks you to refresh login

βš™οΈ Architecture Highlights

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  🧡 Thread 1-3:  Turnstile Solver Pool (always fresh)    β”‚
β”‚  🧡 Thread 4:    OTP Auto-Resender                       β”‚
β”‚  🧡 Thread 5+:   Parallel Seat Reservation Workers       β”‚
β”‚  🧡 Main:        Trip Search β†’ Layout β†’ Confirm β†’ PDF    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  • TTL-bounded token pool β€” every token is timestamped; anything older than 100s is dropped before use.
  • Thread-safe shared state β€” all reservation lists protected by locks; no race condition can double-book.
  • Zero recursion β€” flat while True retry loops mean unlimited resilience without stack overflow.
  • Boundary-only error handling β€” internal helpers stay clean; only network edges catch exceptions.

πŸ”’ Safety & Compliance

⚠️ For personal use only. This tool helps individuals reserve their own tickets faster β€” it does not bypass payment, security, or identity verification. You still pay through the official gateway. You still verify with your own phone's OTP. You still submit your real passenger details.

  • βœ… Uses the official Bangladesh Railway / Shohoz API β€” no scraping, no DOM hacks.
  • βœ… Captchas solved through legitimate 2Captcha service (you pay per solve).
  • βœ… Respects server rate limits with intelligent backoff.
  • ❌ Not affiliated with Bangladesh Railway or Shohoz.

πŸ“ˆ Roadmap

  • Multi-threaded Turnstile token pool
  • Per-seat fresh token rotation
  • Auto OTP resend
  • PDF auto-download
  • Telegram bot notifications
  • GUI desktop app (Electron / PyQt)
  • Mobile companion app
  • Multi-account orchestration
  • Smart fare-class fallback

πŸ’¬ Support & Contact

πŸ“§ Need help, custom build, or premium edition?

Portfolio
Email
Telegram
WhatsApp


πŸ’¬ Telegram / WhatsApp: +8801616397082


πŸ’Ό Available for freelance & paid projects β€” Let's
build something great together!


⭐ Show Some Love

If this bot saved you from the 8 AM ticket war, drop a ⭐ on the repo β€” it really helps!

Built with ❀️ for Bangladeshi train travelers who refuse to lose
the seat war.


Made in Bangladesh πŸ‡§πŸ‡©

project :https://github.com/Mahdi-hasan-shuvo/bangladesh-railway-ticket-booking-bot

Top comments (0)