Example #1
0
    def borrowISBN(self, isbn):
        """
        A function created to borrow a book based on its ISBN

        Args:
            isbn: string of the isbn of the book looking to be borrowed
        """

        if self.validator.validateISBN(isbn):
            if self.validator.isbnExists(isbn):
                if self.validator.onLoan(self.username, isbn):
                    print("You can not borrow this book again.\n")
                else:
                    currentdate = datetime.now()
                    dueDate = currentdate.date() + timedelta(days=7)

                    eventID = self.calendar.createCalendarEvent(
                        isbn, self.username)

                    with DatabaseUtils() as db:

                        if (db.insertBorrow(isbn, self.username, eventID)):
                            print("Book ISBN {} sucessfully borrowed by {}.".
                                  format(isbn, self.username))
                            print("Due date is: " +
                                  dueDate.strftime(DATE_FORMAT))
                            print("A event has been set in our GoogleCalendar")
                        else:
                            self.calendar.removeCalendarEvent(
                                isbn, self.username)
                            print("Book unsucessfully borrowed due")
Example #2
0
    def returnBook(self, isbn):
        """A function created to return a book based on its ISBN

        Args:
            isbn: string of the isbn of the book looking to be borrowed
        """
        if self.validator.validateISBN(isbn):
            if self.validator.isbnExists(isbn):
                if self.validator.onLoan(self.username, isbn):
                    eventID = None

                    with DatabaseUtils() as db:
                        eventID = db.updateReturnDate(isbn, self.username)

                    if eventID is not None:
                        print(
                            "Book ISBN {} sucessfully returned by {}.".format(
                                isbn, self.username))
                        self.calendar.removeCalendarEvent(isbn, self.username)
                        print("EventID {} successfully remove".format(eventID))
                    else:
                        print(
                            "Book unsucessfully returned by {} due to db error"
                            .format(self.username))
                else:
                    print("You did not borrow Book ISBN {}".format(isbn))
                    print("Please return another book")
Example #3
0
    def __init__(self, username, config):
        self.username = username
        self.validator = Validator()
        self.calendar = CalendarUtils(config['gc']['credentials_path'])
        self.voice = VoiceSearchUtils()
        self.QR = QR()

        with DatabaseUtils() as db:
            db.createBookTable()
            db.createBorrowTable()
            db.insertSampleBook()
Example #4
0
    def searchBookByAuthor(self):
        """A function created to search for a book by Author

        Returns:
            True or False based on printList function
        """

        self.printSection("SEARCH BY AUTHOR")
        author = self.getSearchInput("Author: ")

        if self.validator.validateAuthor(author):
            with DatabaseUtils() as db:
                return self.printList("search results",
                                      "all search results", BOOK_HEADERS,
                                      db.getBooksByAuthor(author))
Example #5
0
    def searchBookByTitle(self):
        """A function created to search for a book by Title

        Returns:
            True or False based on printList function
        """

        self.printSection("SEARCH BY TITLE")

        title = self.getSearchInput("Title: ")

        if self.validator.validateTitle(title):
            with DatabaseUtils() as db:
                return self.printList("search results", "all search results",
                                      BOOK_HEADERS, db.getBooksByTitle(title))
Example #6
0
    def searchBookByISBN(self):
        """
        A function created to search for a book by ISBN

        Returns:
            True or False based on printList function
        """

        self.printSection("SEARCH BY ISBN")

        isbn = self.getSearchInput("ISBN: ")

        if self.validator.validateISBN(isbn):
            with DatabaseUtils() as db:
                return self.printList("search results", "all search results",
                                      BOOK_HEADERS, db.getBookByISBN(isbn))
Example #7
0
    def isbnExists(self, isbn):
        """
        A function to check that the isbn exists in the library

        Args:
            isbn: string to be checked

        Returns:
            True is the isbn exists
            False if it doesnt exist
        """

        # check if isbn exits in the database
        with DatabaseUtils() as db:
            if not db.getBookByISBN(isbn):
                print("Book ISBN {} does not exist".format(isbn))
                print("Please try again")
                return False
            else:
                return True
Example #8
0
    def onLoan(self, username, isbn):
        """
        A function to check if the user has the isbn book on loan

        Args:
            username: string to check records against
            isbn: string to check records against

        Returns:
            True is the book is on loan to this user
            False if it isnt
        """

        # check if the user has not returned the book
        with DatabaseUtils() as db:
            currentLoan = db.stillOnLoan(username, isbn)
            if currentLoan is not None:
                print("You are currently borrowing book ISBN {}".format(isbn))
                print("Book ISBN {} was borrowed on {}".format(
                    isbn, currentLoan[0]))
                print("It will be due on {}".format(currentLoan[1]))
                return True
            else:
                return False
Example #9
0
 def listBorrowsByUser(self):
     """A function to list the books borrowed by the user"""
     with DatabaseUtils() as db:
         self.printList("user borrow records", "your borrow records",
                        BORROW_HEADERS,
                        db.getBorrowsByUsername(self.username))
Example #10
0
 def listBooks(self):
     """A function to list the books"""
     with DatabaseUtils() as db:
         self.printList("books", "all books", BOOK_HEADERS, db.getBooks())