本文整理汇总了Python中models.Book.mediaType方法的典型用法代码示例。如果您正苦于以下问题:Python Book.mediaType方法的具体用法?Python Book.mediaType怎么用?Python Book.mediaType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Book
的用法示例。
在下文中一共展示了Book.mediaType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_books
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import mediaType [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: upload_file
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import mediaType [as 别名]
def upload_file(self, filename):
gcs_file = gcs.open(filename)
datareader = csv.reader(gcs_file)
count = 0
entities = []
for row in datareader:
count += 1
#TODO: Pass the enums
if len(row[1]) > 0:
booktitle = row[1].lower()
booksbId = row[0]
#convert 1/4/3101 to 3101-04--01
if booksbId.find('/')>-1:
list = booksbId.split('/')
if len(list)>1:
booksbId = list[2] + '-0'+list[1] +'--0'+list[0]
b_key = ndb.Key(Book, booksbId.upper())
newBook = Book(
key = b_key,
sbId = booksbId,
title = booktitle,
volume = row[2],
author = row[3],
isbn = row[4],
price = row[5],
#language = row[6],
notes = row[8],
#suggestedGrade = row[9],
category = row[10],
publisher = row[15],
editionYear = row[18],
donor = row[20],
comments = row[25]
)
if row[6]:
lang = row[6]
if lang == 'English':
newBook.language = Language.ENGLISH
elif lang == 'Tamil':
newBook.language = Language.TAMIL
elif lang == 'Gujarathi':
newBook.language = Language.GUJARATHI
elif string.find(lang, 'Hindi')>-1:
newBook.language = Language.HINDI
if row[9]:
grade = row[9]
if grade == 'KG':
newBook.suggestedGrade.append(Grade.K)
elif self._isNumber(grade):
newBook.suggestedGrade.append(self._getGrade(int(grade)))
elif grade == 'Adult':
newBook.suggestedGrade.append(Grade.ADULT)
else:
minGrade = 0
if string.find(grade, '-Jan')>-1:
maxGrade = grade[0]
minGrade = 1
elif string.find(grade, '-Feb')>-1:
minGrade = 2
maxGrade = grade[0]
elif string.find(grade, '-Mar')>-1:
minGrade = 3
maxGrade = grade[0]
if minGrade > 0:
for i in range(minGrade, int(maxGrade)+1):
newBook.suggestedGrade.append(self._getGrade(i))
if row[16]:
if row[16] == 'Book':
newBook.mediaType = Media.BOOK
elif row[16] == 'Dictionary':
newBook.mediaType = Media.DICTIONARY
elif string.find(row[16], 'CD')>-1:
newBook.mediaType = Media.CD
entities.append(newBook)
if count%50==0 and entities:
ndb.put_multi(entities)
entities=[]
if entities:
ndb.put_multi(entities)
self.response.set_status(204)