This project is a command-line-based train ticket booking and monitoring system built with Python and MySQL. It provides a user interface for booking and canceling tickets and a password-protected admin interface for managing the railway network and visualizing data with matplotlib
.
- Book Tickets: Users can book tickets for available trains. The system checks for seat availability (both AC and General classes) and updates the booking status in real-time.
- Waiting List: If seats are full, the system automatically places users on a waiting list (up to a maximum of two).
- Cancel Tickets: Users can cancel their booked tickets using their unique ticket ID. The system then automatically confirms a ticket for the next person on the waiting list, if applicable.
The admin interface is password-protected and offers several management and visualization tools:
- Add New Trains: Admins can add new trains to the database, including details like train number, name, source, destination, and ticket fares.
- View Train & Passenger Lists: View detailed, formatted lists of all trains in the network and all booked passengers.
- Data Visualization:
- Gender Distribution: Generate a pie chart showing the gender distribution of passengers for a specific train on a given date.
- Seat Availability: View a bar chart displaying the availability of AC and General seats for a selected train across its scheduled dates.
- Age Distribution: Create a histogram to visualize the age distribution of all passengers across the network.
- Backend: Python
- Database: MySQL
- Libraries:
mysql-connector-python
for connecting to and interacting with the MySQL database.matplotlib
for generating data visualizations and plots.
- Python 3.x
- MySQL Server
First, you need to set up the database and tables.
-
Open your MySQL client (e.g., MySQL Workbench, or the command-line client).
-
Run the SQL script provided in the
sql.txt
file to create therailway_network
database, define the table structures (trainList
,available_days
,train_status
,passenger
), and insert initial sample data.-- Snippet from sql.txt create database railway_network; use railway_network; create table trainList ( trainNumber varchar(10) primary key, trainName char(50), train_source char(30), train_destination char(30), AC_ticket_fair float4, GEN_ticket_fair float4 ); -- ... and so on for the other tables.
Next, set up your Python environment.
- Clone the repository or download the project files.
- Install the required Python packages. You can install them using
pip
:pip install mysql-connector-python matplotlib
Make sure to update the database connection details in Train Network.py
to match your MySQL setup. The default password is set to 1234
.
# In Train Network.py
connection=mysql.connector.connect(host='localhost',user='root',passwd='1234',
database='railway_network')
Execute the main Python script from your terminal to start the application:
python "Train Network.py"
You will be greeted with a main menu where you can choose your desired action.
1: Book a ticket
2: Cancel Ticket
3: Admin Interface
4: Exit
Choice:
To access the admin panel, select option 3
and enter the password (default is 1234
).
--------------------
1: Add a new train
2: Train List
3: Passengers List
4: Gender Chart
5: Seat Availability
6: Age Distribution
7: Exit admin interface
--------------------
Enter your choice: