Exemple #1
0
def edit(edit_book):
    print('''I'm going to show you each element of the book.  If you don't want
              to change it, just press enter.  Otherwise, enter a new value.
              For multiple authors and tags, separate them by a comma.
              e.g. author1,author2,author3''')
    new_book = {}
    new_book['barcode'] = input("Barcode: " + str(edit_book.bc))
    new_book['isbn'] = input("ISBN: " + str(edit_book.isbn))
    new_book['title'] = input("Title: " + str(edit_book.title))  # doesn't pull info for anything below.
    new_book['authors'] = input("Authors: " + str(edit_book.authors))
    new_book['pages'] = input("Number of Pages: " + str(edit_book.pages))
    new_book['publ_year'] = input("Publication Year: " + str(edit_book.publ_year))
    new_book['publisher'] = input("Publisher: " + str(edit_book.publisher))
    new_book['location'] = input("Location: " + str(edit_book.location))
    new_book['description'] = input("Description: " + str(edit_book.description))
    new_book['call_num'] = input("Call number: " + str(edit_book.call_num))
    new_book['tags'] = input("Tags: " + str(edit_book.tags))

    for key, value in new_book.items():
        if value == '':
            new_book[key] = None

    old_bc = edit_book.bc # we need this to ensure we don't create a duplicate db entry
    edit_book.edit(new_book['barcode'], new_book['isbn'], new_book['title'], new_book['authors'],
                   new_book['pages'], new_book['publ_year'], new_book['publisher'],
                   new_book['location'], new_book['description'], new_book['call_num'],
                   new_book['tags'])
    the_db = Bdb(dbLocation)
    if edit_book.bc is None:
        the_db.store(edit_book)
    else:
        the_db.delete(Book(old_bc))
        the_db.store(edit_book)
    print("Success!")
Exemple #2
0
def edit(edit_book):
    print('''I'm going to show you each element of the book.  If you don't want
              to change it, just press enter.  Otherwise, enter a new value.
              For multiple authors and tags, separate them by a comma.
              e.g. author1,author2,author3''')
    new_book = {}
    new_book['barcode'] = input("Barcode: " + str(edit_book.bc))
    new_book['isbn'] = input("ISBN: " + str(edit_book.isbn))
    new_book['title'] = input(
        "Title: " +
        str(edit_book.title))  # doesn't pull info for anything below.
    new_book['authors'] = input("Authors: " + str(edit_book.authors))
    new_book['pages'] = input("Number of Pages: " + str(edit_book.pages))
    new_book['publ_year'] = input("Publication Year: " +
                                  str(edit_book.publ_year))
    new_book['publisher'] = input("Publisher: " + str(edit_book.publisher))
    new_book['location'] = input("Location: " + str(edit_book.location))
    new_book['description'] = input("Description: " +
                                    str(edit_book.description))
    new_book['call_num'] = input("Call number: " + str(edit_book.call_num))
    new_book['tags'] = input("Tags: " + str(edit_book.tags))

    for key, value in new_book.items():
        if value == '':
            new_book[key] = None

    old_bc = edit_book.bc  # we need this to ensure we don't create a duplicate db entry
    edit_book.edit(new_book['barcode'], new_book['isbn'], new_book['title'],
                   new_book['authors'], new_book['pages'],
                   new_book['publ_year'], new_book['publisher'],
                   new_book['location'], new_book['description'],
                   new_book['call_num'], new_book['tags'])
    the_db = Bdb(dbLocation)
    if edit_book.bc is None:
        the_db.store(edit_book)
    else:
        the_db.delete(Book(old_bc))
        the_db.store(edit_book)
    print("Success!")
Exemple #3
0
def add_book():
    add_option = input('''Let's add a book.  How would you like to add it?\n
                              1) Manually\n
                              2) Search by ISBN\n
                              3) Search by Title: ''')

    add_option = int(add_option)

    if add_option == 1:
        manual_add = {}
        print("If you have multiple authors or tags, please separate them with a comma.")
        print("e.g. author1,author2,author3")
        print("To autogenerate a barcode, enter -1 for it.")
        print()
        for item in terms:
            manual_add[item] = input("Please enter the " + item + ": ")

        for item in manual_add:
            if item in substitutions:
                manual_add[substitutions[item]] = manual_add.pop(item)

        manual_book = create_book_from_dict(manual_add)
        book_db = Bdb(dbLocation)
        book_db.store(manual_book)

    elif add_option == 2:
        isbn = input("Please enter the 10 or 13 digit ISBN: ")
        lookup = Lookup()
        book = lookup.by_isbn(isbn)
        bc = input('''Please enter a unique barcode, or -1 to autogenerate: ''')

        bc = int(bc)

        book.bc = bc

        location = input('''Please enter the location of the book, default blank: ''')
        book.location = location

        call_num = input('''Please enter the call number of the book: ''')
        book.call_num = call_num

        tags = input('''Please enter any tags, separated by a comma: ''')
        tags = tags.strip()
        book.tags = tags

        print('''Ok, everything should be set.  I'll show you what I've got,
        and if it looks good, just press enter, otherwise type something in
        and I'll return you to the beginning.''')

        book.print_check()

        is_ok = input("")

        if is_ok != "":  # not 100% sure this will work
            raise ValueError
        else:
            book_db = Bdb(dbLocation)
            book_db.store(book)

    elif add_option == 3:
        title = input("Please enter the title you'd like to search for:")
        lookup = Lookup()
        input("The following are the results.  Please enter the number of the " +
                  "result you'd like.  Press any key to display them.")
        books = []
        for index, book in enumerate(lookup.by_title(title), start=1):
            if index == 11:
                break  # only print first 10 results?? Not very elegant.
            print('%i) Title: %s, Author(s): %s' % (
                index,
                book.title,
                str(book.authors).strip('[]')
            ))
            books.append(book)
        user_choice = input("Which result would you like? Or hit enter for none.")

        if user_choice == '':
            return 2

        user_choice = int(user_choice)

        user_choice -= 1  # need to compensate for off-by-one.

        book = books[user_choice]

        bc = input('''Please enter a unique barcode, or -1 to autogenerate: ''')
        bc = int(bc)
        book.bc = bc

        location = input('''Please enter the location of the book, default blank: ''')
        book.location = location

        call_num = input('''Please enter the call number of the book: ''')
        book.call_num = call_num

        tags = input('''Please enter any tags, separated by a comma: ''')
        tags = tags.strip()
        book.tags = tags

        assert isinstance(book, Book)
        print('''Ok, everything should be set.  I'll show you what I've got,
        and if it looks good, just press enter, otherwise type something in
        and I'll return you to the beginning.''')

        book.print_check()

        is_ok = input("")

        if is_ok != "":
            raise ValueError  # should consider changing to a UserQuit exception.
        else:
            book_db = Bdb(dbLocation)
            book_db.store(book)
Exemple #4
0
def add_book():
    add_option = input('''Let's add a book.  How would you like to add it?\n
                              1) Manually\n
                              2) Search by ISBN\n
                              3) Search by Title: ''')

    add_option = int(add_option)

    if add_option == 1:
        manual_add = {}
        print(
            "If you have multiple authors or tags, please separate them with a comma."
        )
        print("e.g. author1,author2,author3")
        print("To autogenerate a barcode, enter -1 for it.")
        print()
        for item in terms:
            manual_add[item] = input("Please enter the " + item + ": ")

        for item in manual_add:
            if item in substitutions:
                manual_add[substitutions[item]] = manual_add.pop(item)

        manual_book = create_book_from_dict(manual_add)
        book_db = Bdb(dbLocation)
        book_db.store(manual_book)

    elif add_option == 2:
        isbn = input("Please enter the 10 or 13 digit ISBN: ")
        lookup = Lookup()
        book = lookup.by_isbn(isbn)
        bc = input(
            '''Please enter a unique barcode, or -1 to autogenerate: ''')

        bc = int(bc)

        book.bc = bc

        location = input(
            '''Please enter the location of the book, default blank: ''')
        book.location = location

        call_num = input('''Please enter the call number of the book: ''')
        book.call_num = call_num

        tags = input('''Please enter any tags, separated by a comma: ''')
        tags = tags.strip()
        book.tags = tags

        print('''Ok, everything should be set.  I'll show you what I've got,
        and if it looks good, just press enter, otherwise type something in
        and I'll return you to the beginning.''')

        book.print_check()

        is_ok = input("")

        if is_ok != "":  # not 100% sure this will work
            raise ValueError
        else:
            book_db = Bdb(dbLocation)
            book_db.store(book)

    elif add_option == 3:
        title = input("Please enter the title you'd like to search for:")
        lookup = Lookup()
        input(
            "The following are the results.  Please enter the number of the " +
            "result you'd like.  Press any key to display them.")
        books = []
        for index, book in enumerate(lookup.by_title(title), start=1):
            if index == 11:
                break  # only print first 10 results?? Not very elegant.
            print('%i) Title: %s, Author(s): %s' %
                  (index, book.title, str(book.authors).strip('[]')))
            books.append(book)
        user_choice = input(
            "Which result would you like? Or hit enter for none.")

        if user_choice == '':
            return 2

        user_choice = int(user_choice)

        user_choice -= 1  # need to compensate for off-by-one.

        book = books[user_choice]

        bc = input(
            '''Please enter a unique barcode, or -1 to autogenerate: ''')
        bc = int(bc)
        book.bc = bc

        location = input(
            '''Please enter the location of the book, default blank: ''')
        book.location = location

        call_num = input('''Please enter the call number of the book: ''')
        book.call_num = call_num

        tags = input('''Please enter any tags, separated by a comma: ''')
        tags = tags.strip()
        book.tags = tags

        assert isinstance(book, Book)
        print('''Ok, everything should be set.  I'll show you what I've got,
        and if it looks good, just press enter, otherwise type something in
        and I'll return you to the beginning.''')

        book.print_check()

        is_ok = input("")

        if is_ok != "":
            raise ValueError  # should consider changing to a UserQuit exception.
        else:
            book_db = Bdb(dbLocation)
            book_db.store(book)