-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBus Reservation System.py
More file actions
266 lines (237 loc) · 7.88 KB
/
Bus Reservation System.py
File metadata and controls
266 lines (237 loc) · 7.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
import pickle
import os
# Global ID
i_d = ''
def sign_up():
global i_d
try:
with open('customer_d.dat', 'ab+') as f:
f.seek(0)
i_d = input('Create id: ')
while True:
try:
l = pickle.load(f)
if i_d == l[0]:
i_d = input('ID already exists, create unique id *^* ')
f.seek(0)
except EOFError:
break
dob = input('Enter your date of birth(DD/MM/YYYY): ')
mb_no = int(input('Enter your mobile number: '))
e_mail = input('Enter your e-mail id: ')
pasw = input('Create password: ')
L = [i_d, dob, mb_no, e_mail, pasw]
with open('customer_d.dat', 'ab') as f:
pickle.dump(L, f)
print('\nId created successfully :)')
print('Logged in ;)\n')
except Exception as e:
print("Error during signup:", e)
def sign_in():
global i_d
i_d = input('Enter your id: ')
pas = input('Enter your password: ')
flag = 0
if i_d == 'admin@01' and pas == '30102005':
flag = 1
else:
try:
with open('customer_d.dat', 'rb') as f:
while True:
try:
l = pickle.load(f)
if i_d == l[0] and pas == l[4]:
flag = 1
break
elif l[0] == i_d and l[4] != pas:
flag = 2
print('Wrong password!!')
pas = input('Enter password again: ')
if l[4] == pas:
flag = 1
break
except EOFError:
break
except FileNotFoundError:
pass
if flag == 1:
print('\t\t\t***( Login Successful )***\n')
elif flag == 2:
print("Login Unsuccessful!!!\n")
else:
print('No id found :(')
print('Please sign up > ^ <')
sign_up()
def validate_date(date):
try:
d, m, y = map(int, date.split('/'))
m0 = [4, 6, 9, 11]
m1 = [1, 3, 5, 7, 8, 10, 12]
if y < 2022 or y > 2026 or m < 1 or m > 12 or d < 1:
return False
elif m == 2:
return d <= 28
elif m in m0:
return d <= 30
elif m in m1:
return d <= 31
return False
except:
return False
def write():
with open('Book_bus_.dat', 'ab') as f:
d = input('Departure from: ')
a = input('Arrival to: ')
bus_no = input('Enter bus number: ')
date = input('Enter the date of journey(DD/MM/YYYY): ')
while not validate_date(date):
print("Invalid date!")
date = input("Please enter valid date: ")
p_no = int(input('Enter number of passengers: '))
for _ in range(p_no):
name = input('Enter the name of passenger: ')
spcl = input('Is the passenger disabled or senior citizen? y/n: ')
global i_d
r = [i_d, d, a, bus_no, date, name, spcl]
pickle.dump(r, f)
print('Booking Successful :)')
def display():
global i_d
flag = 0
try:
with open('Book_bus_.dat', 'rb') as f:
while True:
l = pickle.load(f)
if l[0] == i_d:
print(l)
flag = 1
except EOFError:
if not flag:
print('\nNOTHING TO DISPLAY +_+')
def search_by_name():
name = input('Enter name you want to search: ')
flag = 0
try:
with open('Book_bus_.dat', 'rb') as f:
while True:
l = pickle.load(f)
if l[5] == name:
print(l)
flag = 1
except EOFError:
if not flag:
print('NO SUCH RECORD FOUND -_-')
def search_by_date():
date = input('Enter date you want to search(DD/MM/YYYY): ')
flag = 0
try:
with open('Book_bus_.dat', 'rb') as f:
while True:
l = pickle.load(f)
if l[4] == date:
print(l)
flag = 1
except EOFError:
if not flag:
print('NO SUCH RECORD FOUND -_-')
def update_date():
global i_d
bus = input('Enter bus number: ')
date = input('Enter date you want to update(DD/MM/YYYY): ')
date1 = input('Enter date to which you want to change it to(DD/MM/YYYY): ')
flag = 0
with open('Book_bus_.dat', 'r+b') as f:
try:
while True:
x = f.tell()
l = pickle.load(f)
if l[4] == date and l[3] == bus and l[0] == i_d:
l[4] = date1
f.seek(x)
pickle.dump(l, f)
flag = 1
except EOFError:
pass
if not flag:
print('NO SUCH RECORD FOUND!!! -_-')
else:
print('UPDATION DONE :)')
def delete():
global i_d
a = input('Drop single reservation or all for a day? (S/A): ').strip().lower()
with open('Book_bus_.dat', 'rb') as f, open('new.dat', 'wb') as f1:
flg = 0
try:
while True:
l = pickle.load(f)
if a == 's':
date = input('Enter date(DD/MM/YYYY): ')
bus = input('Enter bus number: ')
name = input('Enter name: ')
if l[0] == i_d and l[3] == bus and l[4] == date and l[5] == name:
flg = 1
else:
pickle.dump(l, f1)
elif a == 'a':
date = input('Enter date(DD/MM/YYYY): ')
bus = input('Enter bus number: ')
if l[0] == i_d and l[3] == bus and l[4] == date:
flg = 1
else:
pickle.dump(l, f1)
except EOFError:
pass
os.remove('Book_bus_.dat')
os.rename('new.dat', 'Book_bus_.dat')
if flg:
print('DELETION SUCCESSFUL :)')
else:
print('NO SUCH RECORD FOUND FOR DELETION *_*')
def display_all():
try:
with open('customer_d.dat', 'rb') as f:
while True:
l = pickle.load(f)
print(l)
except EOFError:
pass
# Main Menu
print('\t\t\t*********************************')
print('\t\t\t* ONLINE BUS RESERVATION SYSTEM *')
print('\t\t\t*********************************')
print('\t\t\t* WELCOME TO PSP BUSES *')
print('\t\t\t*********************************\n')
print('Please sign up/sign in\nPress 1 to sign up\nPress 2 to sign in')
s = int(input())
while s not in [1, 2]:
s = int(input('Enter valid choice: '))
if s == 1:
sign_up()
else:
sign_in()
if i_d == 'admin@01':
print('The details of our customers:-')
display_all()
else:
while True:
print('_____________________________________________')
print('1.Reserve seats\n2.Display all Bookings\n3.Search by name\n4.Search by date\n5.Update date\n6.Drop reservation\n0.Exit')
print('_____________________________________________')
c = int(input('Enter your choice: '))
print()
if c == 1:
write()
elif c == 2:
display()
elif c == 3:
search_by_name()
elif c == 4:
search_by_date()
elif c == 5:
update_date()
elif c == 6:
delete()
elif c == 0:
break
else:
print('Enter valid choice!!!')