Commit 84d7b018 authored by Jasmin Jutila's avatar Jasmin Jutila
Browse files

Revert "Merge branch 'k' into 'master'"

This reverts merge request !2
parent 31c25718
from Reservation import *
from ReadingReservations import *
from ReadingCustomers import *
from WritingCustomers import *
from CreateCustomer import *
import Reservation
import ReadingReservations
import ReadingCustomers
from WritingReservations import *
import WritingReservations
import CreateCustomer
import datetime
import sys
import re
#Check customer input that is needed for a new reservation
def new_reservation_datainput():
#date of reservation
print("Which date would you like to reserve for? Enter the date in format 'ddmmyyyy' :")
print("Type date; format ddmmyyyy")
date = input()
day = date[0:2]
month = date[2:4]
year = date[6:8]
year_2 = date[4:8]
try: #check input valid
datetime.datetime(int(year),int(month),int(day)) #check input is a date overall
i = True
date_reservation = datetime.datetime(int(year_2),int(month),int(day))
date_today = datetime.datetime.today()
if date_reservation > date_today: #check input date is in the future
j = True
else:
j = False
except ValueError:
i = False
j = False
while i == False or j == False:
if j == False and i == False:
print("Input date is not valid. Try again.")
elif j == False and i == True:
print("Reservation date has to be in the future.")
else:
print("Input date is not valid. Try again.")
print("Enter the date in format 'ddmmyyyy' :")
date = input()
day = date[0:2]
month = date[2:4]
year = date[6:8]
year_2 = date[4:8]
try:
datetime.datetime(int(year),int(month),int(day))
i = True
date_reservation = datetime.datetime(int(year_2),int(month),int(day))
date_today = datetime.datetime.today()
if date_reservation > date_today:
j = True
else:
j = False
except ValueError:
i = False
j = False
#reservation time
print ("Enter reservation time; format hhmm (24h clock). Length of reservation is always 60 minutes. :")
while date not in range
print ("Type time; format hhmm (24h clock)")
time = input()
#not the smartest way to check input, but clear and simple
while time not in {'0700','0800','0900','1000','1100','1200','1300','1400','1500','1600','1700','1800','1900','2000','2100'}:
print("Invalid time. Reservation must start at even hours. Try again.")
print ("Type time; format hhmm (24h clock). Length of reservation is always 60 minutes.")
time = input()
# reservation length is predetermined, and is told to the customer in previous function
length = 60
#customer ID
print("Type your Customer id. If you don't have a customer id type 'no id' :")
print("Type length (in minutes)")
length = input()
print("Type Customer id")
id = input()
if id.isalpha() == True: #checking that id input is not a string
i = True
while i == True:
print("ID has to be a number. Try again. If you don't have a customer id type 'no id' :")
id = input()
if id.isalpha():
i = True
else:
i = False
if id == 'no id': #If customer doesn't yet have one
print("Do you want to add a new customer?")
vastaus_2 = input()
while vastaus_2 not in {"Yes", "No" }:
print("Please answer Yes or No.")
vastaus_2 = input()
if vastaus_2 == ("Yes"): #Creating a new customer account
new_customer = CreateCustomer.new_customer_datainput()
CreateCustomer.save_customer(new_customer)
id = new_customer.id
elif vastaus_2 == ("No"): #Rservation cannot be added without valid ID
print("Reservation cannot be added without Customer ID. Quitting reservation system. Please contact customer service")
sys.exit()
else:
if check_customer_id(id) == False:
j = True
else:
j = False
while j == False: #If customer id cannot be found from our customer database
print("The customer id is not in our database. Did you mean to write: "+id+"? ")
confirmation = input()
while confirmation not in {"Yes", "No"}:
print("Please answer Yes or No:")
confirmation = input()
if confirmation == ("Yes") : #Adding new customer
print("The customer id is not in our database. Do you want to add a new customer")
vastaus_2 = input()
while vastaus_2 not in {"Yes", "No"}:
print("Please answer Yes or No.")
vastaus_2 = input()
if vastaus_2 == ("Yes"):
new_customer = CreateCustomer.new_customer_datainput()
CreateCustomer.save_customer(new_customer)
id = new_customer.id
break
else:
print("Reservation cannot be added without Customer ID. Quitting reservation system. Please contact customer service")
sys.exit()
else:
print("Please rewrite your customer id, remember customer id is a number between 100-999:")
id = input()
if check_customer_id(id) == False:
j = True
break
else:
print("The customer id "+id+" is still not in our database. Please contact customer service or do you want to add a new customer?")
vastaus_2 = input()
while vastaus_2 not in {"Yes", "No"}:
print("Please answer Yes or No.")
vastaus_2 = input()
if vastaus_2 == ("Yes"):
new_customer = CreateCustomer.new_customer_datainput()
CreateCustomer.save_customer(new_customer)
id = new_customer.id
break
else:
print("Reservation cannot be added without Customer ID. Quitting reservation system. Please contact customer service")
sys.exit()
#Field
field = input("Which field would you like to reserve? (give field number):\n")
while field not in {'1','2','3','4','5'}:
print("Error. Insert field number between 1-5:")
field = input()
#saving all the data gathered
new_reservation = Reservation.Reservation(date,time,length,id,field)
Field = input("Which field would you like to reserve? (give field number)")
new_reservation = Reservation(date,time,length,id,Field)
return new_reservation
#Check availability of reservation, so are there previous reservations at the dame date, time and field
def check_availability(Reservation):
def check_availability(Reservation): #TÄLLÄ HETKELLÄ KAIKKI VARAUKSET SAMANPITUISIA
data = ReadingReservations.reading_reservations()
if len(data) == 0:
return True
for i in range(len(data)):
if int(data[i].date) == int(Reservation.date):
if int(data[i].time) == int(Reservation.time) and int(data[i].field) == int(Reservation.field):
if data[i].date == Reservation.date:
if data[i].time == Reservation.time and data[i].Field == Reservation.Field:
return False
else:
pass
else:
return True
#save reservation to an external csv file for safekeeping
else:
return True
def save_reservation(Reservation):
if check_availability(Reservation) is True:
WritingReservations.write_new_reservation(str(Reservation.date),str(Reservation.time),str(Reservation.length),str(Reservation.id),str(Reservation.field))
WritingReservations.write_new_reservation(str(Reservation.date),str(Reservation.time),str(Reservation.length),str(Reservation.id),str(Reservation.Field))
#Checking if customer id is in our database
def check_customer_id(id): #Palauttaa True jos ei löydy, False jos löytyy
data = ReadingCustomers.reading_customers()
if len(data) == 0:
return True
try:
for i in range(len(data)):
if int(id) == int(data[i].id):
return False
else:
return True
except ValueError:
return True
......
#Creating the customer class
class Customer():
def __init__(self,firstname,lastname,id,gender,email):
......
from Reservation import *
import csv
def reading_reservations():
try:
......
......@@ -2,12 +2,12 @@ import Customer
class Reservation():
def __init__(self,date,time,length,id,field):
def __init__(self,date,time,length,id,Field):
self.date = date
self.time = time
self.length = length
self.id = id
self.field = field
self.Field = Field
def get_date(self):
return self.date
......
......@@ -4,4 +4,5 @@ with open('fields.csv', 'w', newline='') as file:
writer.writerow([1, 60, 10])
writer.writerow([2, 100, 20])
writer.writerow([3, 20, 5])
\ No newline at end of file
import csv
import os
def write_new_reservation(date,time,length,id,field):
with open('reservations.csv', 'a', newline='') as file:
with open('reservations.csv', 'w', newline='') as file:
writer = csv.writer(file)
def write_new_reservation(date,time,length,id,Field):
with open('reservations.csv', 'w', newline='') as file:
writer = csv.writer(file)
writer.writerow([date, time, length, id, field])
file.flush()
os.fsync(file.fileno())
file.close()
writer.writerow([date, time, length, id, Field])
import csv
from Reservation import *
from Field import *
from idlelib import rstrip
import ReadingFields
from CreateReservation import *
import CreateReservation
import csv
fields = ReadingFields.reading_fields()
try:
file = open('reservations.csv')
file.close()
except FileNotFoundError:
with open("reservations.csv", "a") as f:
read_file = csv.writer(f)
try:
file_2 = open('customers.csv')
file_2.close()
except FileNotFoundError:
with open("customers.csv", "a") as f:
read_file = csv.writer(f)
response = input("Do you want to add new reservation?\n")
while response not in {"Yes", "No"}:
response = input("Please answer Yes or No: \n")
while response == "Yes":
response = input("Do you want to add new reservation?")
while response not in {"yes", "no"}:
response = input("Please enter yes or no: ")
while response == "yes":
new_reservation = CreateReservation.new_reservation_datainput()
if CreateReservation.check_availability(new_reservation) is True:
CreateReservation.save_reservation(new_reservation)
print("Reservation SUCCESFULL.")
response = input("Do you want to add another new reservation?\n")
while response not in {"Yes", "No"}:
response = input("Please enter Yes or No: ")
print("SUCCESS")
response = input("Do you want to add another new reservation?")
while response not in {"yes", "no"}:
response = input("Please enter yes or no: ")
else:
print("No availability. Reservation failed.")
response = input("Do you want to try a different date or time?\n")
while response not in {"Yes", "No"}:
response = input("Please enter yes or no: \n")
response = input("Do you want to try a different date or time?")
while response not in {"yes", "no"}:
response = input("Please enter yes or no: ")
else:
print("Ok. Reservation system will close")
quit()
print("Ok")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment