本文整理汇总了Python中models.Book.author方法的典型用法代码示例。如果您正苦于以下问题:Python Book.author方法的具体用法?Python Book.author怎么用?Python Book.author使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Book
的用法示例。
在下文中一共展示了Book.author方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_books
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import author [as 别名]
def update_books(books = get_books()):
opener = urllib2.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
for book in books:
try:
b = Book.objects.filter(title=book['title']).count()
print '>>>', b
if not b:
b = Book()
b.title = book['title']
author = book['author']
last_name = author.split(' ')[-1]
first_name = ' '.join(author.split(' ')[:-1])
try:
author = Author.objects.get(first_name=first_name, last_name=last_name)
except:
author = Author(first_name=first_name, last_name=last_name)
author.save()
b.author = author
b.external_url = 'http://en.wikipedia.org'+book['link']
try:
content = opener.open('http://en.wikipedia.org'+book['link']).read()
s = Soup(content)
info = s.find('table', {'class':'infobox'})
img = info.find('img')
if img:
b.image = 'http:'+img.get('src')
except:
print "IMAGE FAILED FOR", book
b.save()
except Exception, e:
print e
print "WOAH TOTAL FAILURE", book
示例2: get
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import author [as 别名]
def get(self):
db = getUtility(IRelationalDatabase)
cr = db.cursor()
barcode = self.book.barcode
if barcode:
cr.execute("""SELECT
id,
barcode,
author,
title
FROM books
WHERE barcode = ?""",
(barcode,))
else:
cr.execute("""SELECT
id,
barcode,
author,
title
FROM books""")
rst = cr.fetchall()
cr.close()
books = []
for record in rst:
id = record['id']
barcode = record['barcode']
author = record['author']
title = record['title']
book = Book()
book.id = id
book.barcode = barcode
book.author = author
book.title = title
books.append(book)
return books
示例3: insert_data
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import author [as 别名]
def insert_data(self, data):
"""
Will handle inserting data into the database
"""
try:
# Check if book is in database, if so update else create
try:
book = db_session.query(Book).filter(Book.book_id == data.get('book_id')).one()
except NoResultFound:
book = Book()
book.title = data.get('title')
book.subtitle = data.get('subtitle')
book.author = data.get('author')
book.year = data.get('year')
book.pages = data.get('pages')
book.language = data.get('language')
book.publisher = data.get('publisher')
book.isbn = data.get('isbn')
book.format = data.get('format')
book.description = data.get('description')
book.file_source = data.get('file_source')
book.file_cover_source = data.get('file_cover_source')
book.file_location = data.get('file_location')
book.file_cover_location = data.get('file_cover_location')
book.book_id = data.get('book_id')
book.time_collected = data.get('time_collected')
db_session.add(book)
db_session.commit()
# self.track_stat('rows_added_to_db', rows_affected)
except Exception:
db_session.rollback()
logger.exception("Error adding to db {data}".format(data=data))
示例4: post
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import author [as 别名]
def post(self):
entity_key_urlsafe = self.request.get("entity_key")
book = None
book_seller_key = self.person.key
# Make sure POST request is given these names
book_image_url = self.request.get("image-url")
book_price = float(self.request.get("price"))
book_isbn = self.request.get("isbn")
book_author = self.request.get("author")
book_title = self.request.get("title")
book_dept = self.request.get("dept-abbrev")
book_condition_id = int(self.request.get("condition"))
if entity_key_urlsafe:
book_key = ndb.Key(urlsafe=entity_key_urlsafe)
book = book_key.get()
# keep same seller key
# don't need cart_key
book.price = book_price
if book_isbn:
book.isbn = book_isbn
if book_author:
book.author = book_author
if book_title:
book.title = book_title
if book_dept:
book.dept = book_dept.lower()
if book_condition_id:
book.condition_id = book_condition_id
book.image_url = book_image_url
else:
book = Book(parent=ROOT_BOOK_KEY, seller_key = book_seller_key, price=book_price,
image_url=book_image_url)
if book_isbn:
book.isbn = book_isbn
if book_author:
book.author = book_author
if book_title:
book.title = book_title
if book_dept:
book.dept = book_dept.lower()
if book_condition_id:
book.condition_id = book_condition_id
# TODO: Replace above with this when all fields are given
# book = Book(parent=ROOT_BOOK_KEY, seller_key = book_seller_key, price=book_price,
# image_url=book_image_url,
# isbn = book_isbn, author = book_author, title = book_title,
# dept = book_dept, comments = str(book_comments).strip())
logging.info("Adding Book: " + str(book))
book.put()
self.redirect(self.request.referer)
示例5: on_add_clicked
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import author [as 别名]
def on_add_clicked(self, *args):
barcode = self.ui.barcode.get_text()
author = self.ui.author.get_text()
title = self.ui.title.get_text()
book = Book()
book.barcode = barcode
book.author = author
book.title = title
self.add(book)
self.ui.list_store.append((book, barcode, author, title))
示例6: order_add_book_custom
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import author [as 别名]
def order_add_book_custom(request):
"""Add book to the current order with a custom title & author. Used for the
AJAX book adds of books with custom titles and/or authors."""
# If this is a non-unique book, fill in what attributes we can and continue
if request.POST.get('Title', False):
book = Book()
book.title = request.POST.get('Title', '')
book.author = request.POST.get('Author', '')
order_add_book(request, book)
else:
# The title is empty, which is the one field we require. We fail
# silently for now, but could do something here.
print 'Tried to add a custom book with no title to the current order, failing silently'
return order_render_as_response(request)
示例7: initialize_lists
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import author [as 别名]
def initialize_lists(self):
cm=Gtk.ListStore(object, str, str, str)
self.ui.catalog=cm
self.ui.catalog_view.set_model(cm)
for _ in range(3):
b=Book()
b.title="Brotherhood of the ring"
b.author="J.R.R.Tolkien"
b.barcode="123-1232"
self.append_book(b)
mm=Gtk.ListStore(object, int, str)
self.ui.members=mm
self.ui.member_view.set_model(mm)
for _ in range(3):
m=Member()
m.name="Jim Carry"
m.number=123
self.append_member(m)
示例8: add
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import author [as 别名]
def add(request):
if request.method == "POST":
form = BookAddForm(request.POST)
if form.is_valid():
book = Book()
book.title = form.cleaned_data['title']
book.author = form.cleaned_data['author']
book.press = form.cleaned_data['press']
book.year = form.cleaned_data['year']
book.save()
messages.success(request, "已保存")
form = BookAddForm()
else:
messages.error(request, "保存失败,请检查所填写的内容!")
else:
form = BookAddForm()
context = RequestContext(request, {
"form":form,
})
return render_to_response("add.html", context)
示例9: post
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import author [as 别名]
def post(self):
user = users.get_current_user()
if user:
# gather ip the pieces of data
bookshelf_name = user.nickname()
book = Book(parent=bookshelf_key(bookshelf_name))
book.username = user.nickname()
book.title = self.request.get('title')
book.author = self.request.get('author')
if self.request.get('in_series') == constants.CHECKED:
book.in_series = True
else:
book.in_series = False
book.series_name = self.request.get('series_name')
try:
book.book_in_series = int(self.request.get('book_in_series'))
except:
book.book_in_series = None
book.isbn = self.request.get('isbn')
try:
book.pub_year = int(self.request.get('pub_year'))
except:
book.pub_year = None
if self.request.get('was_it_read') == constants.CHECKED:
book.was_read = True
else:
book.was_read = False
try:
cdt = datetime.strptime(self.request.get('date_read'), '%m/%d/%Y')
cd = date(cdt.year, cdt.month, cdt.day)
book.completed_date = cd
except Exception, e:
logging.info("exception getting read date : " + str(e))
book.completed_date = None
book.put()
self.redirect('/books')
示例10: get_books_ml
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import author [as 别名]
def get_books_ml():
opener = urllib2.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
content = opener.open('http://www.modernlibrary.com/top-100/100-best-novels/').read()
s = Soup(content)
books = []
_list = []
for bl in s.findAll('div', {'class':'list-100'}):
_list += bl.findAll('li')
for b in _list:
title = b.find('strong').getText().title()
author = b.getText()[b.getText().find('by')+3:]
books.append({
'title':title,
'author':author,
})
for book in books:
try:
b = Book.objects.filter(title=book['title']).count()
print '>>>', b
if not b:
b = Book()
b.title = book['title']
author = book['author']
last_name = author.split(' ')[-1]
first_name = ' '.join(author.split(' ')[:-1])
try:
author = Author.objects.get(first_name=first_name, last_name=last_name)
except:
author = Author(first_name=first_name, last_name=last_name)
author.save()
b.author = author
b.save()
except Exception, e:
print e
print "WOAH TOTAL FAILURE", book
示例11: fetchCreateByISBN
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import author [as 别名]
def fetchCreateByISBN(isbn, dataSource, needInvoke):
book = Book.byISBN(isbn)
if needInvoke: dataSource = dataSource(isbn)
if not book:
book = Book()
book.title = dataSource.title
book.author = dataSource.author
book.isbn = dataSource.isbn
book.image = dataSource.image
book.imageSmall = dataSource.imageSmall
book.imageLarge = dataSource.imageLarge
book.amazonUrl = dataSource.detailUrl
book.numberOfPages = dataSource.numberOfPages
book.put()
book.tags = dataSource.genre
return book
示例12: run_api
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import author [as 别名]
def run_api():
"""function to hit new york times api and return all books and authors"""
for category in lists:
try:
r = urlopen("http://api.nytimes.com/svc/books/v3/lists/" +
category + ".json?api-key=" + times_keys["books"])
rInfo = r.info()
rRaw = r.read().decode(rInfo.get_content_charset('utf8'))
result = json.loads(rRaw)
except Exception as e:
print(category + " has given us an error")
break
# Make a dictionary of the list categories
book_lists = {}
# Make a list of book objects
list_of_book_objects = []
try:
books = result["results"]["books"]
except Exception as e:
print("*" * 80)
print(result)
print(category)
print("*" * 80)
books = []
for book in books:
# Empty list
del list_of_book_objects[:]
# Book title
book_title = book["title"]
# Best Seller List Name
book_best_seller_list = result["results"]["list_name"]
# Best Seller List date
book_best_seller_date = result["results"]["bestsellers_date"]
# ISBN
book_isbn = book["primary_isbn13"]
# Publisher
book_publisher = book["publisher"]
# Summary
book_summary = book["description"]
# Image
book_book_image = book["book_image"]
# Amazon link
book_amazon_link = book["amazon_product_url"]
# Author object
a = book["author"]
single_author = a.split(' and ')[0]
if len(single_author.split(' ')) >= 2:
lastName = single_author.split(' ')[-1]
else:
lastName = "None"
firstName = single_author.split(' ')[0]
with app.app_context():
author = Author.query.filter_by(
first_name=firstName).filter_by(last_name=lastName).all()
if len(author) > 0:
book_author = author[0]
else:
book_author = Author(
first_name=firstName, last_name=lastName,
book_count=0, bio="not found", link=None)
with app.app_context():
DB.session.add(book_author)
DB.session.commit()
with app.app_context():
q_book = Book.query.filter_by(isbn=book_isbn).all()
if len(q_book) > 0:
b = q_book[0]
b.best_seller_list = b.best_seller_list + \
", " + book_best_seller_list
else:
b = Book(isbn=book_isbn,
title=book_title,
summary=book_summary,
best_seller_date=book_best_seller_date,
best_seller_list=book_best_seller_list,
book_image=book_book_image,
amazon_link=book_amazon_link,
publisher=book_publisher)
b.author = book_author
with app.app_context():
try:
DB.session.add(b)
DB.session.commit()
except Exception:
print("Handling weird book summary")
DB.session.rollback()
DB.session.delete(book_author)
DB.session.commit()
#.........这里部分代码省略.........
示例13: post
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import author [as 别名]
def post(self):
book = Book();
book.title = self.request.get('title')
book.author = self.request.get('author')
book.put()
self.redirect("/list")
示例14: sell
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import author [as 别名]
def sell():
'''
This function insert a book which the user sold to the database. Also, Checks if the user
has enough creadits to pay to the system for this sale.
'''
form = sellForm()
if (request.method == 'POST') and form.validate_on_submit():
#DETERMINE IF USER HAVE ENOUGH CREDIT TO SELL THE BOOK
#GET USER ID
username = request.form['username']
user = User.query.filter_by(username = str(username)).first()
userid = user.id
#GET USER CREDITS
user_credits = user.get_credit()
#GET USER COMPLAINTS
num_of_complaints = db.session.query(User_Complaints).filter_by(complained_id = userid).count()
#CALCULATE CREDIT AFTER SALE
temp_credit = user.credits - ((int(request.form['saleDuration'])) * 5) - ((int(request.form['saleDuration'])) * num_of_complaints)
#UPDATE USER CREDITS
if (temp_credit < 0):
return render_template('no_credit.html')
user.credits = temp_credit
file = form.data.get('bookImage')
tempBool = 0
b = Book()
filename = ''.join(random.choice(string.ascii_letters+string.digits) for x in range(20))
if (str(request.files['bookImage']) == "<FileStorage: u'' ('application/octet-stream')>"):
print "NO IMAGE"
b.image_name = "noImage.jpg"
else:
#file = form.data.get('bookImage')
file = request.files['bookImage']
file.filename = filename+".jpg"
if file and allowed_file(file.filename):
#UPLOAD FILE
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
b.image_name = filename
#PUSH DATA TO DB
b.title = request.form['title']
b.author = request.form['author']
b.isbn = request.form['isbn']
b.price = float(request.form['price'])
b.saleDuration = int(request.form['saleDuration'])
b.publisher = request.form['publisher']
b.numOfPages = int(request.form['numOfPages'])
b.lang = request.form['lang']
b.condition = request.form['condition']
b.genre = request.form['genre']
b.bookType = request.form['bookType']
b.edition = int(request.form['edition'])
b.information = request.form['information']
#tempBool=0
tempBool = False
if (form.data.get('buyable') == True):
#tempBool = 1;
tempBool = True
else:
#tempBool = 0;
tempBool = False
b.buyable = tempBool
if (tempBool == True):
#if (tempBool == 1):
b.buyout_price = float(request.form['buynowPrice'])
# changing current_bid to price
#b.current_bid=float(0)
b.current_bid = b.price
b.biddable= 1
b.starting_bid=float(request.form['price'])
b.owner_id=int(userid)
db.session.add(b)
db.session.commit()
return render_template('success.html')
return render_template('sell.html', form=form)
示例15: Book
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import author [as 别名]
from models import Book
some_books = [('Nietzsche', 'Asi hablo Zaratustra'),
('Pwaqo', 'Conjunto Vacio')]
for abook in some_books:
book = Book()
book.author, book.title = abook
book.save()