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


Python Book.isbn方法代码示例

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


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

示例1: insert_data

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import isbn [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))
开发者ID:xtream1101,项目名称:scrape-itebooks,代码行数:37,代码来源:it-ebooks.py

示例2: create_books

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import isbn [as 别名]
def create_books():
    with open("../anapioficeandfire/books.json") as book_file:
        books = json.load(book_file)

    for d in books:
        id = d["url"].split("/").pop()
        name = d["name"]
        isbn = d["isbn"]
        numberOfPages = d["numberOfPages"]
        publisher = d["publisher"]
        country = d["country"]
        mediaType = d["mediaType"]
        released = d["released"].split("T")[0]

        b = Book.query.get(id)
        if not b:
            b = Book(id=id, name=name, isbn=isbn, numberOfPages=numberOfPages,
                     publisher=publisher, country=country, mediaType=mediaType,
                     released=released)
        else:
            b.name = name
            b.isbn = isbn
            b.numberOfPages = numberOfPages
            b.publisher = publisher
            b.country = country
            b.mediaType = mediaType
            b.released = released

        db.session.add(b)
        print(b)
开发者ID:VectorCell,项目名称:gotdata,代码行数:32,代码来源:create_db.py

示例3: post

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import isbn [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)
开发者ID:fanghuang,项目名称:Booksharepoint,代码行数:59,代码来源:action_handlers.py

示例4: test_repository_update_works

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import isbn [as 别名]
def test_repository_update_works():
    r = Repository()
    bk = Book('TITLE', 'DESCRIPTION', 'ISBN')
    r.store(bk)
    bk = r.find_one('ISBN')
    bk.title = 'NEWTITLE'
    bk.isbn = 'NEWISBN'
    r.store(bk)

    maybe_bk = r.find_one('ISBN')
    assert_is_none(maybe_bk)

    maybe_bk = r.find_one('NEWISBN')
    assert_is_not_none(maybe_bk)
    assert_equals(maybe_bk.isbn, 'NEWISBN')
    assert_equals(maybe_bk.title, 'NEWTITLE')
开发者ID:owenphelps,项目名称:library,代码行数:18,代码来源:model_tests.py

示例5: post

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import isbn [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')
开发者ID:codeoloco,项目名称:mebook,代码行数:42,代码来源:mebook.py

示例6: fetchCreateByISBN

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import isbn [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

示例7: edit_book

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import isbn [as 别名]
def edit_book(number):
	amazon_img = False
	if number == 'new':
		book = Book()
		book.mass = 0
		book.width = 0
		book.length = 0
		book.thickness = 0
		title = 'Ajouter un livre dans la bibliotheque'
	elif number[0:7] == 'amazon:':
		import urllib
		asin=unicode(number[7:])
		amazon = bottlenose.Amazon(AWS_KEY,AMAZON_SECRET_KEY,LANG)
		#
		# we fetch the primary informations from large group amazon search
		#
		fetch = amazon.ItemLookup(IdType='ASIN', ItemId= asin, ResponseGroup='Large')
		xml = objectify.fromstring(fetch)
		book = Book()
		try:
			book.title = unicode(xml.Items.Item.ItemAttributes.Title)
		except AttributeError:
			book.title = ''
		try:
			amazon_img = unicode(xml.Items.Item.LargeImage.URL)
		except AttributeError:
			amazon_img = ''
		try:
			book.isbn = unicode(xml.Items.Item.ItemAttributes.ISBN)
		except AttributeError:
			book.isbn = ''
		try:
			book.ean = unicode(xml.Items.Item.ItemAttributes.EAN)
		except AttributeError:
			book.ean = ''
		try:
			book.publisher = unicode(xml.Items.Item.ItemAttributes.Publisher)
		except AttributeError:
			book.publisher = ''
		
		#
		# amazon works in US units (hundreds-inches and pounds). I want them in kilos and cm, so I import the data in float and translate.
		#
		try:
			thickness = float(xml.Items.Item.ItemAttributes.PackageDimensions.Height)
			book.thickness = round(thickness * 2.54/100, 1)
		except AttributeError:
			book.thickness = ''
		try:
			length = float(xml.Items.Item.ItemAttributes.PackageDimensions.Length)
			book.length = round(length * 2.54/100, 1)
		except AttributeError:
			book.length = ''
		try:
			width = float(xml.Items.Item.ItemAttributes.PackageDimensions.Width)
			book.width = round(width * 2.54/100, 1)
		except AttributeError:
			book.width = ''
		try:
			mass = float(xml.Items.Item.ItemAttributes.PackageDimensions.Weight)
			book.mass = round(mass * 0.45/100,2)
		except AttributeError:
			book.mass = ''
		try:
			book.numberofpages = int(xml.Items.Item.ItemAttributes.NumberOfPages)
		except AttributeError:
			book.numberofpages = ''
		try:
			book.summary = unicode(xml.Items.Item.EditorialReviews.EditorialReview.Content)
		except AttributeError:
			book.summary = ''
		title = 'Ajouter un livre d\'Amazon dans la bibliotheque'

	else:
		book = Book.query.get(number)
		title = book.title
		if os.path.exists('app/static/covers/' + str(book.id)):
			book.img = True
	form = BookForm()
	form.authortoadd.choices = Author.query.filter(Author!=book.authors)
	update = False
	#if form.validate_on_submit():
	if request.form=='POST' and form.validate():
		#print form.errors
		book.title = unicode(form.title.data)
		# on ajoute les élements en dessous, mais s'ils ne sont pas là, c'est pas grave !
		if form.ean.data != book.ean:
			book.ean = unicode(form.ean.data)
			update = True
		if form.isbn.data != book.isbn:
			book.isbn = unicode(form.isbn.data)
			update = True
		if form.thickness.data != book.thickness:
			book.thickness = unicode(form.thickness.data)
			update = True
		if form.width.data != book.width:
			book.width = unicode(form.width.data)
			update = True
		if form.length.data != book.length:
			book.length = form.length.data
#.........这里部分代码省略.........
开发者ID:22decembre,项目名称:biblib,代码行数:103,代码来源:views.py

示例8: sell

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import isbn [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)
开发者ID:imclab,项目名称:BookBay,代码行数:81,代码来源:views.py


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