当前位置: 首页>>代码示例>>Python>>正文


Python Book.image方法代码示例

本文整理汇总了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
开发者ID:azizmb,项目名称:whatrur,代码行数:35,代码来源:update_books.py

示例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
开发者ID:laimis,项目名称:trackmybooks,代码行数:24,代码来源:readerbook.py


注:本文中的models.Book.image方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。