本文整理汇总了Python中models.Book.image方法的典型用法代码示例。如果您正苦于以下问题:Python Book.image方法的具体用法?Python Book.image怎么用?Python Book.image使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Book
的用法示例。
在下文中一共展示了Book.image方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_books
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import image [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: fetchCreateByISBN
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import image [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