├── README.md ├── user.py ├── tkt_bk.py └── Main_Code.py /README.md: -------------------------------------------------------------------------------- 1 | # Railway-Reservation-System-using-Python 2 | I have develop a railway reservation system which is categories as customer,Ticket checker and admin.following are the functionalities which are fullfill by system-1.login and signup for all three users,2.ticket PNR generated using QR code,3.Ticket Checker easily check ticket using QR scanner etc. 3 | 4 | -------------------------------------------------------------------------------- /user.py: -------------------------------------------------------------------------------- 1 | class User(object): 2 | """docstring for User""" 3 | def __init__(self, name=None, mo_no=None, add=None, email=None): 4 | super(User, self).__init__() 5 | self.name = name 6 | self.mo_no = mo_no 7 | self.add = add 8 | self.email=email 9 | 10 | def __str__(self): 11 | return "\nName : " + self.name+\ 12 | "\nAdd : " + str(self.add)+\ 13 | "\nMo No: "+ str(self.mo_no)+\ 14 | "\nEmail: "+ str(self.email) 15 | 16 | def display(self): 17 | print "Name : ", self.name 18 | print "Add : ", self.mo_no 19 | print "Mo No: ", self.add 20 | print "Email:",self.email 21 | -------------------------------------------------------------------------------- /tkt_bk.py: -------------------------------------------------------------------------------- 1 | class TICKET_BOOK (object): 2 | """docstring for User""" 3 | def __init__(self, Class=None, bdg_pt=None, quota=None): 4 | super(TICKET_BOOK, self).__init__() 5 | self.Class = Class 6 | self.bdg_pt = bdg_pt 7 | self.quota=quota 8 | 9 | def __str__(self): 10 | return "============================="+\ 11 | "\nClass : " + self.Class+\ 12 | "\nbdg_pt: "+ str(self.bdg_pt)+\ 13 | "\nquota : "+ str(self.quota)+\ 14 | "\n============================="+\ 15 | " " 16 | 17 | def display(self): 18 | print "=============================" 19 | print " CLASS : ",self.Class 20 | print " BOARDING PT.: ",self.bdg_pt 21 | print " QUOTA : ",self.quota 22 | print "=============================" 23 | print " " 24 | -------------------------------------------------------------------------------- /Main_Code.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import pickle 3 | from user import User 4 | from tkt_bk import TICKET_BOOK 5 | import qrcode 6 | from random import * 7 | from pathlib import Path 8 | 9 | class Train_Ticket(): 10 | 11 | Admin_list = [] 12 | Cust_list = [] 13 | Tc_list = [] 14 | ticket_list = [] 15 | loc_list=[] 16 | pnr=[] 17 | 18 | def __init__(self, user = None, tkt_bk = None ): 19 | if isinstance(user, User) and isinstance(tkt_bk, TICKET_BOOK): 20 | Train_Ticket.user_list.append(user) 21 | Train_Ticket.ticket_list.append(tkt_bk) 22 | 23 | def Admin_SignUp(self): 24 | print'+-----------------------+' 25 | print' ENTER USER DETAILS ' 26 | print'+-----------------------+' 27 | 28 | name=raw_input("Enter your Name : ") 29 | mo_no=raw_input("Enter your Phone no. : ") 30 | add=raw_input("Enter your Address : ") 31 | email=raw_input("Enter your Email : ") 32 | print'' 33 | newkey=raw_input('Enter Username : ') 34 | newvalue=raw_input('Enter Password : ') 35 | admin[newkey]=newvalue 36 | 37 | Train_Ticket.Admin_list.append(User(name, add,mo_no,email)) 38 | pickle_out = open("AdminInfoList.pickle","wb") 39 | pickle.dump(Train_Ticket.Admin_list, pickle_out) 40 | pickle_out.close() 41 | 42 | pickle_out = open("Admindict.pickle","wb") 43 | pickle.dump(admin, pickle_out) 44 | pickle_out.close() 45 | 46 | def Cust_SignUp(self): 47 | print'+-----------------------+' 48 | print' ENTER USER DETAILS ' 49 | print'+-----------------------+' 50 | 51 | name=raw_input("Enter your Name : ") 52 | mo_no=raw_input("Enter your Phone no. : ") 53 | add=raw_input("Enter your Address : ") 54 | email=raw_input("Enter your Email : ") 55 | print'' 56 | newkey=raw_input('Enter Username : ') 57 | newvalue=raw_input('Enter Password : ') 58 | cust[newkey]=newvalue 59 | 60 | Train_Ticket.Cust_list.append(User(name, add,mo_no,email)) 61 | pickle_out = open("CustInfoList.pickle","wb") 62 | pickle.dump(Train_Ticket.Cust_list, pickle_out) 63 | pickle_out.close() 64 | 65 | pickle_out = open("custdict.pickle","wb") 66 | pickle.dump(cust, pickle_out) 67 | pickle_out.close() 68 | 69 | def Tc_SignUp(self): 70 | print'+-----------------------+' 71 | print' ENTER USER DETAILS ' 72 | print'+-----------------------+' 73 | name=raw_input("Enter your Name : ") 74 | mo_no=raw_input("Enter your Phone no. : ") 75 | add=raw_input("Enter your Address : ") 76 | email=raw_input("Enter your Email : ") 77 | print'' 78 | newkey=raw_input('Enter Username : ') 79 | newvalue=raw_input('Enter Password : ') 80 | tc[newkey]=newvalue 81 | 82 | Train_Ticket.Tc_list.append(User(name, add,mo_no,email)) 83 | pickle_out = open("TcInfoList.pickle","wb") 84 | pickle.dump(Train_Ticket.Tc_list, pickle_out) 85 | pickle_out.close() 86 | 87 | pickle_out = open("tcdict.pickle","wb") 88 | pickle.dump(tc, pickle_out) 89 | pickle_out.close() 90 | 91 | 92 | def ADlogin(self):#ADMIN LOG IN 93 | my_file = Path("admindict.pickle") 94 | if my_file.is_file():#it will check whether file is exists or not 95 | pickle_in = open("admindict.pickle","rb") 96 | admin = pickle.load(pickle_in) 97 | login_username=raw_input('Enter Username : ') 98 | login_password=raw_input('Enter Password : ') 99 | if admin.has_key(login_username): 100 | if admin[login_username]==login_password: 101 | while True: 102 | print'╔═[ADMIN]══════════════╗' 103 | print" 1.Add new Location." 104 | print" 2.Add new Route." 105 | print" 3.Manage Route." 106 | print" 0.Back." 107 | print'╚══════════════════════╝' 108 | 109 | choice=input('Enter Your Choice : ') 110 | 111 | if choice==1: 112 | print'+-----------------------+' 113 | print" CREATE NEW LOCATION " 114 | print'+-----------------------+' 115 | #pickle_out = open("locations.pickle","wb") 116 | #pickle.dump(Train_Ticket.loc_list, pickle_out) 117 | #pickle_out.close() 118 | loc=raw_input('Enter Your Choice : ') 119 | Train_Ticket.loc_list.append(loc) 120 | elif choice==2: 121 | #pickle_in = open("locations.pickle","rb") 122 | #Train_Ticket.loc_list = pickle.load(pickle_in) 123 | From=raw_input("Enter Source : ") 124 | to=raw_input("Enter Destination : ") 125 | if From in Train_Ticket.loc_list: 126 | if to in Train_Ticket.loc_list: 127 | train[From]=to 128 | pickle_out = open("Route.pickle","wb") 129 | pickle.dump(train, pickle_out) 130 | pickle_out.close() 131 | print"Route is added!!!" 132 | else: 133 | print'Invalid Destination!!!' 134 | else: 135 | print 'Invalid Source!!!' 136 | 137 | 138 | elif choice==3: 139 | print"Manage Route" 140 | while True: 141 | print'╔═[ADMIN]══════════════╗' 142 | print" 1.Delete Route." 143 | print" 2.Change Route." 144 | print" 0.Back." 145 | print'╚══════════════════════╝' 146 | choice=input('Enter Your Choice : ') 147 | 148 | if choice==1: 149 | From=raw_input("Enter Source : ") 150 | to=raw_input("Enter Destination : ") 151 | if train.has_key(From): 152 | if train[From]==to: 153 | del train[From] 154 | print"Successfully Removed!!!!" 155 | else: 156 | print"Invalid Destination!!!" 157 | else: 158 | print"Invalid Source!!!" 159 | elif choice==2: 160 | print'╔═[ADMIN]══════════════╗' 161 | print' 1.Update Source.' 162 | print' 2.Update Destination.' 163 | print' 0.Back.' 164 | print'╚══════════════════════╝' 165 | choice=input('Enter Your Choice : ') 166 | 167 | if choice==1: 168 | From=raw_input("Enter Source : ") 169 | to=raw_input("Enter Destination : ") 170 | if train.has_key(From): 171 | if train[From]==to: 172 | new_key=raw_input('Enter New Source :') 173 | train[new_key] = myDict.pop(From) 174 | print"Successfully Update!!!!" 175 | else: 176 | print"Invalid Destination!!!" 177 | else: 178 | print"Invalid Source!!!" 179 | 180 | elif choice==2: 181 | From=raw_input("Enter Source : ") 182 | to=raw_input(" Enter Destination : ") 183 | 184 | if train.has_key(From): 185 | if train[From]==to: 186 | new_value=raw_input('Enter New Destination :') 187 | train[From] = new_value 188 | print"Successfully Update!!!!" 189 | else: 190 | print"Invalid Destination!!!" 191 | else: 192 | print"Invalid Source!!!" 193 | elif choice==0: 194 | break 195 | 196 | elif choice==0: 197 | break 198 | elif choice==0: 199 | break 200 | else: 201 | print('Invalid username or password') 202 | 203 | else: 204 | print"Signup first!!!" 205 | 206 | 207 | 208 | def CUSlogin(self):#CUSTOMER LOG IN 209 | my_file = Path("custdict.pickle") 210 | if my_file.is_file():#it will check whether file is exists or not 211 | pickle_in = open("custdict.pickle","rb") 212 | cust = pickle.load(pickle_in) 213 | login_username=raw_input('Enter Username : ') 214 | login_password=raw_input('Enter Username : ') 215 | if cust.has_key(login_username): 216 | if cust[login_username]==login_password: 217 | 218 | while True: 219 | print'╔═[CUSTOMER]═══════════╗' 220 | print" 1.Book Ticket." 221 | print" 2.View History." 222 | print" 0.Back." 223 | print'╚══════════════════════╝' 224 | 225 | print'' 226 | choice=input('Enter Your Choice : ') 227 | print'' 228 | 229 | if choice==1: 230 | pickle_in = open("Route.pickle","rb") 231 | train = pickle.load(pickle_in) 232 | From=raw_input("Enter Source : ") 233 | to=raw_input("Enter Destination : ") 234 | if train.has_key(From): 235 | if train[From]==to: 236 | print('Train is available for given route') 237 | t.ticket_book() 238 | else: 239 | print('user entered the wrong input') 240 | else: 241 | print('train is not available for given route') 242 | 243 | elif choice==2: 244 | print'+-----------------------+' 245 | print" RECENT HISTORY " 246 | print'+-----------------------+' 247 | print t.ticket_list 248 | elif choice==0: 249 | break 250 | 251 | else: 252 | print('Invalid username or password') 253 | 254 | else: 255 | print"signup first!!!" 256 | 257 | 258 | 259 | 260 | def TClogin(self):#TICKET CHECKER LOG IN 261 | my_file = Path("tcdict.pickle") 262 | if my_file.is_file():#it will check whether file is exists or not 263 | pickle_in = open("tcdict.pickle","rb") 264 | tc = pickle.load(pickle_in) 265 | login_username=raw_input('Enter Username : ') 266 | login_password=raw_input('Enter Username : ') 267 | if tc.has_key(login_username): 268 | if tc[login_username]==login_password: 269 | 270 | while True: 271 | print'╔═[TC]═════════════════╗' 272 | print' 1.Check In Database.' 273 | print' 0.Back.' 274 | print'╚══════════════════════╝' 275 | 276 | print'' 277 | choice=input('Enter Your Choice : ') 278 | print'' 279 | 280 | if choice==1: 281 | print'+-----------------------+' 282 | print' CHECK IN DATABASE ' 283 | print'+-----------------------+' 284 | print'' 285 | pickle_in = open("pnr.pickle","rb") 286 | Train_Ticket.pnr = pickle.load(pickle_in) 287 | a=input('Enter PNR NO. : ') 288 | if a in Train_Ticket.pnr: 289 | print'+-----------------------+' 290 | print" TICKET DETAILS " 291 | print'+-----------------------+' 292 | pickle_in = open("ticket_list.pickle","rb") 293 | Train_Ticket.ticket_list = pickle.load(pickle_in) 294 | print Train_Ticket.ticket_list[0] 295 | else: 296 | print "Invalid PNR!!!" 297 | elif choice==0: 298 | break 299 | 300 | else: 301 | print('Invalid username or password') 302 | 303 | else: 304 | print"Signup first!!!" 305 | 306 | 307 | 308 | def ticket_book(self): 309 | print'+-----------------------+' 310 | print' RESERVATION FORM ' 311 | print'+-----------------------+' 312 | Class=raw_input('Enter Class : ') 313 | bdg_pt=raw_input('Enter Bording point : ') 314 | quota=raw_input('Enter Quota : ') 315 | 316 | Train_Ticket.ticket_list.append(TICKET_BOOK(Class, bdg_pt, quota)) 317 | pickle_out = open("ticket_list.pickle","wb") 318 | pickle.dump(Train_Ticket.ticket_list, pickle_out) 319 | pickle_out.close() 320 | 321 | 322 | qr = qrcode.QRCode( 323 | version = 1, 324 | error_correction = qrcode.constants.ERROR_CORRECT_H, 325 | box_size = 10, 326 | border = 4, 327 | ) 328 | x = randint(1000000000,10000000000)#random number 329 | Train_Ticket.pnr.append(x) 330 | pickle_out = open("pnr.pickle","wb") 331 | pickle.dump(Train_Ticket.pnr, pickle_out) 332 | pickle_out.close() 333 | # The data that you want to store 334 | data = ("PNR NO :: "+str(x)+"\t\n"+"CLASS :: "+Class+"\t\n"+"BOARDING PT :: "+bdg_pt+"\t\n"+"QUOTA :: "+quota) 335 | # Add data 336 | qr.add_data(data) 337 | qr.make(fit=True) 338 | 339 | img = qr.make_image() 340 | # Create an image from the QR Code instance 341 | name_img=raw_input("Name the file : ")#e.g. file.jpg 342 | img.save(name_img) 343 | 344 | 345 | 346 | 347 | admin = {} 348 | cust = {} 349 | tc = {} 350 | train = {} 351 | t=Train_Ticket() 352 | 353 | while True: 354 | 355 | print'╔═[Main Menu]══════════╗' 356 | print' 1.Admin Account.' 357 | print' 2.Customer Account.' 358 | print' 3.Ticket Checker.' 359 | print' 0.Exit.' 360 | print'╚══════════════════════╝' 361 | 362 | 363 | choice=input('Enter Your Choice : ') 364 | print'' 365 | 366 | if choice==1: 367 | while True: 368 | print'╔═[ADMIN]══════════════╗' 369 | print' 1.Log In.' 370 | print' 2.Sign up.' 371 | print' 0.Back.' 372 | print'╚══════════════════════╝' 373 | 374 | choice=input('Enter Your Choice : ') 375 | print'' 376 | if choice==1: 377 | t.ADlogin() 378 | elif choice==2: 379 | t.Admin_SignUp() 380 | elif choice==0: 381 | break 382 | 383 | elif choice==2: 384 | while True: 385 | print'╔═[CUSTOMER]═══════════╗' 386 | print' 1.Log In.' 387 | print' 2.Sign up.' 388 | print' 0.Back.' 389 | print'╚══════════════════════╝' 390 | 391 | choice=input('Enter Your Choice : ') 392 | print'' 393 | if choice==1: 394 | t.CUSlogin() 395 | elif choice==2: 396 | t.Cust_SignUp() 397 | elif choice==0: 398 | break 399 | 400 | elif choice==3: 401 | while True: 402 | print'╔═[TC]═════════════════╗' 403 | print' 1.Log In.' 404 | print' 2.Sign up.' 405 | print' 0.Back.' 406 | print'╚══════════════════════╝' 407 | 408 | choice=input('Enter Your Choice : ') 409 | print'' 410 | if choice==1: 411 | t.TClogin() 412 | elif choice==2: 413 | t.Tc_SignUp() 414 | elif choice==0: 415 | break 416 | 417 | elif choice==0: 418 | break 419 | 420 | 421 | --------------------------------------------------------------------------------