Пример #1
0
def enter_food_items():
    global category_items
    global category_items_quantity
    
    #Getting valid item from the displayed items for the selected category
    item_selected=input("Enter a Items for order: ")
    print()
    
    print("Item Selected from the Menu : ")
    print(item_selected)
    
    #Splitting the item_selected with respect to multiple items selected
    category_items = item_selected.split(',')
    
    '''
        #print("In function def enter_food_items(category_items): ")
        #printing the list of multi selects or single selects using split
        print(category_items)
        print()
        
        Validate the Food Items enter_food_items input
           
    '''

    try :
        item_selected = Validate.validate_item_present(category_items)
    
    except  Validate_item_present  as e:
        print(e)
        #Extra print
        #print(" The selected item is Not Available , Please Re-Enter Again")
        enter_food_items()
    
    finally :
        pass
Пример #2
0
def enter_food_quantity():
    global category_items
    global category_items_quantity
    
    '''
    #Taking input for quantity of Food Items
    #Splitting the category with respect to multiple items selected or single item
    '''
    
    quantity_req = input("Enter a  quantity required : ")
    category_items_quantity = quantity_req.split(',')
    
    #Checking values returned are digits
    for number in category_items_quantity :
        if Validate.validate_input_is_decimal(number) == False :
            enter_food_quantity()
        elif int(number) > 25 and int(number)  <= 0 :
            enter_food_quantity()
            
            
    print("Category name , Quantity")
    for category_index , quantity_item in zip(category_items , category_items_quantity) :
        
        print(category_index ," ", quantity_item)
        FoodModule.Food.cart_dict[category_index] = quantity_item
Пример #3
0
def search_as_guest():

    try:
        FoodModule.Food.is_registered_user = False
        city1 = input("Enter your city:")
        area1 = input("Enter your area:")
        city = city1.upper()
        area = area1.upper()

        list_of_restaurants = Validate.validate_search_category(city, area)
        '''
        Print the details
         '''
        print("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ")
        print(
            "resturantname     type of food    likes     dislikes     rating")
        for select in list_of_restaurants:
            print(select.get_restaurantname(), "     ",
                  select.get_type_of_food(), " ", select.get_likes(), "     ",
                  select.get_dislikes(), "     ", select.get_rating())
        print()

        filter(city, area)

    except CustomException2.Invalidcityareaname as e:
        print(e)
    except Exception as e:
        print(e)
        print()
Пример #4
0
def search_as_login(city,area):
    try:
       
        list_of_restaurants=Validate.validate_search_category(city,area)
        
        print("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ")
        print("resturantname     type of food    likes     dislikes     rating")
        for select in list_of_restaurants:
            print(select.get_restaurantname(),"     ",select.get_type_of_food()," " ,  select.get_likes(),"     ",select.get_dislikes(),"     ",select.get_rating())
        print()   
        
        
        choice=input("Do you want to filter or select restaurant?(F/S)")
        if (choice=="F"):
            
            filtersearch.Filter_search()
            
            
        if (choice=="S"):
            resturant_name=input("Enter the resturant name:")  
            print("")  
    
    except InvalidCategoryException as e:
        print(e)
    except Exception as e:
        print("here is")
        print("Sorry. Some system error occurred")
        print(e)
    print()    
    
Пример #5
0
def display_highest_booked_hotel_by_city():
    print("In Function display_highest_booked_hotel_by_city")
    city1 = input("Enter city name:")
    city = city1.upper()
    list_of_restaurants = Validate.validate_city_wise_highest_booked(city)
    print("resturantname", "\t", "city", "\t", "area", "\t", "rating")
    for select in list_of_restaurants:
        print(select.get_restaurantname(), "\t", select.get_city(), "\t",
              select.get_area(), "\t", select.get_rating())
    print()
Пример #6
0
def display_most_rated_hotel():

    print("In Function def display_most_rated_hotel():")
    list_of_restaurants = Validate.validate_highest_rated()
    print("resturantname", "\ttype of food", "\tlikes", "\tdislikes",
          "\trating")
    for select in list_of_restaurants:
        print(select.get_restaurantname(), "\t", select.get_type_of_food(),
              "\t", select.get_likes(), "\t", select.get_dislikes(), "\t",
              select.get_rating())
    print()
Пример #7
0
def get_restaurantname(city, area):
    try:
        restaurant_name1 = input("Enter the restaurant name:")
        restaurant_name = restaurant_name1.upper()
        list_of_restaurants = Validate.validate_hotel_name(
            city, area, restaurant_name)
        print(restaurant_name)
        FoodModule.Food.restaurant_name = restaurant_name
        FoodModule.Food.restaurant_city = city
        FoodModule.Food.restaurant_area = area
    except CustomException2.Invalidselectname as e:
        print(e)
    except Exception as e:
        print("Sorry. Some system error occurred")
        print(e)
Пример #8
0
def availability_view(category_items): 
    
    '''
        Validate the Food Items Availability input
    '''
    
    #print("In function def availability_view(category_items): ")
    food_available = False
    try :
        food_available = Validate.validate_item_available(category_items)
    
    except  Validate_item_available  as e:
        print(e)
        #print(" after e Selected item not Available!!! Please Select a different item")
        view_category_items(category_item_name)
    
    finally :
        pass
Пример #9
0
def validate_restaurant_name(restaurant):
    global list_of_category
    global list_numbers
    '''
    Validate the user input
    '''
    #Empty the list_numbers
    del list_numbers[:]

    list_of_category = Validate.validate_view_category(restaurant)
    for i in range(1, len(list_of_category) + 1):
        list_numbers.append(i)

    #Using Zip Functionality for zipping two lists
    print("Index ", "Category")
    for index, category in zip(list_numbers, list_of_category):
        print(index, "   ", category)

    print()
Пример #10
0
def search_as_guest():
    try:
        city = input("Enter your city:")
        area = input("Enter your area:")

        #         city=city1.upper()
        #         area=area1.upper()
        list_of_restaurants = Validate.validate_search_category(city, area)
        '''
        Print the details
         '''
        print("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ")
        print(
            "resturantname     type of food    likes     dislikes     rating")
        for select in list_of_restaurants:
            print(select.get_restaurantname(), "     ",
                  select.get_type_of_food(), " ", select.get_likes(), "     ",
                  select.get_dislikes(), "     ", select.get_rating())
        print()

        choice = input("Do you want to filter or select restaurant?(F/S)")
        try:
            if (choice.upper() == "F"):

                filtersearch.Filter_search(city, area)
        except CustomException2.Invalidfilter as e:
            print(e)
        except Exception as e:
            print("Choose F or S")
            print(e)

        if (choice.upper() == "S"):
            resturant_name = input("Enter the resturant name:")
            print("")

    except CustomException2.InvalidCategoryException as e:
        print(e)
    except Exception as e:
        print(e)
    print()
Пример #11
0
def select_category_choice():
    global list_of_category
    global list_numbers
    
    choice=input("Please Select The Category with its Corresponding Number :")
    v_choice = Validate.validate_input_is_decimal(choice)
#     print(v_choice)
#     print("len(list_of_category)")
#     print(len(list_of_category))
    
    if v_choice == False:
        print("Please select from the given choices only.")
        select_category_choice()
    else :
        if int(choice) <= len(list_of_category) and int(choice) >= 1 :
            for index in zip(list_numbers,list_of_category) :
                    if int(choice) == index[0] :
                        print("Choice Selected : ", index[0],"-", index[1])
                        return index[1]
        else : 
            print("Please select from the given choices only.")
            select_category_choice()
Пример #12
0
def get_restaurantname(city, area):
    try:
        restaurant_name1 = input("Enter the restaurant name:")
        restaurant_name = restaurant_name1.upper()
        list_of_restaurants = Validate.validate_hotel_name(
            city, area, restaurant_name)
        print(restaurant_name)

        #Saving to Global Project Variables
        FoodModule.Food.restaurant_name = restaurant_name
        FoodModule.Food.restaurant_city = city
        FoodModule.Food.restaurant_area = area

        from functionality import ViewFunctions
        #Calling Module 3
        print("Calling Module 3")
        ViewFunctions.view_category()

    except CustomException2.Invalidselectname as e:
        print(e)
    except Exception as e:
        print("Sorry. Some system error occurred")
        print(e)
Пример #13
0
def search_as_login(city1, area1):
    try:
        city = city1.upper()
        area = area1.upper()
        list_of_restaurants = Validate.validate_search_category(city, area)

        print("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ")
        print(
            "resturantname     type of food    likes     dislikes     rating")
        for select in list_of_restaurants:
            print(select.get_restaurantname(), "     ",
                  select.get_type_of_food(), " ", select.get_likes(), "     ",
                  select.get_dislikes(), "     ", select.get_rating())
        print()

        filter(city, area)

    except CustomException2.InvalidCategoryException as e:
        print(e)
    except Exception as e:
        print("Sorry. Some system error occurred")
        print(e)
    print()
Пример #14
0
def view_category_items(category):
    try:
        
        
        '''
        Validate the user input
        '''
        list_of_category_items=Validate.validate_view_category_items(category)
        
        '''
        Print the details
        '''
        
        for product in list_of_category_items:
            print(product.get_product_id()," ",product.get_product_name()," ",product.get_price())
        print()  
        
        #Getting valid item from the displayed items for the selected category
        item_selected=input("Enter a Items for order: ")
        print()
        
        category_items = []
        category_items_quantity = []
        
        #Splitting the category with respect to multiple items selected
        category_items = category.split(',')
        
        
        quantity_req =input("Enter a  quantity required : ")
        #Splitting the category with respect to multiple items selected
        category_items_quantity = quantity_req.split(',')
        
        
        for index , category in zip(category_items , list_of_category_items) :
            print(index ," ", category)
            
        print()   
        
        
        
        choice=input("Please Select The Category. Enter Corresponding Number ")
        if(choice=="1"):
            category_id=input("Enter the Category ID")
            '''
            Here we are invoking a dummy function and passing the data to it.
            This dummy function has to be completed by another programmer.
            '''
        elif(choice=="2"):
            category_id=input("Enter the Category ID")
            '''
            Here we are invoking a dummy function and passing the data to it.
            This dummy function has to be completed by another programmer.
            '''
        elif(choice=="3"):
            category_id=input("Enter the Category ID")
           '''
            Here we are invoking a dummy function and passing the data to it.
            This dummy function has to be completed by another programmer.
            '''
        
        elif(choice=="4"):
            category_id=input("Enter the Category ID")
            '''
            Here we are invoking a dummy function and passing the data to it.
            This dummy function has to be completed by another programmer.
            '''
        
        elif(choice=="5"):
            category_id=input("Enter the Category ID")
            '''
Пример #15
0
def view_category():
    try:
        restaurant=input("Enter a category: ")
        print()
        
        '''
        Validate the user input
        '''
        list_of_category=Validate.validate_view_category(restaurant)
        
        '''
        Print the details
        '''
        for index , category in list_of_category:
            print(index ," ", category)
            
        print()   
        
        
        
        choice=input("Please Select The Category. Enter Corresponding Number ")
        
        if(choice=="1"):
            category_id=input("Enter the Category ID")
            '''
            Here we are invoking a dummy function and passing the data to it.
            This dummy function has to be completed by another programmer.
            '''
        elif(choice=="2"):
            category_id=input("Enter the Category ID")
            '''
            Here we are invoking a dummy function and passing the data to it.
            This dummy function has to be completed by another programmer.
            '''
        elif(choice=="3"):
            category_id=input("Enter the Category ID")
            '''
            Here we are invoking a dummy function and passing the data to it.
            This dummy function has to be completed by another programmer.
            '''
        
        elif(choice=="4"):
            category_id=input("Enter the Category ID")
            '''
            Here we are invoking a dummy function and passing the data to it.
            This dummy function has to be completed by another programmer.
            '''
        
        elif(choice=="5"):
            category_id=input("Enter the Category ID")
            '''
            Here we are invoking a dummy function and passing the data to it.
            This dummy function has to be completed by another programmer.
            '''
        
        elif(choice=="6"):
            category_id=input("Enter the Category ID")
            '''
            Here we are invoking a dummy function and passing the data to it.
            This dummy function has to be completed by another programmer.
            '''
            
            
        Checkout.checkout(category_id)
            
        '''
        Handle all the exceptions that can occur
        '''   
    except InvalidCategoryException as e:
        print(e)
    except Exception as e:
        print("Sorry. Some system error occurred")
        print(e)
    print()
Пример #16
0
def Filter_search(city1, area1):
    city = city1.upper()
    area = area1.upper()

    filter = input("Filter based on:")
    temp = 0
    filter_list = filter.split(",")
    list = []
    for value in filter_list:
        list.append(value.lower())
    for value in list:
        if value == "rating" or value == "likes" or value == "dislikes" or value == "type of food":
            temp = 0
        else:
            temp += 1
    if temp == 0:
        if len(list) == 1:
            for value in list:
                if value == "rating":
                    var1 = input("Enter the rating  range:")
                    var1_list = var1.split("-")
                    rating_lower = var1_list[0]
                    rating_upper = var1_list[1]

                    list_of_restaurants = Validate.validate_search_as_rating(
                        city, area, rating_lower, rating_upper)
                    print(
                        "resturantname     type of food    likes     dislikes     rating"
                    )
                    for select in list_of_restaurants:
                        print(select.get_restaurantname(), "     ",
                              select.get_type_of_food(),
                              " ", select.get_likes(), "     ",
                              select.get_dislikes(), "     ",
                              select.get_rating())
                    print()
                    previous_select(city, area)

                elif value == "likes":
                    list_of_restaurants = Validate.validate_search_as_likes(
                        city, area)
                    print(
                        "resturantname     type of food    likes     dislikes     rating"
                    )
                    for select in list_of_restaurants:
                        print(select.get_restaurantname(), "     ",
                              select.get_type_of_food(),
                              " ", select.get_likes(), "     ",
                              select.get_dislikes(), "     ",
                              select.get_rating())
                    print()
                    previous_select(city, area)

                elif value == "dislikes":
                    list_of_restaurants = Validate.validate_search_as_dislikes(
                        city, area)
                    print(
                        "resturantname     type of food    likes     dislikes     rating"
                    )
                    for select in list_of_restaurants:
                        print(select.get_restaurantname(), "     ",
                              select.get_type_of_food(),
                              " ", select.get_likes(), "     ",
                              select.get_dislikes(), "     ",
                              select.get_rating())
                    print()
                    previous_select(city, area)

                elif value == "type of food":
                    var1 = input("enter your food type:(N/V):")
                    list_of_restaurants = Validate.validate_search_as_type(
                        city, area, var1)
                    print(
                        "resturantname     type of food    likes     dislikes     rating"
                    )
                    for select in list_of_restaurants:
                        print(select.get_restaurantname(), "     ",
                              select.get_type_of_food(),
                              " ", select.get_likes(), "     ",
                              select.get_dislikes(), "     ",
                              select.get_rating())
                    print()
                    previous_select(city, area)

        if len(list) == 2:

            if "rating" in list:

                var1 = input("Enter the rating  range:")
                var1_list = var1.split("-")
                rating_lower = var1_list[0]
                rating_upper = var1_list[1]
                if "dislikes" in list:

                    list_of_restaurants = Validate.validate_search_as_rating_dislikes(
                        city, area, rating_lower, rating_upper)
                    print(
                        "resturantname     type of food    likes     dislikes     rating"
                    )
                    for select in list_of_restaurants:
                        print(select.get_restaurantname(), "     ",
                              select.get_type_of_food(),
                              " ", select.get_likes(), "     ",
                              select.get_dislikes(), "     ",
                              select.get_rating())
                    print()
                    previous_select(city, area)

                elif "likes" in list:

                    list_of_restaurants = Validate.validate_search_as_rating_likes(
                        city, area, rating_lower, rating_upper)
                    print(
                        "resturantname     type of food    likes     dislikes     rating"
                    )
                    for select in list_of_restaurants:
                        print(select.get_restaurantname(), "     ",
                              select.get_type_of_food(),
                              " ", select.get_likes(), "     ",
                              select.get_dislikes(), "     ",
                              select.get_rating())
                    print()
                    select = input(
                        "Do u wish to select restaurant or go back to previous menu?(S/P)"
                    )
                    previous_select(city, area)

                elif "type of food" in list:
                    var1 = input("Enter youe type of food:")
                    list_of_restaurants = Validate.validate_search_as_rating_type(
                        city, area, rating_lower, rating_upper, var1)
                    print(
                        "resturantname     type of food    likes     dislikes     rating"
                    )
                    for select in list_of_restaurants:
                        print(select.get_restaurantname(), "     ",
                              select.get_type_of_food(),
                              " ", select.get_likes(), "     ",
                              select.get_dislikes(), "     ",
                              select.get_rating())
                    print()
                    previous_select(city, area)

            if "dislikes" in list:
                if "likes" in list:
                    list_of_restaurants = Validate.validate_search_as_dislike_like(
                        city, area)
                    print(
                        "resturantname     type of food    likes     dislikes     rating"
                    )
                    for select in list_of_restaurants:
                        print(select.get_restaurantname(), "     ",
                              select.get_type_of_food(),
                              " ", select.get_likes(), "     ",
                              select.get_dislikes(), "     ",
                              select.get_rating())
                    print()
                    previous_select(city, area)

                elif "type of food" in list:
                    var1 = input("Enter youe type of food:")
                    list_of_restaurants = Validate.validate_search_as_dislike_type(
                        city, area, var1)
                    print(
                        "resturantname     type of food    likes     dislikes     rating"
                    )
                    for select in list_of_restaurants:
                        print(select.get_restaurantname(), "     ",
                              select.get_type_of_food(),
                              " ", select.get_likes(), "     ",
                              select.get_dislikes(), "     ",
                              select.get_rating())
                    print()
                    previous_select(city, area)

            if "likes" in list:
                if "type of food" in list:
                    var1 = input("Enter youe type of food:")
                    list_of_restaurants = Validate.validate_search_as_like_type(
                        city, area, var1)
                    print(
                        "resturantname     type of food    likes     dislikes     rating"
                    )
                    for select in list_of_restaurants:
                        print(select.get_restaurantname(), "     ",
                              select.get_type_of_food(),
                              " ", select.get_likes(), "     ",
                              select.get_dislikes(), "     ",
                              select.get_rating())
                    print()
                    previous_select(city, area)

        if len(list) == 3:
            if "rating" in list:
                var1 = input("Enter the rating range:")
                var1_list = var1.split("-")
                rating_lower = var1_list[0]
                rating_upper = var1_list[1]
                if "dislikes" in list:
                    if "likes" in list:
                        list_of_restaurants = Validate.validate_search_as_rating_dislike_like(
                            city, area, rating_lower, rating_upper)
                        print(
                            "resturantname     type of food    likes     dislikes     rating"
                        )
                        for select in list_of_restaurants:
                            print(select.get_restaurantname(), "     ",
                                  select.get_type_of_food(), " ",
                                  select.get_likes(), "     ",
                                  select.get_dislikes(), "     ",
                                  select.get_rating())
                        print()
                        previous_select(city, area)

                    if "type of food" in list:
                        var1 = input("Enter youe type of food:")
                        list_of_restaurants = Validate.validate_search_as_rating_dislike_type(
                            city, area, rating_lower, rating_upper, var1)
                        print(
                            "resturantname     type of food    likes     dislikes     rating"
                        )
                        for select in list_of_restaurants:
                            print(select.get_restaurantname(), "     ",
                                  select.get_type_of_food(), " ",
                                  select.get_likes(), "     ",
                                  select.get_dislikes(), "     ",
                                  select.get_rating())
                        print()
                        previous_select(city, area)

                if "likes" in list:
                    if "type of food" in list:
                        var1 = input("Enter youe type of food:")
                        list_of_restaurants = Validate.validate_search_as_like_type_rating(
                            city, area, rating_lower, rating_upper, var1)
                        print(
                            "resturantname     type of food    likes     dislikes     rating"
                        )
                        for select in list_of_restaurants:
                            print(select.get_restaurantname(), "     ",
                                  select.get_type_of_food(), " ",
                                  select.get_likes(), "     ",
                                  select.get_dislikes(), "     ",
                                  select.get_rating())
                        print()
                        previous_select(city, area)

            if "dislikes" in list:
                if "likes" in list:
                    if "type of food" in list:
                        var1 = input("Enter youe type of food:")
                        list_of_restaurants = Validate.validate_search_as_dislike_like_type(
                            city, area, var1)
                        print(
                            "resturantname     type of food    likes     dislikes     rating"
                        )
                        for select in list_of_restaurants:
                            print(select.get_restaurantname(), "     ",
                                  select.get_type_of_food(), " ",
                                  select.get_likes(), "     ",
                                  select.get_dislikes(), "     ",
                                  select.get_rating())
                        print()
                        previous_select(city, area)

        if len(list) == 4:
            if "rating" in list:
                var1 = input("Enter the rating range:")
                var1_list = var1.split("-")
                rating_lower = var1_list[0]
                rating_upper = var1_list[1]
                if "dislikes" in list:
                    if "likes" in list:
                        if "type of food" in list:
                            var1 = input("Enter youe type of food:")
                            list_of_restaurants = Validate.validate_search_as_all(
                                city, area, rating_lower, rating_upper, var1)
                            print(
                                "resturantname     type of food    likes     dislikes     rating"
                            )
                            for select in list_of_restaurants:
                                print(select.get_restaurantname(), "    ",
                                      select.get_type_of_food(), " ",
                                      select.get_likes(), "     ",
                                      select.get_dislikes(), "     ",
                                      select.get_rating())
                            print()
                            previous_select(city, area)

    else:
        print(
            "invalid filter,please choose from rating,likes,dislikes,type of food"
        )
        Filter_search(city, area)
Пример #17
0
def view_category():
    try:
        global category_item_name
        restaurant=input("Enter a Restaurant Name: ")
        print()
        list_numbers = []
        #list_of_category_str = []
        FoodModule.Food.restaurant_name = restaurant
        
        '''
        Validate the user input
        '''
        
        list_of_category=Validate.validate_view_category(restaurant)
        
        length_categories = len(list_of_category)
        
        for i in range(1,length_categories+1) :
            
            list_numbers.append(i)
        
        #Using Zip Functionality for zipping two lists
        print("Index ","Category")
        for index , category in zip(list_numbers,list_of_category) :
            print(index,"   " ,category)
           
        print()   
        
        choice=input("Please Select The Category with its Corresponding Number ")
        
        if(choice=="1"):
            #Converting to int for easy manipulation
            category_item = int(choice)
            #Storing the name from displayed items for specific category
            category_item_name = list_of_category[category_item-1]
            print("Choice Selected :" , choice , ":" , category_item_name)
            FoodModule.Food.category = category_item_name

            
        elif(choice=="2"):
            #Converting to int for easy manipulation
            category_item = int(choice)
            #Storing the name from displayed items for specific category
            category_item_name = list_of_category[category_item-1]
            print("Choice Selected :" , choice , ":" , category_item_name)
            FoodModule.Food.category = category_item_name
            
        elif(choice=="3"):
            #Converting to int for easy manipulation
            category_item = int(choice)
            #Storing the name from displayed items for specific category
            category_item_name = list_of_category[category_item-1]
            print("Choice Selected :" , choice , ":" , category_item_name)
            FoodModule.Food.category = category_item_name

        
        elif(choice=="4"):
            #Converting to int for easy manipulation
            category_item = int(choice)
            #Storing the name from displayed items for specific category
            category_item_name = list_of_category[category_item-1]
            print("Choice Selected :" , choice , ":" , category_item_name)
            FoodModule.Food.category = category_item_name


        elif(choice=="5"):
            #Converting to int for easy manipulation
            category_item = int(choice)
            #Storing the name from displayed items for specific category
            category_item_name = list_of_category[category_item-1]
            print("Choice Selected :" , choice , ":" , category_item_name)
            FoodModule.Food.category = category_item_name
            
            
        elif(choice=="6"):
            #Converting to int for easy manipulation
            category_item = int(choice)
            #Storing the name from displayed items for specific category
            category_item_name = list_of_category[category_item-1]
            print("Choice Selected :" , choice ,":", category_item_name)
            FoodModule.Food.category = category_item_name
            
        
        print()
        #Calling def view_category_items(category): with parameter
        view_category_items(category_item_name)    
        
        '''
        Handle all the exceptions that can occur
        '''
        
    except InvalidCategoryException as e:
        print(e)
    except Exception as e:
        print("Sorry. Some system error occurred")
        print(e)
    print()
Пример #18
0
def view_category_items(category):
    global category_items
    global category_items_quantity
    
    try:   
        '''
        Validate the user input & get Restaurant name from Class Global Variables
        '''
        
        restaurant_name = FoodModule.Food.restaurant_name
        list_of_category_items=Validate.validate_view_category_items(category,restaurant_name)
        
#         print("Printing restaurant name accessed from FoodModule.Food.restaurant_name ")
#         print(restaurant_name)
#         print("After List_of_category_items=Validate.val")
        
        
        '''
        Print the food items details
        '''
        
        print("FoodName \t Price \t Availability")
        for item in list_of_category_items:
            print(item.get_food_name(),"\t",item.get_price(),"\t",item.get_availability())
        print()  
        
        '''
        Calling the function defined below
        '''
        
        enter_food_items()
        
        availability_view(category_items)
        
        enter_food_quantity()
    
        '''
        Printing Dictionary
        #print("Printing Dictionary")
        '''
        
        print("FoodName  \t Quantity")
        for index , value in FoodModule.Food.cart_dict.items() :
            print(index , "  \t" ,value)
        
        
        '''
         WIll call them later after debugging next function
        #Temporary hardcoding for easy debugging
#        username = "******"
#        Checkout.checkout(username)  
        '''
  
        '''
        Calling Class Checkout for further processing
         
        '''
        username = FoodModule.Food.registered_user
        Checkout.checkout(username)
        
        print()
        '''
        Handle all the exceptions that can occur
        '''   
       
        
    except InvalidCategoryException as e:
        print(e)
        
    except InvalidCatItemsException as e:
        print(e)
        
    except Exception as e:
        #Will edit the Error messages in View functions
        print("Sorry. Some system error occurred.")
        print(e)
        
    finally :
        pass
Пример #19
0
def pushLinked():

    ##TODO: validate and push json load to task table

    print 'datttttttta'
    print request.data
    print 'jsonnnnnnnn'
    print request.json

    if not request.json: ##is a dict!!
        return error_helper("The request body does not have JSON Data",400)

    ##removed entities, rels alone can be pushed if previous ids known
    ##changed name to meta_desc
    required_master_props = ['taskid', 'userid', 'token']
    for prop in required_master_props:
        if not prop in request.json:
            return error_helper(str(prop)+"property not in json data", 400)

    # patch for one of these should be present but never none
    # relations can exist in isolation coz of entities that are already present in db
    oneofthese = ['entities','relations']
    flag = False
    for prop in oneofthese:
        if prop in request.json:
            flag = True
            break

    if not flag:
        return error_helper("neither entities nor relations in json data", 400)

    taskid = request.json['taskid']
    tokenid = request.json['token']
    userid = request.json['userid']


    ##XXX: validate these three varibales
    ##XXX: tken, userid, task all valid

    if not taskid.isdigit():
        return error_helper("taskid should be an integer", 400)

    # INFO: tokenid is just for initial validation, will not be saved
    # taskid and userid will be saved
    ##TODO: if the combination is valid
    ##else abort
    ##TODO: get fetchdate and source_url to entities, , 'fetchdate', 'sourceurls'


    ## MAJOR TODO!
    ## some props are interanally reserved crawl_en_id not allowed for nodes
    ## what about ternary relations?
    ##
    ## check for strings
    ## validation checks: if task exists,
    ## ids repeated in nodes in json and in actual
    ## ids repeated in relations
    ## source_urls known in particular format
    ## fetch date in format
    ## allowed labels
    ## props allowed
    ## values all in strings or particular format?
    ## apis to add a new property in allowed dict with its description?
    ## ids ints?
    ## check if nodeid already exists in temp graph db, or relid
    ## create indexes and contsraints will have to add an internal label and internal relation label

    ##MAJOR TODO what to do about metadata?
    ##"description": "Naveen Jindal Connections",
    ##"fetchdate": "01/01/2011",
    ##use this metadata


    ##entities must part in request json
    entities = []
    if 'entities' in request.json:
        entities = request.json['entities'] ##MAJOR TODO: change this to nodes

    ##can be there or can not be, in json
    relations = []
    if 'relations' in request.json:
        relations = request.json['relations']


    # this is for returning the json to the user!
    subgraph = {}

    ##no need to return back token to the user
    #subgraph['token'] = tokenid ##TODO: exatly this? _token! conflict?
    subgraph['userid'] = userid
    subgraph['taskid'] = taskid
    #subgraph['pushdate'] = getTimeNow()

    nodes = {}
    links = {}

    ##MAJOR TODO reserved keywords and required keywords list
    ##MAJOR TODO format and pattern against keywords with regex ??

    required_endict_props = ['labels','properties','id','fetchdate','sourceurl']
    reserved_en_props = ['crawl_en_id','resolvedWithUUID','taskname','token',
    '_token','workname','date','time','resolvedDate',
    'resolvedAgainst','verifiedBy','resolvedBy','verifiedDate','update',
    'lastUpdatedBy','lastUpdatedOn', '_crawl_en_id_','_token_','_taskname_',
    '_id_','_nodenumber_','taskid','_taskid_','verifiedby','_verifiedby_','verifydate',
    'pushdate','_pushedby_','uuid','_uuid_','labels','_labels_','tasktype','_tasktype_','relid','_relid_'] ##_nodeid_ is the node number along with _token_ and _taskname_ will help us in identifying the node! so do not worry!

    ## ALIASES CODE
    # required_en_props = ['name','aliases'] ##inside entity['properties']

    required_en_props = ['name'] ##inside entity['properties']


    validate = Validate() ##TODO: move all validations to this class afterwards

    for en in entities:

        if not 'id' in en:
            return error_helper('id required attribute missing for an entity', 400)


        #print entities[en]
        nodeid = en['id']

        for prop in required_endict_props:
            if not prop in en:
                msg = str(prop)+' required attribute missing for entity %s' %(nodeid)
                return error_helper(msg, 400)

        if not nodeid.isdigit():
            msg = 'entity id should be a number for entity id %s' %(nodeid)
            return error_helper(msg, 400)

        if nodeid in nodes:
            msg = 'id repeated under entities for entity id %s' %(nodeid)
            return error_helper(msg, 400)

        if not len(en['labels'])>0:
            msg = 'Labels list empty for an entity for entity id %s' %(nodeid)
            return error_helper(msg, 400)

        for prop in required_en_props:
            if (not prop in en['properties']) : ##patch for allowing hyperedgenode, checked doesnt affect anything else
                msg = '%s required property missing for an entity for entity id %s' %(prop, nodeid)
                return error_helper(msg, 400)

        ## ALIASES CODE
        # if not len(en['properties']['aliases'])>0:
        #     return error_helper('aliases list empty for an entity', 400)
        # ##TODO: how to verify if the name is in aliases?

        ## XXX: aliases to be handled as a csv?? ##keep it as it is will add - will have to change code when generating keywords etc.
        ## Merge two options for all strings- assume csv seperate - add with "" and then see if lists do not have duplicates append and use
        ## aliases not a list many changes, many places! ##or you can just assume a list and assume no prop named aliases

        for prop in reserved_en_props:
            if prop in en['properties']:
                msg = str(prop)+' reserved property not allowed explicitly for an entity for entity id %s' %(nodeid)
                return error_helper(msg, 400)

        allPropnamesValid, prop = validate.checkAllPropnamesValid(en['properties'])
        if not allPropnamesValid:
            msg = str(prop)+' cannot begin or end with underscore for entity id %s' %(nodeid)
            return error_helper(msg, 400)

        ## MAJOR todo: determine automatically that the type is a list!!
        ## Also push it then like a list - but will have to maintain a list of props that can be list
        ## OR MV and check here back!

        nodelabels = en['labels']

        fetchdate = en['fetchdate']
        sourceurl = en['sourceurl']

        if not fetchdate.isdigit():
            msg = 'fecthdate should be a long time since epoch, negative if dates before 1970 for entity id %s' %(nodeid)
            return error_helper(msg, 400)

        if not validate.validateUrl(sourceurl):
            msg = 'sourceurl should be valid url for entity for entity id %s' %(nodeid)
            return error_helper(msg, 400)

        boolval, prop = validate.checkInternalProps(en['properties'])
        if not boolval:
            msg = 'prop %s not in correct format for entity id %s' %(prop,nodeid)
            return error_helper(msg, 400)

        nodeprops = {}
        for prop in en['properties']:

            # if prop != 'aliases': ##ALIASES CODE


            ##for all MV -- json.loads? or somehting else?
            nodeprops[prop] = en['properties'][prop]

        ### ALIASES CODE
        # nodeprops['aliases'] = []
        # for val in en['properties']['aliases']:
        #     nodeprops['aliases'].append(val)

        # nodeprops = en['properties']
        nodeprops['_pushdate_'] = getTimeNow()
        nodeprops['_crawl_en_id_'] = 'en_'+taskid+'_'+str(nodeid)
        # nodeprops['_token_'] = tokenid ##TODO: if you change this!, will have to change code for entity_read macro.
        nodeprops['_taskid_'] = taskid
        nodeprops['_nodenumber_'] = nodeid
        nodeprops['_pushedby_'] = userid
        nodeprops['_fetchdate_'] = int(fetchdate)
        nodeprops['_sourceurl_'] = sourceurl
        nodes[nodeid] = {'labels':nodelabels,'properties':nodeprops}


    required_reldict_props = ['label','properties','start_entity','end_entity','bidirectional','id','fetchdate','sourceurl']
    reserved_rel_props = ['crawl_rel_id','resolvedWithRELID','taskname','token','_token','workname','date','time','resolvedDate','resolvedAgainst','verifiedBy','resolvedBy','verifiedDate','update','lastUpdatedBy','lastUpdatedOn','_crawl_rel_id_','_token_','_taskname_','_id_','_relnumber_','taskid','_taskid_','verifiedby','_verifiedby_','verifydate',
    'pushdate','uuid','_uuid_','labels','_labels_'] ##just like the above _nodenumber_
    required_rel_props = [] ##inside entity['properties']

    for rel in relations:

        if not 'id' in rel:
            return error_helper('id required attribute missing for a relation', 400)

        linkid = rel['id']

        for prop in required_reldict_props:
            if not prop in rel:
                msg = str(prop)+' required attribute missing for relation id %s' %(linkid)
                return error_helper(str(prop)+' required attribute missing for a relation', 400)


        if linkid in links:
            msg = 'id repeated under relations for relation id %s' %(linkid)
            return error_helper(msg, 400)

        if not linkid.isdigit():
            msg = 'linkid is not a number for relation id %s' %(linkid)
            return error_helper(msg,400)

        linklabel = rel['label']

        if len(linklabel)<3:
            msg = 'Label too short for a relation for relation id %s' %(linkid)
            return error_helper(msg, 400)

        bidirectional = rel['bidirectional']

        if bidirectional!='True' and bidirectional!='False': ##decision taken avoid confusion yes no is default! ##TODO: add rules apis!
            msg = 'bidirectional not True/False for a for a relation for relation id %s' %(linkid)
            return error_helper(msg, 400)

        for prop in required_rel_props:
            if not prop in rel['properties']:
                msg = str(prop)+' required property missing for a relation for relation id %s' %(linkid)
                return error_helper(msg, 400)

        for prop in reserved_rel_props:
            if prop in rel['properties']:
                msg = str(prop)+' reserved property not allowed explicitly for a relation for relation id %s' %(linkid)
                return error_helper(msg, 400)

        allPropnamesValid, prop = validate.checkAllPropnamesValid(rel['properties'])
        if not allPropnamesValid:
            msg = str(prop)+' cannot begin or end with underscore for relation id %s' %(linkid)
            return error_helper(msg, 400)

        linkprops = rel['properties']
        fetchdate = rel['fetchdate']
        sourceurl = rel['sourceurl']

        if not fetchdate.isdigit():
            msg = 'fetchdate should be a long time since epoch, negative if dates before 1970 for relation id %s' %(linkid)
            return error_helper(msg, 400)

        if not validate.validateUrl(sourceurl):
            msg = 'sourceurl should be valid url for entity for relation id %s' %(linkid)
            return error_helper(msg, 400)

        boolval, prop = validate.checkInternalProps(linkprops)
        if not boolval:
            msg = 'prop %s not in correct format for relation id %s' %(prop, linkid)
            return error_helper(msg, 400)

        startnode = 'en_'+taskid+'_'+str(rel['start_entity'])
        endnode = 'en_'+taskid+'_'+str(rel['end_entity'])
        linkprops['_crawl_rel_id_'] = 'rel_'+taskid+'_'+str(linkid)
        #linkprops['_token_'] = tokenid
        linkprops['_taskid_'] = taskid
        linkprops['_relnumber_'] = linkid
        linkprops['bidirectional'] = bidirectional
        linkprops['_pushedby_'] = userid
        linkprops['_pushdate_'] = getTimeNow()
        linkprops['_fetchdate_'] = fetchdate
        linkprops['_sourceurl_'] = sourceurl


        links[linkid] = {'label':linklabel,'properties':linkprops,'start_entity':startnode, 'end_entity':endnode}


    posted, msg = postSubGraph(getGraph(), nodes, links, tokenid, taskid)

    if not posted:
        return error_helper(msg, 400)

    subgraph['entities'] = nodes
    subgraph['relations'] = links


    data = jsonify(subgraph)

    return data, 201 ## 201 is for creation!