-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
216 lines (185 loc) · 7.89 KB
/
main.py
File metadata and controls
216 lines (185 loc) · 7.89 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
# CMPUT 291 Mini-project 1
# Joe Heppelle: heppelle@ualberta.ca
# Ranajay Sarma: sarma@ualberta.ca
import sqlite3
import random
def start(c):
user_type = input("Welcome, select 'L' to login or 'S' to signup if you are a new user!")
if (user_type.lower() == 'l'):
print("Processing Log In...")
user_email = input("Please enter your email: ")
# verify email
# user_password = input("Please enter your password: ")
# verify password
return user_email
if (user_type.lower() == 's'):
print("Processing Sign up...")
new_user_email = input("Please enter sign up email: ")
# verify email, reprompt if email already exists.
# new_user_name = input("Please enter your name: ")
# new_user_phone = input("Please enter your phone number: ")
# new_user_password = input("Please enter password: ")
# insert new account information to the database
print("account created!")
return new_user_email
if (user_type == '0'):
return user_type
else:
print("Invalid input!")
return None
def print_messages(user_email):
# find new messages to this email.
# print all messages
# change statues
print("New messages while you were gone...")
# this is where the member tasks will be distrubuted
def offer_ride(user_email):
# TODO: implement type checking etc..
print("offering ride!")
date = input("Enter date: ")
seat_num = input("Enter number of seats: ")
seat_price = input("Enter price of seat: ")
lugg_desc = input("Enter luggage description: ")
source_location = input("Enter source location: ")
destination = input("Enter destination: ")
car_number = input("Enter car number: ")
# TODO: verify car number.
add_enroute = True
while add_enroute:
print("Search for a enroute location. (enter '0' to terminate search.)")
enroute = input("Enter keyword to search: ")
if enroute == '0':
break
else:
#TODO 3.1.1: Allow for location code.
#TODO 3.2.1: if keyword!=location code, display 5 matching locations.
#TODO 3.2.2: if there are more than 5 matching locations, display 5 at a time
#TODO 3.2.3: let the member chose out of the matching locations.
print("Searching for enroute locations...") # test purpose
rno_generate = True
while rno_generate:
rno = random.randint(0,100000)
# TODO: if rno already exists in database, keep generating new rnoself.
rno_generate = False # test purpose
# TODO 5.0: Set the member as the driver.
print("Ride offere created!...")
def search_ride(user_email):
# TODO: implement basic flow of the task
print("searching for a ride!")
keywords = [] # keywords to be searched.
add_keywords = True
search = True
while search:
while add_keywords:
keyword = input("Enter a keyword to search for a ride (enter '0' to finish adding keywords): ")
if keyword == '0':
break
keywords.append(keyword)
# TODO: 1.1.0: Return all rides which match the keywords.
# TODO: 1.1.1: if keywords match source location, destination, or enroute.
# TODO: 1.1.2: if city, province, or the address contains keyword as a substring.
# TODO: 1.2.0: Display all details of the matching rides (from rides table), and car details.
# TODO: 1.3.0: Display 5 rides at a time.
# TODO: 1.4.0: Provide options to see more rides if matches >5.
# TODO: 2.0: Allow user to select a ride from the rides provided.
# TODO: 3.0: Allow user to send a message to the member posting the ride to book a seat.
response = input("Make another search?(Y/N): ")
if response == 'N':
search = False
def view_booking(user_email):
# TODO: 1.0: Allow member to list all bookings on rides he offers/
# TODO: 1.0.0: Allow cancel of any of those bookings.
# TODO: 1.0.1: Send cancellation message to members who had booked that ride.
print("Viewing bookng details...")
def booking(user_email):
# TODO: implement basic flow of the task
# TODO: 2.0: Allow members to book rides.
# TODO:2.0.0: let member select a ride to book.
# TODO:2.0.1: let member enter his email
# TODO:2.0.2: let member enter the number of seats booked.
# TODO:2.0.3: let member enter cost/seat.
# TODO:2.0.4: let member enter pickup and dropoff location codes.
# TODO:2.0.6: Display warning if ride is overbooked (number of seats booked>number of seats offered)
# TODO:2.0.6.1: ask to confirm the overbooked ride.
# TODO:2.0.7: assign unique bno to the booking made.
# TODO:2.0.8: send message to member who is offering the ride, that this member is booked on the ride.
print("Booking a ride...")
def post_ride_request(user_email):
# TODO: implement basic flow of the task
date = input("Enter the date of the ride: ")
pickup_l = input("Enter the pickup location code: ")
dropoff_l = input("Enter the dropoff location code: ")
amount_per_seat = input("Enter the amount you are willing to pay per seat: ")
rid = random.randint(0,10000)
# TODO: check the rid doesnt exist in database
# TODO: 3.0: email of the requesting member is the email for the ride.
print("posting a ride request!")
def show_ride_request(user_email):
#TODO: 1.0: allow member to see his ride requests
#TODO: 2.0: allow member to delete any of them.
print("Showing ride requests")
def search_ride_request(user_email):
#TODO: 3.0: allow user to search for ride requests with pickup location(code or a city)
#TODO: 3.1: show 5 matches at a time.
#TODO: 3.2: allow user to select a request and message the posting member.
print("Searching for ride requests")
def ride_request(user_email):
# TODO: implement basic flow of the task
while (True):
command = input("Enter 'sh' to view your ride requests, or 's' to search for others ride requests: ")
if command == '0':
break
elif command.lower() == 'sh':
show_ride_request(user_email)
elif command.lower() == 's':
search_ride_request()
else:
print("Invalid option...")
print("searching for a ride request!")
def flow(user_email):
task = ""
while (True):
print("Select a task. 'O' to offer a ride, 'S' to search for a ride, 'book' to book a ride, 'vbook' to view booking details. 'P' to post ride requests, 'SR' for editing and searching ride requests.('0' to terminate program.)")
task = input("Enter task > ")
if (task.lower() == 'o'):
offer_ride(user_email)
elif (task.lower() == 's'):
search_ride(user_email)
elif (task.lower() == 'book'):
booking(user_email)
elif (task.lower() == 'vbook'):
view_booking(user_email)
elif (task.lower() == 'p'):
post_ride_request(user_email)
elif (task.lower() == 'sr'):
ride_request(user_email)
elif (task == '0'):
print("Terminating program...")
exit()
else:
print("invalid request.")
def main():
db = 'prj-tables.sql'
try:
conn = sqlite3.connect(db)
print("Connection to database succcessful.")
except:
print("Connection to database not established.")
c = conn.cursor()
user_email = start(c)
if (user_email == None):
print("Invalid email, terminating program...")
# conn.close()
exit()
elif (user_email == '0'):
print("Terminating program...")
# conn.close()
exit()
else:
print_messages(user_email)
# after login/signup and messages are displayed
user_email = "joeheppelle123@hotmail.com"
flow(user_email)
# conn.commit()
# conn.close()
main()