本文整理汇总了Python中book.Book类的典型用法代码示例。如果您正苦于以下问题:Python Book类的具体用法?Python Book怎么用?Python Book使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Book类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_decrease_number_of_copies
def test_decrease_number_of_copies(self):
book = Book("Lords", "Steven Moore", 2000, "Thriller", 2, 15)
book.decrease_number_of_copies(10)
self.assertEqual(5, book.number_of_copies)
book.decrease_number_of_copies(6)
self.assertNotEqual(-1, book.number_of_copies)
self.assertEqual(0, book.number_of_copies)
示例2: test_increase_number_of_copies
def test_increase_number_of_copies(self):
book = Book("Lords", "Steven Moore", 2000, "Thriller", 2, 0)
book.increase_number_of_copies(10)
self.assertEqual(10, book.number_of_copies)
book.increase_number_of_copies(5)
self.assertNotEqual(10, book.number_of_copies)
self.assertEqual(15, book.number_of_copies)
示例3: delete_book
def delete_book():
to_do = input('''We're going to delete a book. Do you have the barcode? [y/N]: ''')
if to_do.strip() == "" or to_do.strip().lower() == "n":
results = search()
i = 1
for item in results:
print((i + ") " + item)) # not sure how this will come out.
del_me = input("Which one is it? ")
del_me = int(del_me)
del_me = results[del_me - 1]
del_me = del_me.split(",")
del_me = Book(del_me[0]) # this is really fudged atm. serious testing needed
the_db = Bdb(dbLocation)
the_db.delete(del_me)
print("Deleted.")
elif to_do.strip().lower() == "y":
del_me = input("Ok, enter it now: ")
if del_me.strip() == "":
print("Invalid input.")
else:
del_me = int(del_me)
del_me = Book(del_me)
the_db = Bdb(dbLocation)
the_db.delete(del_me)
print("Deleted.")
示例4: __init__
class Tractatus:
# This is the book
tractatus = None
def __init__(self):
""" Construct the Tractatus """
# Build the Book object
self.tractatus = Book()
# Get the tractatus from text
SITE_ROOT = os.path.realpath(os.path.dirname(__file__))
all_text = open(os.path.join(SITE_ROOT, "static", "tractatus.txt"), 'r')
output = all_text.readlines()
# Read the file line by line into self.tractatus
# The actual content only begins at line 30 until the end
for i in range(30, len(output)):
complete_string = str(output[i])
# We need to separate the index and the text
split_string = complete_string.partition(" ")
index = split_string[0]
text = split_string[2].rstrip("\n")
# Load them in
self.tractatus.add_section(index, text)
# print self.tractatus
def get_book(self):
return self.tractatus
示例5: by_title
def by_title(self, title):
"""
Search for a book on OpenLibrary by title
@param title: the title to search for
@return: the raw data of all results
"""
title = title.replace(' ', '+').lower()
url = urllib.request.urlopen(self.search_url+'title='+title)
data = simplejson.load(url)['docs']
for result in data:
book = Book(0)
book.title = result['title']
try:
book.authors = ', '.join(result['author_name']) if isinstance(result['publisher'], list) else result['author_name']
except KeyError:
book.authors = "None"
try:
book.publisher = ', '.join(result['publisher']) if isinstance(result['publisher'], list) else result['publisher']
except KeyError:
book.publisher = "No publisher found."
try:
book.publ_year = result['first_publish_year']
except KeyError:
book.publ_year = 0
try:
book.description = ''.join(result['first_sentence'])
except KeyError:
book.description = "No description found."
yield book
示例6: test_read_book
def test_read_book():
book = Book('test/test_text_file.txt')
book.read_book()
chapters = book.get_chapters
assert len(chapters) == 2
assert chapters[0].get('title') == 'Chapter 1'
sentences = chapters[0].get('sentences')
assert len(sentences) == 4
示例7: parse_all_books
def parse_all_books():
for file in glob.glob("{}/*.txt".format(book_dir)):
print("Parsing... {}".format(file))
book = Book(file)
book.read_book()
book.count_distinct_words()
print(book)
all_books.append(book)
示例8: add_book
def add_book(self, b_name, b_quantity):
b = Book(name= b_name, quantity= int(b_quantity))
urllib.unquote(b.name)
self.response.write("> Voce cadastrou o livro: " + b.name + " com "+ str(b.quantity))
b.put()
示例9: delete
def delete(self, conn):
for row in self.select(conn):
book = Book(
row['id'],
row['title'],
None,
row['published_in'],
)
book.delete(conn)
print("")
示例10: update_location
def update_location(id):
book = Book(id)
if 'update_person' in request.form:
new_location = request.form['location']
else:
new_location = request.form['shelf']
book.update_location(new_location)
return render_book_info(book)
示例11: read_book
def read_book(self, bookname, read_what=None):
if self.suffix == "":
print bookname
filename = self.dir + "/" + bookname
else:
print bookname + "." + self.suffix
filename = self.dir + "/" + bookname + "." + self.suffix
book = Book(filename)
self.books.append(book)
self.current_monad = book.read_linear(self.current_monad) + 1
示例12: run
def run():
mbook = Book.parse(get_mtgox())
bbook = Book.parse(bitfloor.book(level=2))
mbook.flatten('0.01')
our_book, our_book2 = get_our_book()
# remove our stuff from bbook
# bbook will have the orders we don't control
bbook.subtract(our_book2)
# mbook will now have the gap needed to be filled by our orders
mbook.subtract(bbook)
funds = get_funds()
# get the total remaining area needed to fill
# find which factor of it we can fill with our total funds
sumb = sum(o.price*o.size for o in mbook.bids if o.size > 0)*D('1.04')
bfactor = min(1, funds['USD']/sumb) if sumb > 0 else 1
suma = sum(o.size for o in mbook.asks if o.size > 0)
afactor = min(1, funds['BTC']/suma) if suma > 0 else 1
print afactor, bfactor
print suma, sumb
# multiply everything positive by the factor
# mbook will now have what we need to provide to bitfloor's book
for o in mbook.bids:
if o.size > 0:
o.size *= bfactor
o.size = o.size.quantize(D('0.00000001'), rounding=decimal.ROUND_DOWN)
for o in mbook.asks:
if o.size > 0:
o.size *= afactor
o.size = o.size.quantize(D('0.00000001'), rounding=decimal.ROUND_DOWN)
# now, get the difference between what we need to provide and what we have
mbook.subtract(our_book2)
# cancel orders first which are above the gap
cancel(mbook, our_book, 'bid')
cancel(mbook, our_book, 'ask')
# send in orders to fill the gaps
for o in mbook.bids:
if o.size > SIZE_LIMIT:
print 'bid', o
bitfloor.buy(size=str(o.size), price=str(o.price))
for o in mbook.asks:
if o.size > SIZE_LIMIT:
print 'ask', o
bitfloor.sell(size=str(o.size), price=str(o.price))
示例13: _make_book
def _make_book(self, cell, year):
bookID, title, originalTitle = self._extract_titles(cell)
book = Book(bookID, title, originalTitle, year)
alt = filter(alt_text, cell)
if alt:
assert len(alt) == 1
#noinspection PyUnresolvedReferences
book.addTitles(*[x.strip() for x in re.split('\s*;\s+', alt[0].text.strip()[3:-1])])
return book
示例14: update
def update(self, conn, field, new_value):
for row in self.select(conn):
author_name = Authors(['name', '=', row[2]]).select(conn).fetchone()[1]
if field == "name":
author_name = new_value
book = Book(
row['id'],
row['title'],
author_name,
row['published_in'],
)
setattr(book, field, new_value)
book.save(conn)
示例15: create
def create(username):
index = r.hgetall(SESSION_PREFIX + username)
# 检查库存
for k, v in index.items():
stock = Book.get_stock(k)
if int(stock) < int(v):
return False
r.rename(SESSION_PREFIX + username, ORDER_PREFIX + username)
for k, v in index.items():
stock = Book.get_stock(k)
Book.set_stock(k, int(stock) - int(v))
db.orders.insert({'username': username, 'books': index})
return True