예제 #1
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()
예제 #2
0
def list(argsString):
    # Get args
    args = getArgsBy(argsString,',|=')
    if args == [''] or not args:
        try:
            customers = getCustomers({})
        except sqlite3.Error as e:
            print("Sqlite error occured: {}".format(e))
    else:
        searchableArgs = getArgsBy(getConfPart('listBy','customers').strip(),',')
        # Declare base statement then add to it if more args found
        argsDict = {}
        for i in range(0,len(args),2):
            if args[i] in searchableArgs:
                argsDict[args[i]] = args[i+1]
            else:
                print("Invalid argument: {}".format(args[i]))
                outputs.decideWhatToDo()
        try:
            customers = getCustomers(argsDict)
        except sqlite3.Error as e:
            print("Sqlite error occured: {}".format(e))
    
    print(tabulate(customers,
        headers=['customerId','name','address','telephone'],
        tablefmt="fancy_grid"))
    # Return to start
    outputs.decideWhatToDo()
예제 #3
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()
예제 #4
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()
예제 #5
0
def listAvailable(argsString):
    # If args is blank then assume that today was wanted
    args = getArgsBy(argsString,',|=| ')
    conn = dbConnection.connect()
    openTimes = getArgsBy(getConfPart('openTimes'),',')
    bookingLength = getConfPart('bookingLength')
    try:
        #Sets both variable to be equal to the original dateTime
        openTime, absOpenTime = (datetime.strptime(openTimes[0],'%H:%M'),)*2
        closeTime, absCloseTime = (datetime.strptime(openTimes[1],'%H:%M'),)*2
        #If 'today' is supplied as an argument then change it to be equal to the actual date
        if 'today' in args:
            args = [arg.replace('today',datetime.today().strftime('%d/%m/%Y')) for arg in args]
        if args == ['']:
            date = datetime.today()
        elif len(args) == 1:
            #Use date from args, ValueError will be made if invalid date is used
            date = datetime.strptime(args[0],'%d/%m/%Y').date()
        elif len(args) == 2:
            #Just 'times' supplied, so use that and todays date
            date = datetime.today()
            if args[0] == 'times':
                openTime = datetime.strptime(getArgsBy(args[1],'-')[0],'%H:%M')
                closeTime = datetime.strptime(getArgsBy(args[1],'-')[1],'%H:%M')
            else:
                print("Invalid argument '{}'  supplied, was expecting times".format(args[0]))
                outputs.decideWhatToDo()
        elif len(args) == 3:
            #Use date from args and get and use time args
            if args[1] == 'times':
                # In form `lba 1/1/1970 times=0:00-5:00`
                date = datetime.strptime(args[0],'%d/%m/%Y').date()
                openTime = datetime.strptime(getArgsBy(args[2],'-')[0],'%H:%M')
                closeTime = datetime.strptime(getArgsBy(args[2],'-')[1],'%H:%M')
            elif args[0] == 'times':
                # In form `lba times=0:00-5:00 1/1/1970`
                date = datetime.strptime(args[2],'%d/%m/%Y').date()
                openTime = datetime.strptime(getArgsBy(args[1],'-')[0],'%H:%M')
                closeTime = datetime.strptime(getArgsBy(args[1],'-')[1],'%H:%M')
            else:
                print("Expected times argument, none given")
                outputs.decideWhatToDo()
        else:
            #If nothing usable was supplied then give an error
            print("Invalid arguments supplied")
            outputs.decideWhatToDo()
    except ValueError as e:
        print("Error getting date: {}".format(e))
        outputs.decideWhatToDo()
    print(date.strftime('%Y-%m-%d'))
    #timeStampBook is to be queried by LIKE hence the [0] as it's the first elem in the dict
    bookings = getBookings({'timeStampBook':str(date.strftime('%Y-%m-%d'))+'%'},[0])
    bookingTimes = []
    for i in range(0,len(bookings)):
        #Remove date and append to booking times
        bookingTimes.append(bookings[i-1][2][11:])
    curTime = openTime
    if openTime <= absOpenTime:
        curTime = absOpenTime
    if closeTime >= absCloseTime:
        closeTime = absCloseTime
    
    while curTime <= closeTime:
        #Loop through bookings, increment 1 bookingLength at a time
        #If it matches a booking then don't add that time to the list
        if str(curTime.time()) not in bookingTimes:
            print("Aavailable: {}".format(curTime.time()))
        curTime = curTime + timedelta(minutes=int(bookingLength))
    outputs.decideWhatToDo()