Example #1
0
def removeWizzard(argsString):
    if argsString == "" or not argsString:
        print("No arguments provided")
        outputs.decideWhatToDo()
    args = getArgsBy(argsString,',|=')
    print(args)
    if len(args) % 2 != 0:
        print("Insuficient arguments providied, odd number")
        outputs.decideWhatToDo()
    
    searchableArgs=getArgsBy(getConfPart('removeBy','customers').strip(),',')
    try:
        #Remove LIMIT from argsDict
        argsDict = makeArgsDict(args,searchableArgs)
        for i in range(0,len(args),2):
            if args[i].lower() == "limit":
                limit = int(args[i+1])
                print(limit)
                #Limit is in argsDict so remove it
                argsDict.pop('limit',0)
            else:
                limit = 1
    except ValueError as e:
        print("Value error: {}".format(e))
        outputs.decideWhatToDo()

    try:
        remove(argsDict,limit)
    except ValueError as e:
        print("Value error: {}".format(e))
    except TypeError as e:
        print("Type error: {}".format(e))
    except LookupError as e:
        print("Lookup error: {}".format(e))
    outputs.decideWhatToDo()
Example #2
0
def listWizzard(argsString):
    args = getArgsBy(argsString, ',|=')
    if args == [''] or not args:
        try:
            bookings = getBookings({})
        except sqlite3.Error as e:
            print("Sqlite error occured: {}".format(e))
    elif len(args) % 2 != 0:
        # If args length is an uneven length then there is a argument without a pair
        # value and will mean the sql statement will get messed up
        print("Odd number of arguments supplied")
        print("Each argument must have a value eg. \n")
        print("lb key=value or")
        print("lb key=value,key2=value2\n")
        print("There can be no lone keys or values")
    else:
        # Check the arguments are valid then put them into a dictionary to be passed
        # to getBookings()
        searchableArgs = getArgsBy(getConfPart('listBy','bookings').strip(),',')
        argsDict = makeArgsDict(args,searchableArgs)
        try:
            bookings = getBookings(argsDict)
        except sqlite3.Error as e:
            print("Sqlite error occured: {}".format(e))

    print(tabulate(bookings,
        headers=['Booking id','Customer id','Time','Reason'],
        tablefmt="fancy_grid"))
    outputs.decideWhatToDo()
Example #3
0
def removeWizzard(argsString):
    if argsString == '' or not argsString:
        print("No arguments provided")
        outputs.decideWhatToDo()
    args = getArgsBy(argsString,',|=')
    if len(args) % 2 != 0:
        print("Insufficient arguments provided, odd number")
        outputs.decideWhatToDo()
    
    searchableArgs=getArgsBy(getConfPart('removeBy','bookings').strip(),',')
    #makeArgsDict includes LIMIT as an argument so that needs to be removed
    #so it can be used properly
    argsDict = makeArgsDict(args,searchableArgs)
    for i in range(0,len(args),2):
        if args[i].lower() == "limit":
            limit = int(args[i+1])
            #limit is would be in argsDict so remove it
            argsDict.pop('limit',0)
        else:
            limit = 1
    try:
        if remove(argsDict,limit):
            print("Succesfully removed booking")
    except ValueError as e:
        print("Value error: {}".format(e))
    except TypeError as e:
        print("Type error: {}".format(e))
    except LookupError as e:
        print("Lookup error: {}".format(e))
    outputs.decideWhatToDo()