def api(isbn):
    """ Give all the details about the book"""
    if request.method == "GET":
        res = db.execute(
            "SELECT title, author, year, isbn, reviews_count, average_rating FROM books WHERE isbn = :isbn",
            {
                "isbn": isbn
            }).fetchone()
        book = Book()

        if res is None:
            return render_template("error.html",
                                   message="404 book not found"), 404

        book.title, book.author, book.year, book.isbn, book.reviews_count, book.average_rating = res
        if res.reviews_count == 0 or res.average_rating == 0:
            book_aux = api_intern(isbn)
            book.average_rating = book_aux["books"][0]["average_rating"]
            book.reviews_count = book_aux["books"][0]["reviews_count"]

        response = {
            "title": book.title,
            "author": book.author,
            "year": book.year,
            "isbn": book.isbn,
            "review_count": book.reviews_count,
            "average_score": book.average_rating
        }
        return jsonify(response)
Ejemplo n.º 2
0
def test_book():
    book1 = Book("title1", "author1", "genre1 genre4", date(2021, 1, 1), 100)
    book2 = Book("title2", "author2", "genre2 genre4 genre5", date(2021, 4, 1),
                 200)
    book3 = Book("title3", "author3", "genre3 genre5", date(2019, 1, 2), 300)

    assert book1.title == "title1", "test failed book1 title"
    assert book2.title == "title2", "test failed book2 title"
    assert book3.title == "title3", "test failed book3 title"

    assert book1.author == "author1", "test failed book1 author"
    assert book2.author == "author2", "test failed book2 author"
    assert book3.author == "author3", "test failed book3 author"

    assert book1.genre == ["genre1", "genre4"], "test failed book1 genre"
    assert book2.genre == ["genre2", "genre4",
                           "genre5"], "test failed book2 genre"
    assert book3.genre == ["genre3", "genre5"], "test failed book3 genre"

    assert book1.reading_date == date(2021, 1, 1), "test failed book1 date"
    assert book2.reading_date == date(2021, 4, 1), "test failed book2 date"
    assert book3.reading_date == date(2019, 1, 2), "test failed book3 date"

    assert book1.pages == 100, "test failed book1 pages"
    assert book2.pages == 200, "test failed book2 pages"
    assert book3.pages == 300, "test failed book3 pages"
Ejemplo n.º 3
0
 def get_recent_comments(self) -> List[BoxLayout]:
     recent_comments = []
     if DEMO:
         img_paths = [
             'images/Demo/Books/1984.png',
             'images/Demo/Books/IHaveTheRightToDestroyMyself.png',
             'images/Demo/Books/NoPlaceLikeHere.png'
         ]
         books = [
             Book('1984', 'George Orwell', 'Dystopian Fiction', 328, 23),
             Book('I Have The Right To Destroy Myself', 'Young-Ha Kim',
                  'Fiction', 131),
             Book('No Place Like Here', 'Christina June', 'Fiction', 32,
                  231)
         ]
         comments = [
             Comment("I hated this book!", "user420"),
             Comment("I loved this! Couldn't put it down.", "user001"),
             Comment("What a wonderful book!", "user489")
         ]
         for i in range(3):
             recent_comments.append(
                 self.format_comment_preview(img_paths[i], books[i],
                                             comments[i]))
         return recent_comments
     else:
         pass
def details(isbn):
    if session["user"] is None:
        return login()
    """ Give all the details about the book"""
    book = Book()

    book.isbn, book.title, book.author, book.year, book.reviews_count, book.average_rating = db.execute(
        "SELECT isbn, title, author, year, reviews_count, average_rating FROM books WHERE isbn = :isbn",
        {
            "isbn": isbn
        }).fetchone()

    if book.average_rating == 0 or book.reviews_count == 0:
        book_aux = api_intern(isbn)

        book.average_rating = book_aux["books"][0]["average_rating"]
        book.reviews_count = book_aux["books"][0]["reviews_count"]
        db.execute(
            "UPDATE books SET average_rating = :average_rating, reviews_count = :reviews_count WHERE isbn=:isbn",
            {
                "isbn": isbn,
                "average_rating": float(book.average_rating),
                "reviews_count": int(book.reviews_count)
            })

        db.commit()
    if request.method == "GET":
        return render_template("details.html", book=book)
    else:
        return "POST DETAILS"
Ejemplo n.º 5
0
 def createNewBook(self, name="", authors=None, pub_date="", publisher="", isbn="", language="", cover_path="",
                   rating=0, file_path="", tags=None, bookLists=None):
     ID = self.getID()
     ID += 1
     self.updateID(ID)
     book = Book(ID, name, None, pub_date, publisher, isbn, language, cover_path, rating, file_path, tags,
                 bookLists)
     self.addBook(book)
     if authors:
         book.setAuthors(self, authors)
Ejemplo n.º 6
0
def loadSolutionSamples() -> [Solution]:
    return [
        Solution('sample_solution',
                 libraries=[
                     Library(id=0, book_per_day=1, signup_time=1, books=[1, 2])
                 ],
                 books_from_libary=[[Book(1, 10)]])
    ]
Ejemplo n.º 7
0
def main():
    f = open("books.csv")
    reader = csv.reader(f)
    next(f)  #skip first line to avoid reading in column titles
    for isbn, title, author, year in reader:
        book = Book(title=title, author=author, isbn=isbn, year=year, rating=0)

        # check if isbn is a number
        isbncheck_int = is_int(book.isbn)
        if isbncheck_int == True:
            ## check if isbn already exists in database
            #isbncheck_existance = is_inDb(book.isbn)
            #if isbncheck_existance == False:
            book.add_bookToDatabase(db)
        #    #print(f"Added the following book to the database: Author: {author}, title: {title}, ISBN: {isbn}, year: {year}")
        #else:
        #    print(f"isbn already exists in database, book not added")
        else:
            print(f"isbn does not consist of numbers only")
    db.commit()
    print(f"import finished")
Ejemplo n.º 8
0
 def get_publication_buttons(
         self,
         search_keywords: Optional[str] = None
 ) -> List[TwoLineAvatarListItem]:
     buttons = []
     if DEMO:
         img_paths = [
             'images/Demo/Books/1984.png',
             'images/Demo/Books/IHaveTheRightToDestroyMyself.png',
             'images/Demo/Books/NoPlaceLikeHere.png',
             'images/Demo/Books/OneFlewOverTheCuckoosNest.png',
             'images/Demo/Books/TheGirlWithTheDragonTattoo.png',
             'images/Demo/Books/TheHobbit.png',
             'images/Demo/Books/TheNarrowRoadToTheDeepNorth.png',
             'images/Demo/Books/ThreeDayRoad.png',
             'images/Demo/Books/WhyWeSleep.png'
         ]
         books = [
             Book('1984', 'George Orwell', 'Dystopian Fiction', 328, 23),
             Book('I Have The Right To Destroy Myself', 'Young-Ha Kim',
                  'Fiction', 131),
             Book('No Place Like Here', 'Christina June', 'Fiction', 32,
                  231),
             Book('One Flew Over The Cuckoos Nest', 'Ken Kesey', 'Fiction',
                  500, 12),
             Book('The Girl With The Dragon Tattoo', 'Stieg Larsson',
                  'Fiction', 34),
             Book('The Hobbit', 'J. R. R. Tolkien', 'Fantasy', 300),
             Book('The Narrow Road To The Deep North', 'Richard Flanagan',
                  'Fantasy', 430),
             Book('Three Day Road', 'Joseph Boyden', 'Fiction', 223),
             Book('Why We Sleep', 'Matthew Walker', 'Fiction', 190)
         ]
         for i in range(9):
             book = books[i]
             if search_keywords is None or search_keywords.lower() in \
                     (book.title + book.author).lower():
                 buttons.append(
                     self.build_publication_button(img_paths[i], books[i]))
         return buttons
     else:
         # access database and based on search, add books from there
         pass
Ejemplo n.º 9
0
def main():
    print("Welcome to your SmartBookcase! What would you want today?\n")

    conn = sqlite3.connect('bookcase.sqlite')
    cursor = conn.cursor()
    cursor.execute('''CREATE TABLE IF NOT EXISTS Bookcase 
      (title TEXT, author_id INTEGER, genre_id INTEGER, reading_year INTEGER, reading_month INTEGER, reading_day INTEGER, pages INTEGER)'''
                   )
    cursor.execute('''CREATE TABLE IF NOT EXISTS Author
      (id	INTEGER NOT NULL, name TEXT, PRIMARY KEY("id"))''')
    cursor.execute('''CREATE TABLE IF NOT EXISTS Genre
      (id	INTEGER NOT NULL, name TEXT, PRIMARY KEY("id"))''')
    bookcase_data = cursor.execute("SELECT * FROM Bookcase").fetchall()
    books = list()
    for book in bookcase_data:
        cursor.execute("SELECT name FROM Author WHERE id=?", (book[1], ))
        author = cursor.fetchone()[0]
        cursor.execute("SELECT name FROM Author WHERE id=?", (book[2], ))
        genre = cursor.fetchone()[0]
        books.append(
            Book(book[0], author, genre, date(book[3], book[4], book[5]),
                 book[6]))

    bookcase = Bookcase(books)

    while True:
        command = input(
            "Type 1 if you want to add a new book to your bookcase.\nType 2 if you want to see all of your bookcase.\nType 3 if you want to search by something in your bookcase.\nType 4 if you want to know how much pages you have read.\nType 5 if you want to QUIT.\n"
        )

        try:
            command = int(command)
        except:
            print("Please, type a valid command.")
            continue

        if command == 1:
            bookcase.add_new_book(new_book(cursor))
            conn.commit()
        elif command == 2:
            print_by_parameter(bookcase).print()
        elif command == 3:
            search(bookcase)
        elif command == 4:
            print(sum_pages(bookcase))
        elif command == 5:
            break
        elif command != 0:
            print("Please, type a valid command.")
        print("--------------------------------------")
Ejemplo n.º 10
0
def parseRetBooks(ret):
    books = []
    for row in ret:
        ID = row[0]
        name = row[1]
        authors = parseStrListString(row[2])
        pub_date = row[3]
        publisher = row[4]
        isbn = row[5]
        language = row[6]
        cover_path = row[7]
        rating = row[8]
        file_path = row[9]
        tags = parseStrListString(row[10])
        booklists = parseStrListString(row[11])
        book = Book(ID, name, authors, pub_date, publisher, isbn, language, cover_path, rating, file_path, tags,
                    booklists)
        books.append(book)
    return books
Ejemplo n.º 11
0
def new_book(cursor):
    title = input("What is its title? ").strip().lower()
    author = input("Who is the author? ").strip().lower()
    genre = input("Which genre it is?").strip()
    pages = int(input("How many pages does it have? ").strip())
    today_date = date.today()

    cursor.execute("INSERT OR IGNORE INTO Author (name) VALUES (?)",
                   (author, ))
    cursor.execute("SELECT id FROM Author WHERE name=?", (author, ))
    author_id = cursor.fetchone()[0]
    cursor.execute("INSERT OR IGNORE INTO Genre (name) VALUES (?)", (genre, ))
    cursor.execute("SELECT id FROM Genre WHERE name=?", (genre, ))
    genre_id = cursor.fetchone()[0]
    cursor.execute("INSERT INTO Bookcase VALUES (?, ?, ?, ?, ?, ?, ?)",
                   (title, author_id, genre_id, today_date.year,
                    today_date.month, today_date.day, pages))

    return Book(title, author, genre, today_date, pages)
Ejemplo n.º 12
0
def importdata(filename):
    with open(f"./inputdata/{filename}") as inputfile:
        lines = inputfile.readlines()
        library_count = int(lines[0].strip("\n").split(" ")[1])
        available_days = int(lines[0].strip("\n").split(" ")[2])
        book_scores = lines[1].strip("\n").split(" ")
        book_scores = [int(i) for i in book_scores]
        # Create our books
        for id, value in enumerate(book_scores):
            Book(id, value)
        lib_id = 0
        # Create librarys
        for i in range(2, 4 + library_count, 2):
            first_line = lines[i].strip("\n").split(" ")
            second_line = lines[i + 1].strip("\n").split(" ")
            signup_time = int(first_line[1])
            b_per_day = int(first_line[2])
            available_books = list(set([int(i) for i in second_line]))
            Library(lib_id, signup_time, b_per_day, available_books)
            lib_id += 1
    return available_days
Ejemplo n.º 13
0
def main():
    #depickle instances into lists
    book_list = list()
    
    print("Welcome to ITrack, the terminal based invoice tracker. Type HELP at any point to get help.")
    print("ITrack is a free project maintained in my spare time. Don't expect it to work the way it should or be supported all of the time.")
    print("ITrack is free software licenced under the BSD Licence. This is a very permissive licence. Do what you wish with this software.")
    if len(book_list) < 1:
        print("\nNo books detected. Creating a new book.")
        cname = input("Company Name? ")
        book_list.append(Book(cname))
    
    print("Please select a book: ")
    j = 0
    for i in book_list:
        print(j, " : ", i.getCompanyName())
        j += 1
    pick = input("Please enter the number of the book you wish to start editing: ")
    current_book = book_list[int(pick)]
    print("T! Current Book = ", current_book.getCompanyName())
    while True:
        cmd = input(">>> ")
        parsing.parser(cmd)
Ejemplo n.º 14
0
def test_bookcase():
    book1 = Book("title1", "author1", "genre1 genre4", date(2021, 1, 1), 100)
    book2 = Book("title2", "author2", "genre2 genre4 genre5", date(2021, 4, 1),
                 200)
    book3 = Book("title3", "author3", "genre3 genre5", date(2019, 1, 2), 300)
    book4 = Book("title4", "author4", "genre1 genre2", date(2019, 10, 27), 400)

    bookcase1 = Bookcase([book1, book2, book3])
    bookcase2 = Bookcase([book1, book3])
    bookcase3 = Bookcase([book1])
    bookcase4 = Bookcase([])

    assert bookcase1.books == [book1, book2,
                               book3], "test failed bookcase1 books"
    assert bookcase2.books == [book1, book3], "test failed bookcase2 books"
    assert bookcase3.books == [book1], "test failed bookcase3 books"
    assert bookcase4.books == [], "test failed bookcase4 books"

    assert bookcase1.search_by_parameter("title1", "author1", "genre1") == [
        book1
    ], "test failed bookcase1 search_by_parameter book1"
    assert bookcase1.search_by_parameter(
        "title1", "author1",
        "genre2") == [], "test failed bookcase1 search_by_parameter no match"
    assert bookcase1.search_by_parameter("", "", "") == [
        book1, book2, book3
    ], "test failed bookcase1 search_by_parameter empty"
    assert bookcase2.search_by_parameter(
        "title1", "",
        "genre1") == [book1], "test failed bookcase2 search_by_parameter book1"
    assert bookcase2.search_by_parameter(
        "title2", "author2",
        "") == [], "test failed bookcase2 search_by_parameter no match"
    assert bookcase3.search_by_parameter(
        "title1", "",
        "") == [book1], "test failed bookcase3 search_by_parameter book1"
    assert bookcase3.search_by_parameter(
        "", "author3",
        "") == [], "test failed bookcase3 search_by_parameter no match"
    assert bookcase3.search_by_parameter(
        "", "",
        "") == [book1], "test failed bookcase3 search_by_parameter empty"
    assert bookcase4.search_by_parameter(
        "", "", "") == [], "test failed bookcase4 search_by_parameter empty"
    assert bookcase4.search_by_parameter(
        "title1", "author2",
        "genre3") == [], "test failed bookcase4 search_by_parameter no"

    assert bookcase1.is_empty() == 0, "test failed bookcase1 is_empty"
    assert bookcase2.is_empty() == 0, "test failed bookcase2 is_empty"
    assert bookcase3.is_empty() == 0, "test failed bookcase3 is_empty"
    assert bookcase4.is_empty() == 1, "test failed bookcase4 is_empty"

    assert bookcase1.sum_pages(
        "", "") == 600, "test failed bookcase1 sum_pages all time"
    assert bookcase1.sum_pages(
        "2021-01-01",
        "2021-05-13") == 300, "test failed bookcase1 sum_pages year"
    assert bookcase1.sum_pages(
        "2021-02-01",
        "2021-05-13") == 200, "test failed bookcase1 sum_pages month"
    assert bookcase1.sum_pages(
        "2020-01-01",
        "2020-12-31") == 0, "test failed bookcase1 sum_pages empty time"
    assert bookcase2.sum_pages(
        "", "") == 400, "test failed bookcase1 sum_pages all time"
    assert bookcase2.sum_pages(
        "2021-01-01",
        "2021-05-13") == 100, "test failed bookcase2 sum_pages year"
    assert bookcase2.sum_pages(
        "2020-01-01",
        "2020-12-31") == 0, "test failed bookcase2 sum_pages empty time"
    assert bookcase3.sum_pages(
        "", "") == 100, "test failed bookcase1 sum_pages all time"
    assert bookcase3.sum_pages(
        "2020-01-01",
        "2020-12-31") == 0, "test failed bookcase3 sum_pages empty time"
    assert bookcase4.sum_pages(
        "", "") == 0, "test failed bookcase1 sum_pages all time"

    assert bookcase1.order_by_parameter(
        "title").books == bookcase1.order_by_parameter("author").books == [
            book1, book2, book3
        ], "test failed bookcase1 order_by_parameter title and author"
    assert bookcase1.order_by_parameter("reading_date").books == [
        book3, book1, book2
    ], "test failed bookcase1 order_by_parameter date"
    assert bookcase2.order_by_parameter(
        "title").books == bookcase2.order_by_parameter("author").books == [
            book1, book3
        ], "test failed bookcase2 order_by_parameter title and author"
    assert bookcase2.order_by_parameter("reading_date").books == [
        book3, book1
    ], "test failed bookcase2 order_by_parameter date"
    assert bookcase3.order_by_parameter(
        "title").books == bookcase3.order_by_parameter(
            "author").books == bookcase3.order_by_parameter(
                "reading_date").books == [
                    book1
                ], "test failed bookcase3 order_by_parameter"
    assert bookcase4.order_by_parameter(
        "title").books == bookcase4.order_by_parameter(
            "author").books == bookcase4.order_by_parameter(
                "reading_date"
            ).books == [], "test failed bookcase4 order_by_parameter"

    bookcase1.add_new_book(book4)
    bookcase2.add_new_book(book4)
    bookcase3.add_new_book(book4)
    bookcase4.add_new_book(book4)

    assert bookcase1.books == [
        book1, book2, book3, book4
    ], "test failed bookcase1 books after add_new_book"
    assert bookcase2.books == [
        book1, book3, book4
    ], "test failed bookcase2 books after add_new_book"
    assert bookcase3.books == [
        book1, book4
    ], "test failed bookcase3 books after add_new_book"
    assert bookcase4.books == [
        book4
    ], "test failed bookcase4 books after add_new_book"

    assert bookcase1.search_by_parameter(
        "title4", "author4", "genre1") == bookcase2.search_by_parameter(
            "title4", "author4", "genre1") == bookcase3.search_by_parameter(
                "title4", "author4", "genre1"
            ) == bookcase4.search_by_parameter(
                "title4", "author4", "genre1") == [
                    book4
                ], "test failed search_by_parameter book4 after add_new_book"

    assert bookcase1.is_empty() == bookcase2.is_empty() == bookcase3.is_empty(
    ) == bookcase4.is_empty() == 0, "test failed is_empty after add_new_book"

    assert bookcase1.sum_pages(
        "", "") == 1000, "test failed bookcase1 sum_pages after add_new_books"
    assert bookcase1.sum_pages(
        "", "") == 800, "test failed bookcase2 sum_pages after add_new_books"
    assert bookcase1.sum_pages(
        "", "") == 500, "test failed bookcase3 sum_pages after add_new_books"
    assert bookcase4.sum_pages(
        "", "") == 400, "test failed bookcase4 sum_pages after add_new_books"

    assert bookcase1.order_by_parameter("pages") == [
        book4, book3, book2, book1
    ], "test failed bookcase1 order_by_parameter after add_new_book"
Ejemplo n.º 15
0
    def __repr__(self):
        return f"BookID: {self.id}"


class TEST:
    all_test = []

    def __init__(self, id, books):
        self.id = id
        self.books = books
        TEST.all_test.append(self)


for i in test_list:
    Book(i, i)
    TEST(i, Book.all_books[0])

print("BOOK PERSOPECTOVE ___________")
for i in Book.all_books:
    print(i.shipped)

print("TEST PERSOPECTOVE ___________")
for i in TEST.all_test:
    print(i.books.shipped)

TEST.all_test[0].books.shipped = True

print("TEST PERSOPECTOVE ___________")
for i in TEST.all_test:
    print(i.books.shipped)
def add_book():
    book = Book()
    title = input("ENTER TITLE OF BOOK")
    author = input("ENTER AUTHOR OF BOOK")
    publish = input("ENTER PUBLISHER OF BOOK")
    pub_year = input("ENTER PUBLISH YEAR OF BOOK")
    id = input("ENTER ID OF BOOK")
    status = "Available"
    book.set_title(title)
    book.set_author(author)
    book.set_publish(publish)
    book.set_pub_year(pub_year)
    book.set_b_id(id)
    book.set_status(status)

    db_admin.add_book(book)
def remove_book():
    book = Book()
    b_id = input("ENTER BOOK ID TO BE REMOVED")
    book.set_b_id(b_id)

    db_admin.remove_book(book)