classes
Customer.py
class Customer:
cust_type=None
__orderdetails = []
def __init__(self):
self.__name = None
#self.__orderdetails = []
self.__city=None
self.__state=None
self.__area=None
self.__address=None
def get_city(self):
return self.__city
def get_state(self):
return self.__state
def get_area(self):
return self.__area
def get_address(self):
return self.__address
def set_city(self, value):
self.__city = value
def set_state(self, value):
self.__state = value
def set_area(self, value):
self.__area = value
def set_address(self, value):
self.__address = value
def get_name(self):
return self.__name
@staticmethod
def get_orderdetails():
return Customer.__orderdetails
def set_name(self, value):
self.__name = value
#print("*****",self.__name)
@staticmethod
def set_orderdetails(value):
Customer.__orderdetails.append(value)
------
Item.py
class Item:
def __init__(self):
self.__item_name =None
self.__item_category = None
self.__item_price = None
self.__item_availability = None
def get_item_name(self):
return self.__item_name
def get_item_category(self):
return self.__item_category
def get_item_price(self):
return self.__item_price
def get_item_availability(self):
return self.__item_availability
def set_item_name(self, value):
self.__item_name = value
def set_item_category(self, value):
self.__item_category = value
def set_item_price(self, value):
self.__item_price = value
def set_item_availability(self, value):
self.__item_availability = value
-------- Order.py
class Order:
def __init__(self,item_name,quantity,price,rid):
self.__item_name = item_name
self.__quantity = quantity
self.__price = price
self.__rid = rid
def get_rid(self):
return self.__rid
def set_rid(self, value):
self.__rid = value
def get_item_name(self):
return self.__item_name
def get_quantity(self):
return self.__quantity
def get_price(self):
return self.__price
def set_item_name(self, value):
self.__item_name = value
def set_quantity(self, value):
self.__quantity = value
def set_price(self, value):
self.__price = value
Restaurant.py
class Restaurant:
def __init__(self):
self.__rid = None
self.__restaurant_name = None
self.__item_list = []
self.__restaurant_type =None
self.__city=None
self.__area=None
self.__likes=None
self.__dislikes=None
self.__ratings=None
def get_rid(self):
return self.__rid
def get_likes(self):
return self.__likes
def get_dislikes(self):
return self.__dislikes
def set_rid(self, value):
self.__rid = value
def set_likes(self, value):
self.__likes = value
def set_dislikes(self, value):
self.__dislikes = value
def get_city(self):
return self.__city
def get_area(self):
return self.__area
def get_ratings(self):
return self.__ratings
def set_city(self, value):
self.__city = value
def set_area(self, value):
self.__area = value
def set_ratings(self, value):
self.__ratings = value
def get_restaurant_type(self):
return self.__restaurant_type
def set_restaurant_type(self, value):
self.__restaurant_type = value
def get_restaurant_name(self):
return self.__restaurant_name
def get_item_list(self):
return self.__item_list
def set_restaurant_name(self, value):
self.__restaurant_name = value
def set_item_list(self, value):
self.__item_list.append(value)
database folder
addbill.py
'''
Created on Mar 15, 2017
@author: s
'''
import utility.DBConnectivity
def add_bill(custid,rid):
con=utility.DBConnectivity.create_connection()
cur=utility.DBConnectivity.create_cursor(con)
cur.execute("insert into bill values('"+rid+"','"+custid+"')")
cur.close()
con.commit()
con.close()
-----
DisplayDetails.py
'''
Created on Mar 16, 2017
@author:s
'''
import classes.Customer
import classes.Restaurant
import utility.DBConnectivity
def display_restaurant():
con=utility.DBConnectivity.create_connection()
cur=utility.DBConnectivity.create_cursor(con)
cur.execute(" select * from (Select * from restaurant order by ratings desc) a where rownum<=5")
print("Hotel Name\tCity\tArea\tRatings\n")
r1=classes.Restaurant.Restaurant()
for value in cur:
r1.set_restaurant_name(value[1])
r1.set_city(value[7])
r1.set_area(value[6])
r1.set_ratings(value[5])
print(r1.get_restaurant_name(),end="\t")
print(r1.get_city(),end="\t")
print(r1.get_area(),end="\t")
print(r1.get_ratings())
cur.close()
con.close()
def display_customer():
con=utility.DBConnectivity.create_connection()
cur=utility.DBConnectivity.create_cursor(con)
cur.execute("Select username,area,city,state,address from customer where username in(select username from bill group by username having count(username)=(select max(count(username)) from bill group by username))")
print("CustomerName\tAddress\tArea\tCity\tState\n")
c1=classes.Customer.Customer()
for value in cur:
c1.set_name(value[0])
c1.set_area(value[1])
c1.set_city(value[2])
c1.set_state(value[3])
c1.set_address(value[4])
print(c1.get_name(),end="\t")
print(c1.get_address(),end="\t")
print(c1.get_area(),end="\t")
print(c1.get_city(),end="\t")
print(c1.get_state())
cur.close()
con.close()
def display_the_most_booked_hotel():
con=utility.DBConnectivity.create_connection()
cur=utility.DBConnectivity.create_cursor(con)
city=input("Enter City")
cur.execute("Select * from restaurant where rid in(select r.rid from bill b inner join restaurant r on b.rid=r.rid where r.rcity='"+city+"' group by r.rid,r.rcity having count(*)=(select max(count(r.rid)) from bill b inner join restaurant r on b.rid=r.rid where r.rcity='"+city+"' group by r.rid,r.rcity) )")
print("Hotel Name\tCity\tArea\tRatings\n")
r1=classes.Restaurant.Restaurant()
for value in cur:
r1.set_restaurant_name(value[1])
r1.set_city(value[7])
r1.set_area(value[6])
r1.set_ratings(value[5])
print(r1.get_restaurant_name(),end="\t")
print(r1.get_city(),end="\t")
print(r1.get_area(),end="\t")
print(r1.get_ratings())
cur.close()
con.close()
--------
ItemDB.py
from utility import DBConnectivity
from classes.Item import Item
def get_category(rname):
con=DBConnectivity.create_connection()
cur=DBConnectivity.create_cursor(con)
list_of_category=[]
rid = None
cur.execute("select distinct category,rid from item where rid=(select rid from restaurant where rname ='"+rname+"')"+" order by 1" )
#:rid",{"rid":rid})
for category,rid in cur:
list_of_category.append(category)
rid = rid
return [list_of_category,rid]
cur.close()
con.close()
def get_items(category,rid):
try:
con=DBConnectivity.create_connection()
cur=DBConnectivity.create_cursor(con)
list_of_items=[]
cur.execute("select category,item_name,availability,price from item where rid='"+rid+"' and category = '"+category+"'")
#:rid",{"rid":rid})
for category,item_name,availability,price in cur:
item = Item()
item.set_item_category(category)
item.set_item_price(price)
item.set_item_availability(availability)
item.set_item_name(item_name)
list_of_items.append(item)
return list_of_items
except Exception as e:
print(e)
finally:
cur.close()
con.close()
# get_items('Maharashtrian', 'R1009')
---------
RegistrationDB.py
import utility.DBConnectivity
def set_password(password1,user_name):
try:
con=utility.DBConnectivity.create_connection()
cur=utility.DBConnectivity.create_cursor(con)
cur.execute("update customer set password="+"'"+password1+"'" "where username="+"'"+user_name+"'")
return
finally:
cur.close()
con.commit()
con.close()
def validate_user1(user_name):
try:
con=utility.DBConnectivity.create_connection()
cur=utility.DBConnectivity.create_cursor(con)
cur.execute("select password,username from customer where username="+"'"+user_name+"'")
for password,username in cur:
#print(password)
return password
finally:
cur.close()
con.close()
def secretques(user_name):
try:
con=utility.DBConnectivity.create_connection()
cur=utility.DBConnectivity.create_cursor(con)
cur.execute("select username,secq from customer where username="+"'"+user_name+"'")
for username,secq in cur:
return secq
finally:
cur.close()
con.close()
def validate_secretques(user_name):
try:
con=utility.DBConnectivity.create_connection()
cur=utility.DBConnectivity.create_cursor(con)
cur.execute("select username,seca from customer where username="+"'"+user_name+"'")
for username,seca in cur:
return seca
finally:
cur.close()
con.close()
def validate_user2(name):
try:
con=utility.DBConnectivity.create_connection()
cur=utility.DBConnectivity.create_cursor(con)
cur.execute("select username,password from customer where username="+"'"+name+"'")
for username, password in cur:
if username==name:
return name
finally:
cur.close()
con.close()
def input_to_db(name,password,mailid,phno,secq,seca,area_name,city_name,state,address):
try:
con=utility.DBConnectivity.create_connection()
cur=utility.DBConnectivity.create_cursor(con)
cur.execute("insert into customer values("+"'"+str(name)+"'"+","+"'"+str(password)+"'"+","+"'"+str(mailid)+"'"+","+str(phno)+","+"'"+str(secq)+"'"+","+"'"+str(seca)+"'"+","+"'"+str(area_name)+"'"+","+"'"+str(city_name)+"'"+","+"'"+str(state)+"'"+","+"'"+str(address)+"'"+")" )
return
finally:
cur.close()
con.commit()
con.close()
# input_to_db("Shreya", "sdfsd", "dsgdg", 25848258, "sxgxd", "dgsbds", "hfbdfhd", "dgsd", "fhxhfh")
-----------
rest_and_itemcheck
'''
Created on Mar 15, 2017
@author: s
'''
import utility.DBConnectivity
def restaurant_name(rid):
con=utility.DBConnectivity.create_connection()
cur=utility.DBConnectivity.create_cursor(con)
cur.execute("Select rname from restaurant where rid='"+rid+"'")
rname=""
for value in cur:
rname=value
cur.close()
con.commit()
con.close()
return rname[0]
def item_check(rid,item_name):
con=utility.DBConnectivity.create_connection()
cur=utility.DBConnectivity.create_cursor(con)
cur.execute("Select 1 from item where rid='"+rid+"'and item_name='"+item_name+"' and availability='A'")
result=0
for value in cur:
result=value
cur.close()
con.commit()
con.close()
if result!=0:
return True
else:
return False
--------------
RestaurantDB.py
from utility import DBConnectivity
from classes.Restaurant import Restaurant
from classes.Customer import Customer
def get_city_area(cust):
try:
con=DBConnectivity.create_connection()
cur=DBConnectivity.create_cursor(con)
cur.execute("select city,area from customer where username = '"+cust.cust_type+"'")
for city1,area1 in cur:
# customer=Customer()
# customer.set_city(city1)
# customer.set_area(area1)
cust.set_city(city1)
print("city:",cust.get_city())
cust.set_area(area1)
print("area:",cust.get_area())
return cust
finally:
cur.close()
con.close()
def get_restaurant(city,area):
try:
con=DBConnectivity.create_connection()
cur=DBConnectivity.create_cursor(con)
list_of_restaurant=[]
#cur.execute("select rname,r_type,likes,dislikes,ratings from restaurant where rarea=:res_area and rcity=:res_city",{"res_area":area,"res_city":city})
cur.execute("select rname,r_type,likes,dislikes,ratings from restaurant where rarea='"+area+"' and rcity='"+city+"'")
for name,types,like,dlike,rate in cur:
restaurant=Restaurant()
restaurant.set_restaurant_name(name)
restaurant.set_restaurant_type(types)
restaurant.set_likes(like)
restaurant.set_dislikes(dlike)
restaurant.set_ratings(rate)
list_of_restaurant.append(restaurant)
return list_of_restaurant
finally:
cur.close()
con.close()
def get_restaurant_by_rating_type(city,area,num1,num2,ftype):
try:
con=DBConnectivity.create_connection()
cur=DBConnectivity.create_cursor(con)
list_of_restaurant_rating=[]
cur.execute("select rname,r_type,likes,dislikes,ratings from restaurant where rarea=:res_area and rcity=:res_city and ratings>=:r1 and ratings<=:r2 and r_type=:type",{"res_area":area,"res_city":city,"r1":num1,"r2":num2,"type":ftype})
for name,types,like,dlike,rate in cur:
rate_type_restaurant=Restaurant()
rate_type_restaurant.set_restaurant_name(name)
rate_type_restaurant.set_restaurant_type(types)
rate_type_restaurant.set_likes(like)
rate_type_restaurant.set_dislikes(dlike)
rate_type_restaurant.set_ratings(rate)
list_of_restaurant_rating.append(rate_type_restaurant)
return list_of_restaurant_rating
finally:
cur.close()
con.close()
def get_restaurant_by_type(city,area,ftype):
try:
con=DBConnectivity.create_connection()
cur=DBConnectivity.create_cursor(con)
list_of_restaurant_type=[]
cur.execute("select rname,r_type,likes,dislikes,ratings from restaurant where rarea=:res_area and rcity=:res_city and r_type=:type",{"res_area":area,"res_city":city,"type":ftype})
for name,types,like,dlike,rate in cur:
type_restaurant=Restaurant()
type_restaurant.set_restaurant_name(name)
type_restaurant.set_restaurant_type(types)
type_restaurant.set_likes(like)
type_restaurant.set_dislikes(dlike)
type_restaurant.set_ratings(rate)
list_of_restaurant_type.append(type_restaurant)
return list_of_restaurant_type
finally:
cur.close()
con.close()
def get_restaurant_by_rating(city,area,num1,num2):
try:
con=DBConnectivity.create_connection()
cur=DBConnectivity.create_cursor(con)
list_of_restaurant_rating=[]
cur.execute("select rname,r_type,likes,dislikes,ratings from restaurant where rarea=:res_area and rcity=:res_city and ratings>=:r1 and ratings<=:r2",{"res_area":area,"res_city":city,"r1":num1,"r2":num2})
for name,types,like,dlike,rate in cur:
rating_restaurant=Restaurant()
rating_restaurant.set_restaurant_name(name)
rating_restaurant.set_restaurant_type(types)
rating_restaurant.set_likes(like)
rating_restaurant.set_dislikes(dlike)
rating_restaurant.set_ratings(rate)
list_of_restaurant_rating.append(rating_restaurant)
return list_of_restaurant_rating
finally:
cur.close()
con.close()
def get_restaurant_by_likes(city,area):
try:
con=DBConnectivity.create_connection()
cur=DBConnectivity.create_cursor(con)
list_of_restaurant_rating=[]
cur.execute("select rname,r_type,likes,dislikes,ratings from restaurant where rarea=:res_area and rcity=:res_city order by likes desc",{"res_area":area,"res_city":city})
for name,types,like,dlike,rate in cur:
like_restaurant=Restaurant()
like_restaurant.set_restaurant_name(name)
like_restaurant.set_restaurant_type(types)
like_restaurant.set_likes(like)
like_restaurant.set_dislikes(dlike)
like_restaurant.set_ratings(rate)
list_of_restaurant_rating.append(like_restaurant)
return list_of_restaurant_rating
finally:
cur.close()
con.close()
def get_restaurant_by_dislikes(city,area):
try:
con=DBConnectivity.create_connection()
cur=DBConnectivity.create_cursor(con)
list_of_restaurant_rating=[]
cur.execute("select rname,r_type,likes,dislikes,ratings from restaurant where rarea=:res_area and rcity=:res_city order by dislikes",{"res_area":area,"res_city":city})
for name,types,like,dlike,rate in cur:
dlike_restaurant=Restaurant()
dlike_restaurant.set_restaurant_name(name)
dlike_restaurant.set_restaurant_type(types)
dlike_restaurant.set_likes(like)
dlike_restaurant.set_dislikes(dlike)
dlike_restaurant.set_ratings(rate)
list_of_restaurant_rating.append(dlike_restaurant)
return list_of_restaurant_rating
finally:
cur.close()
con.close()
def get_restaurant_by_rating_like_type(city,area,num1,num2,ftype):
try:
con=DBConnectivity.create_connection()
cur=DBConnectivity.create_cursor(con)
list_of_restaurant_rating=[]
cur.execute("select rname,r_type,likes,dislikes,ratings from restaurant where rarea=:res_area and rcity=:res_city and ratings>=:r1 and ratings<=:r2 and r_type=:type order by likes desc",{"res_area":area,"res_city":city,"r1":num1,"r2":num2,"type":ftype})
for name,types,like,dlike,rate in cur:
rate_like_type_restaurant=Restaurant()
rate_like_type_restaurant.set_restaurant_name(name)
rate_like_type_restaurant.set_restaurant_type(types)
rate_like_type_restaurant.set_likes(like)
rate_like_type_restaurant.set_dislikes(dlike)
rate_like_type_restaurant.set_ratings(rate)
list_of_restaurant_rating.append(rate_like_type_restaurant)
return list_of_restaurant_rating
finally:
cur.close()
con.close()
def get_restaurant_by_rating_dislike_type(city,area,num1,num2,ftype):
try:
con=DBConnectivity.create_connection()
cur=DBConnectivity.create_cursor(con)
list_of_restaurant_rating=[]
cur.execute("select rname,r_type,likes,dislikes,ratings from restaurant where rarea=:res_area and rcity=:res_city and ratings>:r1 and ratings<:r2 and r_type=:type order by dislikes ",{"res_area":area,"res_city":city,"r1":num1,"r2":num2,"type":ftype})
for name,types,like,dlike,rate in cur:
rate_like_type_restaurant=Restaurant()
rate_like_type_restaurant.set_restaurant_name(name)
rate_like_type_restaurant.set_restaurant_type(types)
rate_like_type_restaurant.set_likes(like)
rate_like_type_restaurant.set_dislikes(dlike)
rate_like_type_restaurant.set_ratings(rate)
list_of_restaurant_rating.append(rate_like_type_restaurant)
return list_of_restaurant_rating
finally:
cur.close()
con.close()
def get_restaurant_by_rating_like_dislike_type(city,area,num1,num2,ftype):
try:
con=DBConnectivity.create_connection()
cur=DBConnectivity.create_cursor(con)
list_of_restaurant_rating=[]
cur.execute("select rname,r_type,likes,dislikes,ratings from restaurant where rarea=:res_area and rcity=:res_city and ratings>=:r1 and ratings<=:r2 and r_type=:type order by likes desc,dislikes",{"res_area":area,"res_city":city,"r1":num1,"r2":num2,"type":ftype})
for name,types,like,dlike,rate in cur:
rate_like_type_restaurant=Restaurant()
rate_like_type_restaurant.set_restaurant_name(name)
rate_like_type_restaurant.set_restaurant_type(types)
rate_like_type_restaurant.set_likes(like)
rate_like_type_restaurant.set_dislikes(dlike)
rate_like_type_restaurant.set_ratings(rate)
list_of_restaurant_rating.append(rate_like_type_restaurant)
return list_of_restaurant_rating
finally:
cur.close()
con.close()
def get_restaurant_by_like_type(city,area,ftype):
try:
con=DBConnectivity.create_connection()
cur=DBConnectivity.create_cursor(con)
list_of_restaurant_rating=[]
cur.execute("select rname,r_type,likes,dislikes,ratings from restaurant where rarea=:res_area and rcity=:res_city and r_type=:type order by likes desc",{"res_area":area,"res_city":city,"type":ftype})
for name,types,like,dlike,rate in cur:
rate_like_type_restaurant=Restaurant()
rate_like_type_restaurant.set_restaurant_name(name)
rate_like_type_restaurant.set_restaurant_type(types)
rate_like_type_restaurant.set_likes(like)
rate_like_type_restaurant.set_dislikes(dlike)
rate_like_type_restaurant.set_ratings(rate)
list_of_restaurant_rating.append(rate_like_type_restaurant)
return list_of_restaurant_rating
finally:
cur.close()
con.close()
def get_restaurant_by_dislike_type(city,area,ftype):
try:
con=DBConnectivity.create_connection()
cur=DBConnectivity.create_cursor(con)
list_of_restaurant_rating=[]
cur.execute("select rname,r_type,likes,dislikes,ratings from restaurant where rarea=:res_area and rcity=:res_city and r_type=:type order by dislikes",{"res_area":area,"res_city":city,"type":ftype})
for name,types,like,dlike,rate in cur:
rate_like_type_restaurant=Restaurant()
rate_like_type_restaurant.set_restaurant_name(name)
rate_like_type_restaurant.set_restaurant_type(types)
rate_like_type_restaurant.set_likes(like)
rate_like_type_restaurant.set_dislikes(dlike)
rate_like_type_restaurant.set_ratings(rate)
list_of_restaurant_rating.append(rate_like_type_restaurant)
return list_of_restaurant_rating
finally:
cur.close()
con.close()
def get_restaurant_by_rating_like(city,area,num1,num2):
try:
con=DBConnectivity.create_connection()
cur=DBConnectivity.create_cursor(con)
list_of_restaurant_rating=[]
cur.execute("select rname,r_type,likes,dislikes,ratings from restaurant where rarea=:res_area and rcity=:res_city and ratings>=:r1 and ratings<=:r2 order by likes desc",{"res_area":area,"res_city":city,"r1":num1,"r2":num2})
for name,types,like,dlike,rate in cur:
rate_like_type_restaurant=Restaurant()
rate_like_type_restaurant.set_restaurant_name(name)
rate_like_type_restaurant.set_restaurant_type(types)
rate_like_type_restaurant.set_likes(like)
rate_like_type_restaurant.set_dislikes(dlike)
rate_like_type_restaurant.set_ratings(rate)
list_of_restaurant_rating.append(rate_like_type_restaurant)
return list_of_restaurant_rating
finally:
cur.close()
con.close()
def get_restaurant_by_rating_dislike(city,area,num1,num2):
try:
con=DBConnectivity.create_connection()
cur=DBConnectivity.create_cursor(con)
list_of_restaurant_rating=[]
cur.execute("select rname,r_type,likes,dislikes,ratings from restaurant where rarea=:res_area and rcity=:res_city and ratings>=:r1 and ratings<=:r2 order by dislikes",{"res_area":area,"res_city":city,"r1":num1,"r2":num2})
for name,types,like,dlike,rate in cur:
rate_like_type_restaurant=Restaurant()
rate_like_type_restaurant.set_restaurant_name(name)
rate_like_type_restaurant.set_restaurant_type(types)
rate_like_type_restaurant.set_likes(like)
rate_like_type_restaurant.set_dislikes(dlike)
rate_like_type_restaurant.set_ratings(rate)
list_of_restaurant_rating.append(rate_like_type_restaurant)
return list_of_restaurant_rating
finally:
cur.close()
con.close()
-------
update_rating_and_likes.py
'''
Created on Mar 15, 2017
@author: swapnil.mishra
'''
import utility.DBConnectivity
def update_rating_like(rid,rating,service):
con=utility.DBConnectivity.create_connection()
cur=utility.DBConnectivity.create_cursor(con)
cur.execute("select ratings from restaurant where rid='"+rid+"'")
avg_rating=0
for value in cur:
avg_rating=value[0]
rating=((avg_rating)+(rating))/2
cur.execute("update restaurant set ratings="+str(rating)+"where rid='"+rid+"'")
if(service=='y'):
cur.execute("Update restaurant set likes=likes+1 where rid='"+rid+"'")
else:
cur.execute("Update restaurant set dislikes=dislikes+1 where rid='"+rid+"'")
con.commit()
cur.close()
con.close()
---------
folder:exceptions
CalculateBillExceptions.py
class PaymentFailedException(Exception):
def __init__(self):
super().__init__("Payment Failed!!! Redirecting back to the main menu")
----
CustomeExceptions.py
class InvalidCityException(Exception):
def __init__(self):
super().__init__("The city is invalid")
class InvalidAreaException(Exception):
def __init__(self):
super().__init__("The Area is invalid")
# class InvalidCityAreaException(Exception):
# def __init__(self):
# super().__init__("The City and Area is invalid")
class InvalidRestaurantException(Exception):
def __init__(self):
super().__init__("The Restaurant name is invalid")
--------
Exceptions.py
class InvalidPasswordException(Exception):
def __init__(self):
super().__init__("Password is invalid.Please try combination of alphabets,digits and special characters\n Re-login")
class InvalidEmailException(Exception):
def __init__(self):
super().__init__("Emailid is invalid Re-login")
class InvalidPhnoException(Exception):
def __init__(self):
super().__init__("Invalid phno, Re-login")
---------
ItemExceptions.py
class InvalidRestaurantException(Exception):
def __init__(self):
super().__init__("The restaurant is invalid")
class InvalidCategoryException(Exception):
def __init__(self):
super().__init__("Invalid Category!!")
# class itemNotAvailableException(Exception):
# def __init__(self):
# super().__init__("Item not Available!!")
----------
folder:functionality
DisplayDetail.py
'''
Created on Mar 16, 2017
@author: swapnil.mishra
'''
import database.DisplayDetails
def display_detail():
choice='y'
while(choice=='y'):
print("a.Display the most rated hotel")
print("b.Display customer details")
print("c.Display city-wise hotel details")
choice=input("Enter choice")
if(choice in ["a","b","c"]):
if choice=="a":
database.DisplayDetails.display_restaurant()
elif choice=="b":
database.DisplayDetails.display_customer()
elif choice=="c":
database.DisplayDetails.display_the_most_booked_hotel()
choice=input("Do you wish to continue(y/n)?: ")
else:
print("Invalid Choice!! Enter the choice again")
return
-----------
CalculateBill.py
'''
Created on Mar 15, 2017
@author: swapnil.mishra
'''
import utility.DBConnectivity
import classes.Customer
import functionality.Registration
import database.addbill
import database.rest_and_itemcheck
import database.update_rating_and_likes
import validations.CardDetailValidation
from exceptions.CalculateBillExceptions import PaymentFailedException
def calculate_bill(cust=classes.Customer.Customer()):
if(cust.get_orderdetails()==[]):
print("Your cart is empty. Please select Items!")
return
else:
set_of_rest=[]
for item in cust.get_orderdetails():
set_of_rest.append(item.get_rid())
set_of_rest=set(set_of_rest)
print("Item Ordered:@",end="")
for rest in set_of_rest:
print(database.rest_and_itemcheck.restaurant_name(rest),end="|")
print("\nItem name \t\t Item Quantity")
total_price=0
discount_p=0
unavailable_items=[]
for order in cust.get_orderdetails():
print(order.get_item_name(),"\t\t",order.get_quantity())
for order in cust.get_orderdetails():
item_name=order.get_item_name()
if not(database.rest_and_itemcheck.item_check(order.get_rid(),item_name)):
unavailable_items.append(item_name)
else:
total_price+=order.get_quantity()*order.get_price()
if(len(unavailable_items)!=0):
string=""
for item in unavailable_items:
print(item," not available!!!!")
string+=item+","
choice=input("Do you wish to proceed to payment without "+string[0:-1]+"(y/n):")
else:
choice=input("Do you wish to proceed to payment(y/n)")
flag=False
while(flag==False):
if(choice in ['n','N']):
print("Payment Cancelled!! Redirecting back to the main menu")
return
elif(choice in ['Y','y']):
flag=True
else:
print("Incorrest choice!!!!! Kindly enter a valid choice ")
delivery_charge=0
choice=input("Dine-In/Door Delivery(i/d): ")
choice=choice.lower()
if(choice=="d"):
delivery_charge=50
print("Item name \t\t Item Quantity\t\t Item Price\t\t Total Price")
for order in cust.get_orderdetails():
item_name=order.get_item_name()
if not(database.rest_and_itemcheck.item_check(order.get_rid(),item_name)):
pass
else:
print(order.get_item_name(),"\t\t",order.get_quantity(),"\t\t\t",order.get_price(),"\t\t\t",order.get_quantity()*order.get_price())
print("Delivery Charge: ",delivery_charge)
if not(classes.Customer.Customer.cust_type==None):
discount_p=5
print("Discount: ",discount_p*total_price/100)
total_price-=discount_p*total_price/100
total_price+=delivery_charge
print("Total Amount to be paid: ",total_price," Rs.")
if(payment_portal()):
if not(classes.Customer.Customer.cust_type==None):
print("Customer Data added into the billing table")
for rid in set_of_rest:
database.addbill.add_bill(classes.Customer.Customer.cust_type,rid)
print("Restaurant",database.rest_and_itemcheck.restaurant_name(rid))
rating=input("Enter rating: ")
rating=[float(rating.strip(' "'))][0]
while(rating>10 or rating<0):
print("Rating Invalid!!! Rating should be between 0 and 10")
rating=input("Enter rating again: ")
rating=[float(rating.strip(' "'))][0]
service=input("Did you like the service(y/n):")
service=service.lower()
while(service not in ['y','n']):
service=input("Enter a valid choice.\nDid you like the service(y/n)?:")
service=service.lower()
database.update_rating_and_likes.update_rating_like(rid, rating, service)
print("Restaurant service and rating updated!! Redirecting back to the menu!!")
classes.Customer.Customer.set_orderdetails([])
def payment_portal():
try:
card_no=""
print("Welcome to the Payment Portal")
choice=input("Payment option:(card/cash): ")
flag=False
while(flag==False):
if(choice.lower() in ['cash','card']):
flag=True
else:
print("Kindly Select the correct payment mode")
choice=input("Payment option:(card/cash): ")
if(choice.lower()=="cash"):
print("Amount paid Successfully")
return True
elif(choice.lower()=="card"):
cardstatus=False
payment_status=False
choice='y'
while(cardstatus==False and choice=='y'):
cardstatus=True
print("Enter card details:")
card_no=input("Enter 16 digit Card Number")
exp_date=input("Enter expiry date(MM/YYYY)")
cvv=input("Enter CVV")
name=input("Enter name")
if not(validations.CardDetailValidation.card_detail_validation(card_no,cvv,exp_date,name)):
cardstatus=False
choice=input("Do you wish to continue(y/n): ")
else:
choice='n'
payment_status=True
if(cardstatus==True and payment_status==True):
print("Card is Valid!!")
print("Amount payment successful!!")
return True
else:
raise PaymentFailedException
except PaymentFailedException as e:
print(e)
----------
ItemSearch.py
from classes.Customer import Customer
from classes.OrderDetails import Order
import database.ItemDB
from validations.ItemValidation import categoryValidation
from validations.ItemValidation import itemAvailabilityValidation
from validations.ViewValidations import validate_restaurant
from validations.ItemValidation import restaurantValidation
import functionality.CalculateBill
order_details = []
def displayRestaurantName(rname=None,customer=None):
if rname == None:
flag = 1
while flag==1 :
rname = input("Enter restaurant name:")
if validate_restaurant(rname):
flag = 0
# else:
# print("Invalid Restaurant Name!!")
if customer == None:
customer = Customer()
displayCategory(rname,customer)
return
def displayCategory(rname,customer):
#list_of_category = database.ItemDB.get_category(rname)
list_of_category = restaurantValidation(rname)
'''
list_of_category[0] = category_list
list_of_category[1] = rid
'''
print("\nAvailable Category:")
rid = list_of_category[1]
#print(rid)
category_dict = {}
count = 1
for item in list_of_category[0]:
category_dict.update({count:item})
# print(str(count)+". "+item)
count += 1
for key,value in category_dict.items():
print(str(key)+". "+value)
'''
SELECTING A CATEGORY
'''
list_of_items = None
while list_of_items == None :
option = input("\nPlease select a category")
if option not in str(category_dict.keys()):
print("Invalid Category!!")
list_of_items = None
else:
category = category_dict[int(option)]
list_of_items = categoryValidation(category,rid,rname)
'''
DISPLAYING ITEM LIST
'''
print("\nItemname\tAvailability\tPrice")
for item in list_of_items:
print(item.get_item_name(),"\t",item.get_item_availability()+"\t\t"+str(item.get_item_price()))
'''
ITEM SELECTION
'''
flag = 1
while(flag == 1):
selected_items = input("Select Items : ")
selected_item_list = selected_items.split(",")
selected_items = []
flag = 0
for item_name in selected_item_list:
item = itemAvailabilityValidation(item_name, list_of_items)
if item == None:
flag = 1
print("Item not Available.")
break
else:
selected_items.append(item)
flag = 0
while flag == 0:
quantity = input("Quantity Required :")
quantity_list = quantity.split(",")
#if itemQuantityValidation(quantity_list,selected_items) == True:
if len(quantity_list) == len(selected_items):
flag = 1
else:
print("Invalid Quantity!!. Enter required number of quantity.")
print("Items added successfully to cart !!")
addToCart(selected_items,quantity_list,customer,rid,rname)
return
def addToCart(selected_items,quantity_list,customer,rid,rname):
print("\nItem Ordered")
print("ItemName \tQuantity")
global order_details
for i in range(len(selected_items)):
order = Order(selected_items[i].get_item_name(),int(quantity_list[i]),selected_items[i].get_item_price(),rid)
order_details.append(order)
print(order.get_item_name(),"\t",order.get_quantity())
flag = 0
while flag == 0 :
option = input("\nDo you wish to continue to billing or Cancelling any item or Save for later ?? (B/C/S)")
if option.upper() == "B" :
get_bill(customer)
flag = 1
elif option.upper()== "C" :
cancelItems(customer)
elif option.upper() == "S" :
# global order_details
item_cart = order_details
save_for_later(customer)
flag = 1
return
def get_bill(customer):
global order_details
for order in order_details:
customer.set_orderdetails(order)
functionality.CalculateBill.calculate_bill(customer)
#CalculateBill.calculate_bill(customer)
def cancelItems(customer):
item_to_cancel = input("Items to cancel")
item_to_cancel = item_to_cancel.split(",")
global order_details
for item_name in item_to_cancel:
for order in order_details:
if order.get_item_name() == item_name:
order_details.remove(order)
# for order in customer_orders:
# customer.set_orderdetails(order)
def save_for_later(customer):
global order_details
for order in order_details:
customer.set_orderdetails(order)
order_details = []
print("Items saved successfully !!!")
#displayRestaurantName()
---------
Registration.py
import functionality.SearchRestaurant
# import re
import classes.Customer
from database.RegistrationDB import validate_user1, validate_secretques, validate_user2, secretques, input_to_db,set_password
#import validations
from validations.ViewValidations import validate_email, validate_password,validate_phno
from classes import Customer
def registration():
print("a. Guest")
print("b. Registered User")
print("c. New User")
option=input()
if option=='a':
reg1()
elif option=='b':
reg2()
elif option=='c':
reg3()
else:
print("Please enter a valid option (a,b,c)")
def reg1():
print("You are not eligible for any discounts")
cust = classes.Customer.Customer()
functionality.SearchRestaurant.search(cust)
def reg2():
cust = classes.Customer.Customer()
user_name=input("Enter the username:")
password=input("Enter the password:")
value=validate_user1(user_name)
# print("---------",value)
if password==value:
Customer.Customer.cust_type=user_name
cust.set_name(user_name)
functionality.SearchRestaurant.search(cust)
else:
var=input("Reenter password or Forgot password? (R/F)")
if var=='R':
reg2()
elif var=='F':
var1=secretques(user_name)
print(var1)
ans=input()
value1=validate_secretques(user_name)
if ans==value1:
end=False
while(end==False):
password1=input("Enter the Password:")
if validate_password(password1):
password2=input("Confirm password:")
if password1==password2:
end=True
set_password(password1,user_name)
reg2()
else:
print("Password doesnot match, login again")
reg2()
else:
reg2()
cust = classes.Customer.Customer.set_name(user_name)
functionality.SearchRestaurant.search(cust)
else:
print("Answer does not match login again")
reg2()
else:
print("Invalid entry, Please choose a correct option")
reg2()
def reg3():
name=input("Enter the username:")
value2=validate_user2(name)
if value2==name:
print("User name already exists!!!")
print("Enter different user name")
reg3()
else:
mailid=input("Email id:")
if validate_email(mailid):
phno=input("Mobile number:")
if validate_phno(phno):
password2=input("Enter the password:")
if validate_password(password2):
password=input("Confirm password:")
if password2==password:
secq=input("Secret question:")
seca=input("Answer:")
city_name=input("City name:")
area_name=input("Area name")
state=input("State")
address=input('Address')
print("Registration Successfull!!!")
input_to_db(name,password,mailid,phno,secq,seca,area_name,city_name,state,address)
reg2()
else:
print("Password does not match Reenter the password")
reg3()
else:
reg3()
else:
reg3()
else:
reg3()
# reg1()
-----------
SearchRestaurant.py
from database import RestaurantDB
from functionality.ItemSearch import *
from exceptions.CustomException import InvalidCityException
from exceptions.CustomException import InvalidAreaException
from validations import ViewValidations
#from validations.ViewValidations import validate_area, validate_city,\
# validate_restaurant
from validations.ViewValidations import validate_area,validate_city,validate_restaurant
import classes
import functionality
def search(cust):
city=''
area=''
if(cust.get_name()==None):
city=input("enter city:")
if validate_city(city):
area=input("enter area:")
if validate_area(area):
displayRestaurants(city,area,cust)
else:
customer=RestaurantDB.get_city_area(cust)
city=customer.get_city()
area=customer.get_area()
displayRestaurants(city,area,customer)
def displayRestaurants(city,area,cust):
restaurant_list=[]
restaurant_list=(RestaurantDB.get_restaurant(city,area))
print("\nRestaurant\t\tType\t\tLikes\t\tDislikes\tRatings")
for i in restaurant_list:
print(i.get_restaurant_name(),"\t\t",i.get_restaurant_type(),"\t\t",str(i.get_likes()),"\t\t",str(i.get_dislikes()),"\t\t",str(i.get_ratings()))
filters=(input("\nDo you wish to filter or select restaurant?(F/S)"))
if(filters.upper()=="S"):
rname=input("Enter restaurant name:")
if validate_restaurant(rname):
functionality.ItemSearch.displayRestaurantName(rname,cust)
elif(filters.upper()=="F"):
fbased=(input("filter based on:"))
if(fbased.lower()=="ratings"):
displayRestaurantRating(city,area,cust)
elif(fbased.lower()=="type of food"):
displayRestaurantType(city, area, cust)
elif(fbased.lower()=="likes"):
displayRestaurantLike(city, area, cust)
elif(fbased.lower()=="dislikes"):
displayRestaurantDislike(city, area, cust)
elif(fbased.lower()=="type of food,ratings"):
displayRestaurantTypeRating(city, area,cust,fbased)
elif(fbased.lower()=="type of food,likes"):
displayRestaurantTypeLike(city, area,cust,fbased)
elif(fbased.lower()=="type of food,dislikes"):
displayRestaurantTypeDislikes(city, area, cust,fbased)
elif(fbased.lower()=="likes,ratings"):
displayRestaurantLikeRating(city,area,cust,fbased)
elif(fbased.lower()=="dislikes,ratings"):
displayRestaurantDislikeRating(city,area,cust,fbased)
elif(fbased.lower()=="type of food,likes,ratings"):
displayRestaurantTypeLikesRating(city,area,cust,fbased)
elif(fbased.lower()=="type of food,dislikes,ratings"):
displayRestaurantTypeDislikesRating(city,area,cust,fbased)
elif(fbased.lower()=="type of food,likes,dislikes,ratings"):
displayRestaurantTypeLikeDislikesRating(city,area,cust,fbased)
else:
print("Try filters based on type of food,likes,dislikes,ratings \nSelect from filter in the above order")
displayRestaurants(city,area,cust)
else:
print("Invalid choice.. Enter again")
displayRestaurants(city,area,cust)
def displayRestaurantRating(city,area,cust):
frange=input("Provide rating range:")
num=[]
num=frange.split("-")
restaurant_list_rate=[]
restaurant_list_rate=RestaurantDB.get_restaurant_by_rating(city,area,num[0],num[1])
for i in restaurant_list_rate:
print(i.get_restaurant_name(),"\t\t",i.get_restaurant_type(),"\t\t",i.get_likes(),"\t\t",i.get_dislikes(),"\t\t",i.get_ratings())
menu=input("\nDo you wish to select restaurant or go back to previous menu?(S/P)")
if(menu.lower()=='s'):
rname=input("Enter restaurant name:")
if validate_restaurant(rname):
functionality.ItemSearch.displayRestaurantName(rname,cust)
elif(menu.lower()=="p"):
displayRestaurants(city, area, cust)
def displayRestaurantType(city,area,cust):
ftype=input("Enter food type:")
restaurant_list_type=[]
restaurant_list_type=RestaurantDB.get_restaurant_by_type(city,area,ftype)
for i in restaurant_list_type:
print(i.get_restaurant_name(),"\t\t",i.get_restaurant_type(),"\t\t",i.get_likes(),"\t\t",i.get_dislikes(),"\t\t",i.get_ratings())
menu=input("\nDo you wish to select restaurant or go back to previous menu?(S/P)")
if(menu.lower()=='s'):
rname=input("Enter restaurant name:")
if validate_restaurant(rname):
functionality.ItemSearch.displayRestaurantName(rname,cust)
elif(menu.lower()=="p"):
displayRestaurants(city, area, cust)
def displayRestaurantLike(city,area,cust):
restaurant_list_like=[]
restaurant_list_like=RestaurantDB.get_restaurant_by_likes(city, area)
for i in restaurant_list_like:
print(i.get_restaurant_name(),"\t\t",i.get_restaurant_type(),"\t\t",i.get_likes(),"\t\t",i.get_dislikes(),"\t\t",i.get_ratings())
menu=input("\nDo you wish to select restaurant or go back to previous menu?(S/P)")
if(menu.lower()=='s'):
rname=input("Enter restaurant name:")
if validate_restaurant(rname):
functionality.ItemSearch.displayRestaurantName(rname,cust)
elif(menu.lower()=="p"):
displayRestaurants(city, area, cust)
def displayRestaurantDislike(city,area,cust):
restaurant_list_like=[]
restaurant_list_like=RestaurantDB.get_restaurant_by_dislikes(city, area)
for i in restaurant_list_like:
print(i.get_restaurant_name(),"\t\t",i.get_restaurant_type(),"\t\t",i.get_likes(),"\t\t",i.get_dislikes(),"\t\t",i.get_ratings())
menu=input("\nDo you wish to select restaurant or go back to previous menu?(S/P)")
if(menu.lower()=='s'):
rname=input("Enter restaurant name:")
if validate_restaurant(rname):
functionality.ItemSearch.displayRestaurantName(rname,cust)
elif(menu.lower()=="p"):
displayRestaurants(city, area, cust)
def displayRestaurantTypeRating(city,area,cust,fbased):
value=[]
num=[]
value=fbased.split(",")
if(value[0].lower()=="type of food" and value[1].lower()=="ratings"):
ftype=input("Enter food type:")
frange=input("provide rating range:")
num=frange.split("-")
restaurant_list_typerate=[]
restaurant_list_typerate=RestaurantDB.get_restaurant_by_rating_type(city, area, num[0], num[1], ftype)
for i in restaurant_list_typerate:
print(i.get_restaurant_name(),"\t\t",i.get_restaurant_type(),"\t\t",i.get_likes(),"\t\t",i.get_dislikes(),"\t\t",i.get_ratings())
menu=input("\nDo you wish to select restaurant or go back to previous menu?(S/P)")
if(menu.lower()=='s'):
rname=input("Enter restaurant name:")
if validate_restaurant(rname):
functionality.ItemSearch.displayRestaurantName(rname,cust)
elif(menu.lower()=="p"):
displayRestaurants(city, area, cust)
def displayRestaurantTypeLike(city, area,cust,fbased):
value=[]
value=fbased.split(",")
if(value[0].lower()=="type of food"):
ftype=input("Enter food type:")
restaurant_list_type=[]
restaurant_list_type=RestaurantDB.get_restaurant_by_like_type(city,area,ftype)
for i in restaurant_list_type:
print(i.get_restaurant_name(),"\t\t",i.get_restaurant_type(),"\t\t",i.get_likes(),"\t\t",i.get_dislikes(),"\t\t",i.get_ratings())
menu=input("\nDo you wish to select restaurant or go back to previous menu?(S/P)")
if(menu.lower()=='s'):
rname=input("Enter restaurant name:")
if validate_restaurant(rname):
functionality.ItemSearch.displayRestaurantName(rname,cust)
elif(menu.lower()=="p"):
displayRestaurants(city, area, cust)
def displayRestaurantTypeDislikes(city,area,cust,fbased):
value=[]
value=fbased.split(",")
if(value[0].lower()=="type of food"):
ftype=input("Enter food type:")
restaurant_list_type=[]
restaurant_list_type=RestaurantDB.get_restaurant_by_dislike_type(city,area,ftype)
for i in restaurant_list_type:
print(i.get_restaurant_name(),"\t\t",i.get_restaurant_type(),"\t\t",i.get_likes(),"\t\t",i.get_dislikes(),"\t\t",i.get_ratings())
menu=input("\nDo you wish to select restaurant or go back to previous menu?(S/P)")
if(menu.lower()=='s'):
rname=input("Enter restaurant name:")
if validate_restaurant(rname):
functionality.ItemSearch.displayRestaurantName(rname,cust)
elif(menu.lower()=="p"):
displayRestaurants(city, area, cust)
def displayRestaurantLikeRating(city,area,cust,fbased):
value=[]
num=[]
value=fbased.split(",")
if(value[1].lower()=="ratings"):
frange=input("provide rating range:")
num=frange.split("-")
restaurant_list_rate=[]
restaurant_list_rate=RestaurantDB.get_restaurant_by_rating_like(city,area,num[0],num[1])
for i in restaurant_list_rate:
print(i.get_restaurant_name(),"\t\t",i.get_restaurant_type(),"\t\t",i.get_likes(),"\t\t",i.get_dislikes(),"\t\t",i.get_ratings())
menu=input("\nDo you wish to select restaurant or go back to previous menu?(S/P)")
if(menu.lower()=='s'):
rname=input("Enter restaurant name:")
if validate_restaurant(rname):
functionality.ItemSearch.displayRestaurantName(rname,cust)
elif(menu.lower()=="p"):
displayRestaurants(city, area, cust)
def displayRestaurantDislikeRating(city,area,cust,fbased):
value=[]
num=[]
value=fbased.split(",")
if(value[1].lower()=="ratings"):
frange=input("provide rating range:")
num=frange.split("-")
restaurant_list_rate=[]
restaurant_list_rate=RestaurantDB.get_restaurant_by_rating_dislike(city,area,num[0],num[1])
for i in restaurant_list_rate:
print(i.get_restaurant_name(),"\t\t",i.get_restaurant_type(),"\t\t",i.get_likes(),"\t\t",i.get_dislikes(),"\t\t",i.get_ratings())
menu=input("\nDo you wish to select restaurant or go back to previous menu?(S/P)")
if(menu.lower()=='s'):
rname=input("Enter restaurant name:")
if validate_restaurant(rname):
functionality.ItemSearch.displayRestaurantName(rname,cust)
elif(menu.lower()=="p"):
displayRestaurants(city, area, cust)
def displayRestaurantTypeLikesRating(city,area,cust,fbased):
value=[]
num=[]
value=fbased.split(",")
if(value[0].lower()=="type of food" and value[2].lower()=="ratings"):
ftype=input("Enter food type:")
frange=input("provide rating range:")
num=frange.split("-")
restaurant_list_typerate=[]
restaurant_list_typerate=RestaurantDB.get_restaurant_by_rating_like_type(city, area, num[0],num[1], ftype)
for i in restaurant_list_typerate:
print(i.get_restaurant_name(),"\t\t",i.get_restaurant_type(),"\t\t",i.get_likes(),"\t\t",i.get_dislikes(),"\t\t",i.get_ratings())
menu=input("\nDo you wish to select restaurant or go back to previous menu?(S/P)")
if(menu.lower()=='s'):
rname=input("Enter restaurant name:")
if validate_restaurant(rname):
functionality.ItemSearch.displayRestaurantName(rname,cust)
elif(menu.lower()=="p"):
displayRestaurants(city, area, cust)
def displayRestaurantTypeDislikesRating(city,area,cust,fbased):
value=[]
num=[]
value=fbased.split(",")
if(value[0].lower()=="type of food" and value[2].lower()=="ratings"):
ftype=input("Enter food type:")
frange=input("provide rating range:")
num=frange.split("-")
restaurant_list_typerate=[]
restaurant_list_typerate=RestaurantDB.get_restaurant_by_rating_dislike_type(city, area, num[0],num[1], ftype)
for i in restaurant_list_typerate:
print(i.get_restaurant_name(),"\t\t",i.get_restaurant_type(),"\t\t",i.get_likes(),"\t\t",i.get_dislikes(),"\t\t",i.get_ratings())
menu=input("\nDo you wish to select restaurant or go back to previous menu?(S/P)")
if(menu.lower()=='s'):
rname=input("Enter restaurant name:")
if validate_restaurant(rname):
functionality.ItemSearch.displayRestaurantName(rname,cust)
elif(menu.lower()=="p"):
displayRestaurants(city, area, cust)
def displayRestaurantTypeLikeDislikesRating(city,area,cust,fbased):
value=[]
num=[]
value=fbased.split(",")
if(value[0].lower()=="type of food" and value[3].lower()=="ratings"):
ftype=input("Enter food type:")
frange=input("provide rating range:")
num=frange.split("-")
restaurant_list_typerate=[]
restaurant_list_typerate=RestaurantDB.get_restaurant_by_rating_like_dislike_type(city, area, num[0],num[1], ftype)
for i in restaurant_list_typerate:
print(i.get_restaurant_name(),"\t\t",i.get_restaurant_type(),"\t\t",i.get_likes(),"\t\t",i.get_dislikes(),"\t\t",i.get_ratings())
menu=input("\nDo you wish to select restaurant or go back to previous menu?(S/P)")
if(menu.lower()=='s'):
rname=input("Enter restaurant name:")
if validate_restaurant(rname):
functionality.ItemSearch.displayRestaurantName(rname,cust)
elif(menu.lower()=="p"):
displayRestaurants(city, area, cust)
# cust = classes.Customer.Customer()
# displayRestaurants('Mysore', 'Hebbal', cust)
#
-----
utility
DBConnectivity.py
'''
Created on Mar 9, 2017
@author: Anbarasi.Ayyannan
'''
import cx_Oracle
def create_connection():
return cx_Oracle.Connection('T753845/T753845@10.123.79.60/Georli05')
def create_cursor(con):
return cx_Oracle.Cursor(con)
--------
Menu.py
import functionality.ItemSearch
import functionality.Registration
import functionality.SearchRestaurant
import functionality.DisplayDetail
from classes.Customer import Customer
print("*********************************************")
print(" Welcome to PyFood Service!! ")
print("*********************************************")
print("Choose an Option from below:\n")
end=False
while(end==False):
print("1. Registration")
print("2. Search Restaurant")
print("3. Item Search")
print("4. Billing")
print("5. Display Details")
print("6. Exit")
option=input()
if(option.isdigit() and (int(option)>=1 and int(option)<=6)):
if(int(option)==1):
print("Registration")
functionality.Registration.registration()
if(int(option)==2):
print("Search Restaurant")
cust = Customer()
functionality.SearchRestaurant.search(cust)
if(int(option)==3):
print("Item Search")
functionality.ItemSearch.displayRestaurantName()
if(int(option)==4):
print("Billing")
functionality.CalculateBill.calculate_bill()
if(int(option)==5):
print("Display Details")
functionality.DisplayDetail.display_detail()
if(int(option)==6):
Customer.cust_type=None
print("Thank you!")
end=True
else:
print("Please enter a valid option (1,2,3,4,5,6)")
validation
CardDetailValidation
'''
Created on Mar 16, 2017
@author: swapnil.mishra
'''
import datetime
def card_detail_validation(card_no,cvv,exp_date,name):
error=0
if len(card_no)!=19:
print("Invalid Card no")
error+=1
list1=card_no.split("-")
for number in list1:
if not(number.isdigit()):
print("Invalid Card no")
error+=1
break
if(len(cvv)!=3 and cvv.isdigit()):
print("Invalid CVV no or format")
error+=1
try:
exp_date=datetime.datetime.strptime(exp_date,"%m/%Y")
if exp_date<=datetime.datetime.today():
print("Card Expired!!")
error+=1
except:
print("Invalid Date Format")
error+=1
if name=="":
print("Name is Invalid")
error+=1
if error==0:
return True
else:
return False
ItemValidation.py
import database.ItemDB
from exceptions import ItemExceptions
#from exceptions.ItemExceptions import InvalidRestaurantException,InvalidCategoryException
#from classes import Customer
#from functionality import SearchRestaurant
#from functionality import ItemSearch
#
# def restaurantNameValidation():
# customer = Customer()
#SearchRestaurant.search(customer)
def restaurantValidation(rname):
try:
list_of_category = database.ItemDB.get_category(rname)
if(len(list_of_category[0])==0):
raise ItemExceptions.InvalidRestaurantException()
return list_of_category
except ItemExceptions.InvalidRestaurantException as e:
print(e)
#ItemSearch.displayCategory(rname)
return False
def categoryValidation(category,rid,rname):
try:
list_of_items = database.ItemDB.get_items(category,rid)
if len(list_of_items) == 0:
raise ItemExceptions.InvalidCategoryException()
return list_of_items
except ItemExceptions.InvalidCategoryException as e:
print(e)
#ItemSearch.displayCategory(rname)
return
def itemAvailabilityValidation(item_name,list_of_items):
for item in list_of_items:
if item.get_item_name() == item_name:
if item.get_item_availability() == "A":
return item
ViewValidations.py
import re
from exceptions.Exceptions import InvalidPasswordException
from exceptions.Exceptions import InvalidEmailException
from exceptions.Exceptions import InvalidPhnoException
from utility import DBConnectivity
from database import RestaurantDB
from exceptions.CustomException import InvalidCityException
from exceptions.CustomException import InvalidAreaException
from exceptions.CustomException import InvalidRestaurantException
def validate_password(password):
try:
if(re.search(r"[a-zA-Z0-9@#$%&*^]+",password)==None):
raise InvalidPasswordException()
else:
return True
except InvalidPasswordException as e:
print(e)
return False
def validate_email(mailid):
try:
if(re.search(r"(\w+[.|\w])*@(\w+[.])*(com$|in$)",mailid)==None):
raise InvalidEmailException()
else:
return True
except InvalidEmailException as e:
print(e)
return False
def validate_phno(phno):
try:
if len(phno)!=10 or (re.search(r"[0-9]",phno)==None):
raise InvalidPhnoException()
else:
return True
except InvalidPhnoException as e:
print(e)
return False
#
# from functionality.SearchRestaurant import displayRestaurants
def validate_area(area1):
try:
con=DBConnectivity.create_connection()
cur=DBConnectivity.create_cursor(con)
flag=0
cur.execute("select rarea,rname from restaurant")
for area,name in cur:
if area1==area:
return True
flag=1
if(flag==0):
raise InvalidAreaException()
except InvalidAreaException as e:
print(e)
finally:
cur.close()
con.close()
def validate_city(city1):
try:
con=DBConnectivity.create_connection()
cur=DBConnectivity.create_cursor(con)
flag=0
cur.execute("select rcity,rname from restaurant")
for city,rname in cur:
if city1==city:
return True
flag=1
if(flag==0):
raise InvalidCityException()
except InvalidCityException as e:
print(e)
# except Exception as e:
# print("Sorry. Some system error occurred")
# print(e)
finally:
cur.close()
con.close()
def validate_restaurant(rname1):
try:
con=DBConnectivity.create_connection()
cur=DBConnectivity.create_cursor(con)
flag=0
cur.execute("select rname,rcity from restaurant")
for rname,city in cur:
if rname1==rname:
return True
flag=1
if(flag==0):
raise InvalidRestaurantException
except InvalidRestaurantException as e:
print(e)
# except Exception as e:
# print("Sorry. Some system error occurred")
# print(e)
finally:
cur.close()
con.close()
------
\'''
Created on Mar 16, 2017
@author: swapnil.mishra
'''
import classes.OrderDetails
import classes.Customer
import functionality.CalculateBill
import functionality.DisplayDetail
import database.DisplayDetails
import validations.CardDetailValidation
import exceptions.CalculateBillExceptions
'''
positive test cases
'''
return_value=validations.CardDetailValidation.card_detail_validation('1234-1234-1235-1245','093','05/2022','Viknesh')
return_value=validations.CardDetailValidation.card_detail_validation('2344-2341-2355-1245','493','07/2021','Viknesh2')
return_value=validations.CardDetailValidation.card_detail_validation('1234-1234-1235-1245','093','05/2022','Viknesh')
'''
negative test cases
'''
return_value=validations.CardDetailValidation.card_detail_validation('12d34-1234-1235-1245','093','05/2022','Viknesh')
return_value=validations.CardDetailValidation.card_detail_validation('1234-1234-1235-1245','09','05/2022','Viknesh')
return_value=validations.CardDetailValidation.card_detail_validation('1234-1234-1235-1245','093','95/2022','Viknesh')
return_value=validations.CardDetailValidation.card_detail_validation('1234-1234-1235-1245','093','05/2022','')
TestCases.py
from validations.ViewValidations import validate_email,validate_password,validate_phno
from exceptions.Exceptions import InvalidPasswordException,InvalidEmailException,InvalidPhnoException
# '''positive test cases'''
#
# print(validate_password("pass1@jack"))
# print(validate_email("jack@gmail.com"))
# print(validate_phno("1234567890"))
#
#
# '''negative test cases'''
#
# try:
# test_pass=validate_password('jahgv.w')
# except InvalidPasswordException as e:
# print(e)
#
# try:
# test_mail=validate_email('dhncjk')
# except InvalidEmailException as e:
# print(e)
#
# try:
# test_phno=validate_phno('1523604')
# except InvalidPhnoException as e:
# print(e)
#
def test_validate_password_1():
invalid_pass='gdjhk'
expected_output=False
actual_output=validate_password(invalid_pass)
assert actual_output==expected_output
def test_validate_password_2():
invalid_pass='gdjh1k'
expected_output=False
actual_output=validate_password(invalid_pass)
assert actual_output==expected_output
def test_validate_password_3():
invalid_pass='gdj@3hk'
expected_output=True
actual_output=validate_password(invalid_pass)
assert actual_output==expected_output
def test_validate_email_1():
invalid_email='fgrtuy'
expected_output=False
actual_output=validate_email(invalid_email)
assert actual_output==expected_output
def test_validate_email_2():
invalid_email='fgr.t@uy.com'
expected_output=True
actual_output=validate_email(invalid_email)
assert actual_output==expected_output
def test_validate_phno_1():
invalid_phno='gwed'
expected_output=False
actual_output=validate_phno(invalid_phno)
assert actual_output==expected_output
def test_validate_phno_2():
invalid_phno='123654'
expected_output=False
actual_output=validate_phno(invalid_phno)
assert actual_output==expected_output
def test_validate_phno_3():
invalid_phno='1234569870'
expected_output=True
actual_output=validate_phno(invalid_phno)
assert actual_output==expected_output
def test_validate_phno_4():
invalid_phno='0236547890'
expected_output=False
actual_output=validate_phno(invalid_phno)
assert actual_output==expected_output
TestDisplayDetails
'''
Created on Mar 17, 2017
@author: swapnil.mishra
'''
from functionality.DisplayDetail import*
from database.DisplayDetails import display_restaurant, display_customer,\
display_the_most_booked_hotel
'''
positive testcases
'''
display_restaurant()
display_customer()
display_the_most_booked_hotel()
'''
negative testcases
'''
------
TestItemSearch
import validations.ItemValidation
import exceptions.ItemExceptions
'''
Restaurant Name Validation:
'''
validations.ItemValidation.restaurantValidation("hubham")
category = validations.ItemValidation.restaurantValidation("Shubham")
if category != False:
print("Restaurant Name Validation Successful")
# item = validations.ItemValidation.categoryValidation(category, 'R1012', 'Shubham')
'''
Category Validation
'''
item = validations.ItemValidation.categoryValidation('harhtrian', 'R1012', 'Shubham')
item = validations.ItemValidation.categoryValidation('Maharashtrian', 'R1012', 'Shubham')
if item!= None:
print("Category validation Successful ")
------
TestSearchResults
.import classes.Customer
import classes.Restaurant
import functionality.SearchRestaurant
import database.RestaurantDB
from exceptions.CustomException import InvalidRestaurantException,\
InvalidCityException, InvalidAreaException
from validations.ViewValidations import validate_area
from validations.ViewValidations import validate_city
from validations.ViewValidations import validate_restaurant
'''
positive testcases
'''
validate_area("MG Road")
validate_area("Bypass Road")
validate_city("Kochi")
validate_city("Calicut")
validate_restaurant("Biriyani Hut")
validate_restaurant("Paragon")
'''
negative testcases
'''
try:
validate_area("mg road")
validate_area("bypass road")
validate_city("kochi")
validate_city("calicut")
validate_restaurant("biriyani hut")
validate_restaurant("paragon")
except InvalidAreaException as a:
print(a)
except InvalidCityException as c:
print(c)
except InvalidRestaurantException as e:
print(e)
-------
-- Drop all tables
Drop TABLE customer cascade constraints;
Drop TABLE restaurant cascade constraints;
Drop TABLE item cascade constraints;
Drop TABLE bill cascade constraints;
create table customer(
username varchar2(20) primary key,
password varchar2(20) not null,
emailid varchar2(20),
mobileno integer check(length(mobileno)=10),
secq varchar2(50),
seca varchar2(15),
area varchar2(20),
city varchar2(20),
state varchar2(20),
address varchar2(50)
);
create table restaurant(
rid varchar2(5) primary key,
rname varchar2(30),
r_type varchar2(3),
likes integer,
dislikes integer,
ratings number,
rarea varchar2(20),
rcity varchar2(20)
);
create table item(
rid varchar2(5) references restaurant(rid),
itemid varchar2(5) primary key,
category varchar2(15),
item_name varchar2(20),
availability varchar2(2),
price number
);
create table bill(
rid varchar2(5) references restaurant(rid),
username varchar2(20) references customer(username)
);
INSERT INTO RESTAURANT VALUES('R1001','Biriyani Hut','N',500,50,7,'Bypass Road','Calicut');
INSERT INTO RESTAURANT VALUES('R1002','Malabar Village','N',707,30,8,'MG Road','Kochi');
INSERT INTO RESTAURANT VALUES('R1003','Paragon','V/N',1000,10,9,'MG Road','Kochi');
INSERT INTO RESTAURANT VALUES('R1004','Modern Restaurant','V/N',660,90,8.8,'M.College','Calicut');
INSERT INTO RESTAURANT VALUES('R1005','Arya Bhavan','V',850,20,8.2,'Marine Drive','Kochi');
INSERT INTO RESTAURANT VALUES('R1006','Coffee House','N',859,50,8.9,'Hebbal','Mysore');
INSERT INTO RESTAURANT VALUES('R1007','Silver Spoons','N',345,34,6.7,'Shivajinagar','Banglore');
INSERT INTO RESTAURANT VALUES('R1008','Flavours Of India','V/N',732,59,7.3,'Majestic','Banglore');
INSERT INTO RESTAURANT VALUES('R1009','Annapoorna','V',345,22,6,'M.College','Calicut');
INSERT INTO RESTAURANT VALUES('R1010','Sukh Sagar','V',800,120,7,'Majestic','Banglore');
INSERT INTO RESTAURANT VALUES('R1011','Nagarjuna','V',455,48,7.5,'Hebbal','Mysore');
INSERT INTO RESTAURANT VALUES('R1012','Shubham','V',435,46,7.5,'Hebbal','Mysore');
INSERT INTO RESTAURANT VALUES('R1013','Pizza Hut','V/N',900,34,8,'Suburban Busstand','Mysore');
INSERT INTO customer VALUES('Jack','pass1@jack','jack@gmail.com',1234567890,'what is your name?','jack','Bypass Road','Calicut','Kerala','villa1,Calicut');
INSERT INTO customer VALUES('Jill','pass1@jill','jill@gmail.com',1254367890,'what is your name?','jill','Suburban Busstand','Mysore','Karnataka','villa2,Mysore');
INSERT INTO customer VALUES('Mark','pass1@mark','mark@gmail.com',1869367890,'what is your name?','mark','Suburban Busstand','Mysore','Karnataka','villa3,Mysore');
INSERT INTO customer VALUES('Mary','pass1@mary','mary@gmail.com',1869385290,'what is your name?','mary','Majestic','Banglore','Karnataka','villa4,Bangalore');
INSERT INTO customer VALUES('Kevin','pass1@kevin','kevin@gmail.com',8815235290,'what is your name?','kevin','Medical College','Calicut','Kerala','villa5,Calicut');
INSERT INTO customer VALUES('Joseph','pass1@joseph','joseph@gmail.com',9818535290,'what is your name?','joseph','Shivajinagar','Banglore','Karnataka','villa6,Bangalore');
INSERT INTO customer VALUES('Anthony','pass1@anthony','anthony@gmail.com',9123435290,'what is your name?','anthony','Hebbal','Mysore','Karnataka','villa7,Mysore');
INSERT INTO customer VALUES('Juhi','pass1@juhi','juhi@gmail.com',9185642290,'what is your name?','juhi','MG Road','Kochi','Karnataka','villa8,Kochi');
INSERT INTO ITEM VALUES('R1012','I1150','Maharashtrian','VadaPav','A',20);
INSERT INTO ITEM VALUES('R1012','I1151','Maharashtrian','PavBhaji','A',50);
INSERT INTO ITEM VALUES('R1012','I1156','Maharashtrian','Baked Vadapav','NA',15);
INSERT INTO ITEM VALUES('R1012','I1152','South Indian','Masala Dosa','A',30);
INSERT INTO ITEM VALUES('R1012','I1153','South Indian','Masala Idly','A',30);
INSERT INTO ITEM VALUES('R1012','I1157','South Indian','Schezwan Idly','NA',30);
INSERT INTO ITEM VALUES('R1012','I1154','North Indian','Chole Bhature','A',60);
INSERT INTO ITEM VALUES('R1012','I1155','North Indian','Paneer Poori','A',50);
INSERT INTO ITEM VALUES('R1012','I1158','North Indian','Dal Makhni','NA',50);
INSERT INTO ITEM VALUES('R1009','I1050','Maharashtrian','VadaPav','A',20);
INSERT INTO ITEM VALUES('R1009','I1051','Maharashtrian','PavBhaji','A',50);
INSERT INTO ITEM VALUES('R1009','I1056','Maharashtrian','Baked Vadapav','NA',15);
INSERT INTO ITEM VALUES('R1009','I1052','South Indian','Masala Dosa','A',30);
INSERT INTO ITEM VALUES('R1009','I1053','South Indian','Masala Idly','A',30);
INSERT INTO ITEM VALUES('R1009','I1057','South Indian','Schezwan Idly','NA',30);
INSERT INTO ITEM VALUES('R1009','I1054','North Indian','Chole Bhature','A',60);
INSERT INTO ITEM VALUES('R1009','I1055','North Indian','Paneer Poori','A',50);
INSERT INTO ITEM VALUES('R1009','I1058','North Indian','Dal Makhni','NA',50);
INSERT INTO ITEM VALUES('R1003','I1001','cHICKEN','KABAB','A',80);
INSERT INTO ITEM VALUES('R1003','I1002','CHICKEN','LOLLIPOP','A',100);
INSERT INTO ITEM VALUES('R1003','I1003','FISH','FRY','NA',45);
INSERT INTO ITEM VALUES('R1003','I1004','FISH','Masala','A',30);
INSERT INTO ITEM VALUES('R1003','I1005','SEA FOOD','PRAWNS','A',70);
INSERT INTO ITEM VALUES('R1003','I1006','SEA FOOD','CRAB','NA',30);
INSERT INTO ITEM VALUES('R1003','I1007','SEA FOOD','ROHU','A',160);
INSERT INTO ITEM VALUES('R1003','I1008','CHICKEN','BURGER','A',150);
INSERT INTO ITEM VALUES('R1003','I1009','FISH','CURRY','NA',150);
INSERT INTO ITEM VALUES('R1011','I1250','Maharashtrian','VadaPav','A',20);
INSERT INTO ITEM VALUES('R1011','I1251','Maharashtrian','PavBhaji','A',50);
INSERT INTO ITEM VALUES('R1011','I1256','Maharashtrian','Baked Vadapav','NA',15);
INSERT INTO ITEM VALUES('R1011','I1252','South Indian','Masala Dosa','A',30);
INSERT INTO ITEM VALUES('R1011','I1253','South Indian','Masala Idly','A',30);
INSERT INTO ITEM VALUES('R1011','I1257','South Indian','Schezwan Idly','NA',30);
INSERT INTO ITEM VALUES('R1011','I1254','North Indian','Chole Bhature','A',60);
INSERT INTO ITEM VALUES('R1011','I1255','North Indian','Paneer Poori','A',50);
INSERT INTO ITEM VALUES('R1011','I1258','North Indian','Dal Makhni','NA',50);
INSERT INTO ITEM VALUES('R1006','I1101','cHICKEN','KABAB','A',80);
INSERT INTO ITEM VALUES('R1006','I1102','CHICKEN','LOLLIPOP','A',100);
INSERT INTO ITEM VALUES('R1006','I1103','FISH','FRY','NA',45);
INSERT INTO ITEM VALUES('R1006','I1104','FISH','Masala','A',30);
INSERT INTO ITEM VALUES('R1006','I1105','SEA FOOD','PRAWNS','A',70);
INSERT INTO ITEM VALUES('R1006','I1106','SEA FOOD','CRAB','NA',30);
INSERT INTO ITEM VALUES('R1006','I1107','SEA FOOD','ROHU','A',160);
INSERT INTO ITEM VALUES('R1006','I1108','CHICKEN','BURGER','A',150);
INSERT INTO ITEM VALUES('R1006','I1109','FISH','CURRY','NA',150);
INSERT INTO BILL VALUES('R1009','Jack');
commit;