Skip to content

Instantly share code, notes, and snippets.

@Kahnix
Last active March 15, 2018 16:11
Show Gist options
  • Save Kahnix/1adf20435cfff29fae60634427525fc2 to your computer and use it in GitHub Desktop.
Save Kahnix/1adf20435cfff29fae60634427525fc2 to your computer and use it in GitHub Desktop.
Theatre Booking System
#!/usr/bin/env python3.6
import csv
def read_file(file):
"""Reads the CSV into an array"""
datatest = {}
with open(f"{file}",'r') as file_object:
filereader = csv.reader(file_object, delimiter=',', skipinitialspace=True)
for row in filereader:
datatest[row[0]]=row[1]
return datatest
def get_login_details():
"""Asks the user to enter email and password"""
email = input("Please enter your email and password : \n Email: ")
password = input(" Password: ")
return(email,password)
def display_login_screen():
"""Displays Login screen with username and password"""
print( """
-----------------\n
Theatre Booking\n
-----------------\n
1) Login
2) Quit
""")
validate_login()
def validate_login():
"""Validate the login"""
user_choice = "x"
while not (user_choice.isnumeric() and int(user_choice) > 0 and int(user_choice) < 3):
user_choice = input("Please enter 1 to Login and 2 to quit \n > ")
# Validation handles erroneous data allowing for else to equate to quit.
validate_user(user_choice)
def validate_user(user_choice):
""" Responsible for username and password validation """
if int(user_choice) == 1:
email,password = get_login_details()
datatest=read_file("users.csv")
while email not in datatest:
print("\n !Error! Please enter a valid email\n")
email,password = get_login_details()
account_accepted = False
account_password = datatest.get(email)
while password != account_password:
print("\n !Error! Password Incorrect\n")
password = get_login_details()
account_accepted = False
#Assume the account checks out otherwise
account_accepted = True
validate_seat(account_accepted)
elif int(user_choice) == 2:
exit()
def validate_seat(account_accepted):
while account_accepted == False:
print("Something went wrong, please log in again")
display_login_screen()
seats = draw_seats()
seats_wanted = int(input("Please enter the amount of seats you would like: " ))
row_wanted = input("Please enter the row you would like: ").upper()
row_E,row_D,row_C,row_B,row_A = (seats[0],seats[1],seats[2],seats[3],seats[4])
if row_wanted[0] == "E":
for i in range(0,seats_wanted):
row_E[i]=1
print(f"seats reserved in row E")
elif row_wanted[0] == "D":
for i in range(0,seats_wanted):
row_D[i]=1
print(f"seats reserved in row D")
elif row_wanted[0] == "C":
for i in range(0,seats_wanted):
row_C[i]=1
print(f"seats reserved in row C")
elif row_wanted[0] == "B":
for i in range(0,seats_wanted):
row_B[i]=1
print(f"seats reserved in row B")
elif row_wanted[0] == "A":
for i in range(0,seats_wanted):
row_A[i]=1
print(f"seats reserved in row A")
print(seats)
def draw_seats():
seats = [
[0,0,0,0,0,0,0,0,0,0],#Row E
[0,0,0,0,0,0,0,0,0,0],#Row D
[0,0,0,0,0,0,0,0,0,0],#Row C
[0,0,0,0,0,0,0,0,0,0],#Row B
[0,0,0,0,0,0,0,0,0,0] #Row A
]
return(seats)
def run_code(status):
if status == False:
exit()
while True:
display_login_screen()
run_code(True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment