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


Python Book.isbn方法代码示例

本文整理汇总了Python中books.models.Book.isbn方法的典型用法代码示例。如果您正苦于以下问题:Python Book.isbn方法的具体用法?Python Book.isbn怎么用?Python Book.isbn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在books.models.Book的用法示例。


在下文中一共展示了Book.isbn方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: regFromDouban

# 需要导入模块: from books.models import Book [as 别名]
# 或者: from books.models.Book import isbn [as 别名]
def regFromDouban(request):
    '''利用豆瓣API获取书籍信息加入数据库'''
    try:
        DOUBAN = "https://api.douban.com/v2/book/search?q="
        q = request.REQUEST.get('q', '')
        q = urllib.quote(q.decode('utf8').encode('utf8'))  
        DOUBAN += q
    
        req = urllib.urlopen(DOUBAN)
        resp = req.read()
        result = simplejson.loads(resp)
        books = result['books']
        
        
        for i in range(len(books)):
            author = Author()
            author.name = books[i]['author'][0]
            author.desc = books[i]['author_intro']
            author.save()
            
            try:
                book = Book.objects.get(isbn=books[i]['isbn13'])
            except Book.DoesNotExist:
                book = Book()
                book.name = books[i]['title']
                book.author = author
                book.price = float(''.join([ item for item in books[i]['price'] if item in '1234567890.' ]))
                if not books[i]['isbn13']:
                    book.isbn = books[i]['isbn10']
                else:
                    book.isbn = books[i]['isbn13']
                book.press = books[i]['publisher']
                book.desc = books[i]['summary']
                book.binding = books[i]['binding']
                book.pages = books[i]['pages']
                book.spic = _downloadImg(books[i]['images']['small'], 'small')   
                book.mpic = _downloadImg(books[i]['images']['medium'], 'medium')   
                book.lpic = _downloadImg(books[i]['images']['large'], 'large')   
                book.stock = 140
                book.publish_date = books[i]['pubdate']
                book.category = _getBookCate('letter')
                book.save()
                
        return HttpResponse('success')
    except Exception:
        return HttpResponse('error')
开发者ID:kliyes,项目名称:repo.bookstore,代码行数:48,代码来源:views.py

示例2: addBook

# 需要导入模块: from books.models import Book [as 别名]
# 或者: from books.models.Book import isbn [as 别名]
def addBook(request):
    '''新加书籍, post request only'''
    if request.method != "POST":
        raise Http404
    
    authorName = request.REQUEST.get('authorName', None)
    authorDesc = request.REQUEST.get('authorDesc', None)
    bookName = request.REQUEST.get('bookName', None)
    bookPrice = request.REQUEST.get('bookPrice', None)
    bookIsbn = request.REQUEST.get('bookIsbn', None)
    bookPress = request.REQUEST.get('bookPress', None)
    bookDesc = request.REQUEST.get('bookDesc', None)
    bookBinding = request.REQUEST.get('bookBinding', None)
    bookPages = request.REQUEST.get('bookPages', None)
    bookSpic = request.REQUEST.get('bookSpic', None)
    bookMpic = request.REQUEST.get('bookMpic', None)
    bookLpic = request.REQUEST.get('bookLpic', None)
    bookPublishDate = request.REQUEST.get('bookPublishDate', None)
    stock = request.REQUEST.get('stock', None)
    category = request.REQUEST.get('category', None)
    
    author = Author(name=authorName, desc=authorDesc)
    author.save()
    
    price = float(''.join([ item for item in bookPrice if item in '1234567890.' ]))
    try:
        cate = Category.objects.get(label=category)
    except Category.DoesNotExist:
        raise Http404
    try:
        book = Book.objects.get(isbn=bookIsbn)
    except Book.DoesNotExist:
        book = Book()
    book.name=bookName
    book.author=author 
    book.price=price
    book.isbn=bookIsbn
    book.press=bookPress
    book.desc=bookDesc
    book.binding=bookBinding
    book.pages=bookPages
    book.spic=bookSpic
    book.mpic=bookMpic
    book.lpic=bookLpic 
    book.publish_date=bookPublishDate
    book.stock=stock
    book.category=cate
    book.save()
    utils.addMsg(request, messages.SUCCESS, '添加成功!')
    return HttpResponseRedirect('/manage/reg_book/')
开发者ID:kliyes,项目名称:repo.bookstore,代码行数:52,代码来源:views.py

示例3: setup_environ

# 需要导入模块: from books.models import Book [as 别名]
# 或者: from books.models.Book import isbn [as 别名]
import settings_copy as settings
setup_environ(settings)

from books.models import Book

t = int(raw_input('number of books you want to add:'))

import random

TITLE_PREFIX = (u'数学', u'方程', u'化学', u'生物', u'疾病', u'神经', u'电子', u'模拟', u'物理', u'逻辑', u'算法', u'程序', u'数据库', u'网络', u'计算机', u'概率', u'随机')
TITLE_SUFFIX = (u'引论', u'概论', u'方法', u'教程', u'导读', u'分析', u'入门')
AUTHOR_PREFIX = u'赵钱孙李周吴郑王冯陈褚卫蒋沈韩杨朱秦尤许何吕施张孔曹严华金魏陶姜'
AUTHOR_SUFFIX = u'伟芳秀敏杰丹灵华兆婷超梁晗辉军越征凯腾江帆一中君盛丽群来未晨和刚明娜'

def get_rand(s):
    return s[random.randint(0, len(s) - 1)]

for i in range(t):
    b = Book()
    b.isbn = str(int(random.random() * (10 ** 13)))
    t = random.randint(1, 2)
    s = ''.join([get_rand(TITLE_PREFIX) for tt in range(0, t)])
    s += get_rand(TITLE_SUFFIX)
    b.title = s
    b.author = get_rand(AUTHOR_PREFIX) + get_rand(AUTHOR_SUFFIX);
    if random.randint(0, 2) == 1:
        b.author += get_rand(AUTHOR_SUFFIX)
    b.press = get_rand((u"复旦大学出版社", u"机械工业出版社", u"中华书局"))
    b.sale_price = round(random.random() * 100) + 1
    print b
    b.save()
开发者ID:ComboZhc,项目名称:Library,代码行数:33,代码来源:add_books.py


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