Esempio n. 1
0
def rentABook(commandInPieces):
    repoCaller = Repo()
    ghostBook = Book(commandInPieces[1], " ", " ")
    ghostClient = Client(commandInPieces[2], " ")
    rentDateString = commandInPieces[3].split('/')
    rentDate = datetime.datetime(int(rentDateString[0]),
                                 int(rentDateString[1]),
                                 int(rentDateString[2]))
    try:
        validateRental(ghostBook, ghostClient)
        newRental = Rental("1", Book.getBookId(ghostBook),
                           Client.getClientId(ghostClient), rentDate,
                           "notReturned")
        repoCaller.insertIntoRentals(newRental)
        repoCaller.loadIntoFiles()
        repoCaller.loadIntoPickle()
    except BookAlreadyRentedOrDoesntExistError:
        print(BookAlreadyRentedOrDoesntExistError())
    except ClientAlreadyExistsError:
        print(ClientAlreadyExistsError())
    return False