Esempio n. 1
0
 def add_dummy_entries(self):
     book1 = Book(*BOOK1)
     book2 = Book(*BOOK2)
     book3 = Book(*BOOK3)
     add_book(book1)
     add_book(book2)
     add_book(book3)
Esempio n. 2
0
 def __init__(self):
     print '''Would you like to:
     1. Go somewhere
     2. Call someone
     3. Read a book
     4. Play video games
     '''
     choice = raw_input(">: ")
     if choice == "1":
         print '''Where would you like to go?
         1. Library
         2. Gym
         3. Supermarket
         '''
         choice = raw_input(">: ")
         if choice == "1":
             Library()
         elif choice == "2":
             Gym()
         else:
             Groceries()
     elif choice == "2":
         Call()
     elif choice == "3":
         Book()
     else:
         VideoGames()
Esempio n. 3
0
    def test_book_model(self):
        books = [
            Book('9780062024039', 'Divergent', 'Veronica Roth', 2012,
                 'Fantasy', 3, 'NO', 'Read'),
            Book('9780439554930', 'Harry Potter #1', ' J.K. Rowling', 1997,
                 'Fantasy', 5, 'perfe', 'Currently Reading'),
            Book('0450040186', 'The Shining', 'Stephen King', 1980, 'Horror',
                 2, 'ok', 'Want To Read')
        ]

        self.book_model = BookModel()
        self.book_model.set_books(books)
        self.assertEqual(self.book_model.rowCount(), len(books))
        self.assertEqual(
            self.book_model.headerData(0, Qt.Horizontal, Qt.DisplayRole),
            'ISBN')
        self.assertEqual(
            self.book_model.headerData(1, Qt.Horizontal, Qt.DisplayRole),
            'Title')
        self.assertEqual(
            self.book_model.headerData(2, Qt.Horizontal, Qt.DisplayRole),
            'Author')
        self.assertEqual(
            self.book_model.headerData(3, Qt.Horizontal, Qt.DisplayRole),
            'Year')
        self.assertEqual(
            self.book_model.headerData(4, Qt.Horizontal, Qt.DisplayRole),
            'Genre')
        self.assertEqual(
            self.book_model.headerData(5, Qt.Horizontal, Qt.DisplayRole),
            'Rating')
        self.assertEqual(
            self.book_model.headerData(6, Qt.Horizontal, Qt.DisplayRole),
            'Review')
        self.assertEqual(
            self.book_model.headerData(7, Qt.Horizontal, Qt.DisplayRole),
            'Status')

        getters = ('get_isbn', 'get_title', 'get_author', 'get_year',
                   'get_genre', 'get_rating', 'get_review', 'get_status')
        for row in range(self.book_model.rowCount()):
            for column in range(COLUMNS):
                self.assertEqual(
                    getattr(books[row], getters[column]),
                    self.book_model.data(self.book_model.index(row, column),
                                         Qt.DisplayRole))
Esempio n. 4
0
    def addBook(self):
        # grab the info and create a new book in library list
        newBookTitle = str(raw_input("Title?: "))
        newBookPageCount = int(raw_input("Page Count?: "))
        newBookISBN = int(raw_input("ISBN?: "))

        self.books.append(
            Book(newBookTitle, newBookPageCount, newBookISBN, False))
Esempio n. 5
0
 def test_types(self):
     book = Book('9780062024039', 'Divergent', 'Veronica Roth', 2012,
                 'Fantasy', 3, 'NO', 'Read')
     self.assertTrue(book.get_isbn, str)
     self.assertTrue(book.get_title, str)
     self.assertTrue(book.get_author, str)
     self.assertTrue(book.get_year, int)
     self.assertTrue(book.get_genre, str)
     self.assertTrue(book.get_rating, int)
     self.assertTrue(book.get_review, str)
     self.assertTrue(book.get_status, str)
Esempio n. 6
0
 def show_lib_button_click(self):
     books = select_all()
     if books == []:
         QMessageBox(QMessageBox.Information, "No results",
                     "There are no books in the library!").exec_()
         return
     else:
         book_model = BookModel()
         books = [Book(*book) for book in books]
         book_model.set_books(books)
         self.show_table(book_model)
Esempio n. 7
0
    def show_wishlist_button_click(self):
        text = 'Want Тo Read'
        books = select_by_status(text)

        if books == []:
            QMessageBox(QMessageBox.Information, "No results",
                        "There are no books in the wishlist!").exec_()
            return
        else:
            wishlist_model = BookModel()
            books = [Book(*book) for book in books]
            wishlist_model.set_books(books)
            self.show_table(wishlist_model)
Esempio n. 8
0
 def test_init(self):
     book = Book('9780062024039', 'Divergent', 'Veronica Roth', 2012,
                 'Fantasy', 3, 'NO', 'Read')
     self.assertEqual(book.get_isbn, '9780062024039')
     self.assertNotEqual(book.get_isbn, '1780062024039')
     self.assertEqual(book.get_title, 'Divergent')
     self.assertNotEqual(book.get_title, 'Bookoholic')
     self.assertEqual(book.get_author, 'Veronica Roth')
     self.assertNotEqual(book.get_author, 'Veronica Lqlqlq')
     self.assertEqual(book.get_year, 2012)
     self.assertNotEqual(book.get_year, 2017)
     self.assertEqual(book.get_genre, 'Fantasy')
     self.assertNotEqual(book.get_genre, 'Horror')
     self.assertEqual(book.get_rating, 3)
     self.assertNotEqual(book.get_rating, 23)
     self.assertEqual(book.get_review, 'NO')
     self.assertNotEqual(book.get_review, 'Yes')
     self.assertEqual(book.get_status, 'Read')
     self.assertNotEqual(book.get_status, 'Reading')
Esempio n. 9
0
    def add_button_click(self):
        isbn = self.isbn_line_edit.text()
        title = self.title_line_edit.text()
        author = self.author_line_edit.text()
        year = self.year_line_edit.text()
        genre = self.genre_combo_box.currentText()
        rating = self.rating_slider.value()
        review = self.review_text_edit.toPlainText()
        status = self.status_combo_box.currentText()

        try:
            if self.information_validation(year, isbn):
                error_message = self.error_message(year, isbn)
                QMessageBox(
                    QMessageBox.Critical, "Error",
                    "Invalid " + error_message[:len(error_message) - 1] +
                    ". Please correct it!").exec_()
                return

            new_book = Book(isbn, string.capwords(title),
                            string.capwords(author), int(year),
                            string.capwords(genre), int(rating), review,
                            string.capwords(status))

            if new_book in self.books:
                QMessageBox(QMessageBox.Warning, "Warning",
                            "You have already added this book!").exec_()
                return

            self.books.append(new_book)
            if add_book(new_book) != None:
                QMessageBox(QMessageBox.Information, "Add Book",
                            "You successfully added this book!").exec_()
            else:
                QMessageBox(QMessageBox.Information, "Information",
                            "The book was NOT added!" +
                            "Please try again.").exec_()
        except:
            QMessageBox(QMessageBox.Information, "Add Book",
                        "ISBN must be unique.").exec_()
Esempio n. 10
0
__author__ = 'andydelso'

from book.library import Library
from book.book import Book

library = Library()

#the following and book library included for testing
library.books.append(Book("Wizard of Oz", 92, 1495421864, False))
library.books.append(Book("Off to be a Wizard", 386, 1612184715, False))
library.books.append(Book("The Alchemist", 197, 0061122416, False))

#library.addBook()
#library.addBook()
#library.addBook()

library.books[1].checkOut()

library.printBooks()

#book1 = Book("Wizard of Oz", 100, 1234567, False)

#if __name__ == '__main__':
Esempio n. 11
0
def main(item: str, **kwargs):
    # determine if application is a script file or frozen exe
    application_path = ""
    xml_file_name = kwargs.get('xml_filename', "")
    xml_file_name_scan_data = kwargs.get('xml_filename_scandata', "")
    json_file_name = kwargs.get('json_filename', "")
    ia_path = kwargs.get('ia_path', "")

    if item is None and ia_path is None:
        print("Error: Unrecognized Arguments")
        return

    if item is not None and \
            (xml_file_name is not None or xml_file_name_scan_data
             is not None or json_file_name is not None or ia_path is not None):
        print("Error: \"-item\" parameter should not be mixed with other parameters")
        return

    if item is not None:
        if getattr(sys, 'frozen', False):
            application_path = os.path.dirname(sys.executable)
        elif __file__:
            application_path = os.path.dirname(__file__)

        ia_path = os.path.join(application_path, "iaitems")

        if not os.path.exists(ia_path):
            os.mkdir(ia_path)

        xml_file_name = os.path.join(application_path, "iaitems", item, "".join([item, "_djvu", ".xml"]))
        xml_file_name_scan_data = os.path.join(application_path, "iaitems", item, "".join([item, "_scandata", ".xml"]))
        json_file_name = os.path.join(application_path, "iaitems", item, "".join([item, "_pages", ".json"]))
    else:
        xml_file_name = kwargs.get('xml_filename', None)
        xml_file_name_scan_data = kwargs.get('xml_filename_scandata', None)
        json_file_name = kwargs.get('json_filename', None)
        val_error = []
        if ia_path is None:
            val_error.append("is not provided")

        if xml_file_name is None:
            val_error.append("xml_filename is not provided")

        if json_file_name is None:
            val_error.append("json_filename is not provided")

        if ','.join(val_error) != "":
            print("Error: " + '\r\n'.join(val_error))
            return

        if not os.path.isdir(ia_path):
            print("Error: ia_path \"" + ia_path + "\" does not exist")
            return

        item = xml_file_name.lower().replace("_djvu.xml", "")
        # xml_file_name = os.path.join(ia_path, item, xml_file_name)
        xml_file_name = os.path.join(ia_path, xml_file_name)
        json_file_name = os.path.join(ia_path, json_file_name)
        # json_file_name = os.path.join(ia_path, item, json_file_name)
        if not os.path.isfile(xml_file_name):
            print("Error: xml_filename \"" + xml_file_name + "\" does not exist")
            return

        if xml_file_name_scan_data is not None and xml_file_name_scan_data != "":
            # item = xml_file_name.lower().replace("_scandata.xml", "")
            xml_file_name_scan_data = os.path.join(ia_path, xml_file_name_scan_data)
            # xml_filename_scan_data = os.path.join(ia_path, item, xml_filename_scan_data)
            if not os.path.isfile(xml_file_name_scan_data):
                print("Error: xml_filename_scandata \"" + xml_file_name_scan_data + "\" does not exist")
                return

    if not os.path.isfile(xml_file_name):
        from internetarchive import download
        print("Downloading " + item + "_djvu.xml from internet archive website...")
        download(item, verbose=True, destdir=ia_path, glob_pattern='*_djvu.xml')

        print("Downloading " + item + "_scandata.xml from internet archive website...")
        try:
            download(item, verbose=True, destdir=ia_path, glob_pattern='*_scandata.xml')
        except NameError:
            pass

    # Do auto printed page generation
    if os.path.isfile(xml_file_name):
        if os.path.exists(json_file_name):
            os.remove(json_file_name)  

        print("Generating printed pages...")

        bk = Book()
        bk.load_xml(xml_file_name)

        if not bk.has_valid_leaf_no:
            print("djvu error: unable to extract leaf number.")
            return

        scan_data = ScanData("")
        #if xml_file_name_scan_data is not None:
        #    if os.path.isfile(xml_file_name_scan_data):
        #        scan_data = ScanData(xml_file_name_scan_data)

        bk.generate_json(item, json_file_name, scan_data=scan_data)
        
    else:
        print("Error: File not found [" + xml_file_name + "]!")