コード例 #1
0
def load_database(iris_native):
    book_db = data['database']

    iris_native.kill(book_db)

    book_list = []
    with open('data/books.csv') as f:
        lines = f.readlines()

        for line in lines:
            book_list.append(line.strip('\n'))

    for i in range(1, len(book_list)):
        book = Book()
        book_info = book_list[i]
        book_info = book_info.split(',')
        book.title = book_info[0]
        book.author = book_info[1]
        book.publisher = book_info[2]
        book.page_count = book_info[3]
        book.pic_url = book_info[4]
        book.available = True

        iris_native.set(book.title, book_db, i, "title")
        iris_native.set(book.author, book_db, i, "author")
        iris_native.set(book.publisher, book_db, i, "publisher")
        iris_native.set(book.page_count, book_db, i, "page_count")
        iris_native.set(book.pic_url, book_db, i, "pic_url")
        iris_native.set(book.available, book_db, i, "available")

    print("Loaded books into database")
コード例 #2
0
def initialize_book(iris_native, book_db, id):
    book = Book()
    book.id = id
    book.title = iris_native.get(book_db, id, "title")
    book.author = iris_native.get(book_db, id, "author")
    book.publisher = iris_native.get(book_db, id, "publisher")
    book.page_count = iris_native.get(book_db, id, "page_count")
    book.pic_url = iris_native.get(book_db, id, "pic_url")
    book.available = iris_native.get(book_db, id, "available")

    return book
コード例 #3
0
    elif option == '8':
        book_id = input('Book ID: ')
        book = Book.find_with_alert(book_id)
        if not book:
            continue
        print(
            "Enter the updated details. If you don't provide value it will remain unchanged"
        )
        name = input(f'Book name: ({book.name}): ').strip()
        author = input(f'Book author: ({book.author}): ').strip()
        available = input(f'Books available: ({book.available}): ').strip()
        if name:
            book.name = name
        if author:
            book.author = author
        if available:
            book.available = available
        if name or author or available:
            book.save()
            print('Details updated successfully')

    elif option == '9':
        book_id = input('Book ID: ')
        if confirm():
            member = Book.find_with_alert(book_id)
            Book.delete(book_id)
            print('Book deleted successfully')

    elif option == '10':
        member_id = input('Member id: ')
コード例 #4
0
from models.data_base import Data_base
from models.book import Book

if __name__ == '__main__':
    db = Data_base().library
    new_book = Book()
    new_book.title = input('title: ')
    new_book.author = input('author: ')
    new_book.publisher = input('publisher: ')
    new_book.rating = float(input('rating: '))
    new_book.publishing_date = int(input('publishing_date: '))
    new_book.genre = input('genre: ')
    new_book.description = input('description: ')
    new_book.img = open(input('image: '), 'rb')
    new_book.save()