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