本文整理汇总了Python中openlibrary.api.OpenLibrary.get_many方法的典型用法代码示例。如果您正苦于以下问题:Python OpenLibrary.get_many方法的具体用法?Python OpenLibrary.get_many怎么用?Python OpenLibrary.get_many使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openlibrary.api.OpenLibrary
的用法示例。
在下文中一共展示了OpenLibrary.get_many方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: len
# 需要导入模块: from openlibrary.api import OpenLibrary [as 别名]
# 或者: from openlibrary.api.OpenLibrary import get_many [as 别名]
olid = row[1]
key = '/books' + olid[olid.rindex('/'):len(olid)]
olids.append(key)
iddict[key] = row[0]
# If the whole batch has been done already, skip to the next batch
print olids
if len(olids) == 0:
print 'Batch %r already done; skipping.' % batch_count
continue
# Fetch the book data from the site
got_data = False
for attempt in range(5):
try:
data = ol.get_many(olids)
got_data = True
break
except KeyboardInterrupt:
sys.exit(0)
except:
print 'ol.get_many() error'
traceback.print_exc(file=sys.stdout)
if not got_data:
sys.exit('Failed to get data.')
datalist = []
for doc_key in data:
datalist.append(data[doc_key])
# Fix toc errors
datalist = [fix_toc(doc) for doc in datalist]
示例2: has
# 需要导入模块: from openlibrary.api import OpenLibrary [as 别名]
# 或者: from openlibrary.api.OpenLibrary import get_many [as 别名]
#.........这里部分代码省略.........
try:
return self.ol.get(key, v)
except OLError as e:
self.save_error(key, str(e))
print_log("Get failed: "+str(e))
def clean_author_dates(self):
for year in range(1900, 2013):
authors = self.query({"type": "/type/author", "death_date": str(year)+".", "limit": False})
print_log("Getting authors with death date '" + str(year) + "'...")
for author in authors:
obj = self.ol_get(author)
self.clean_author(obj)
sleep(2)
done = codecs.EncodedFile(open("cleanauthors-done.txt", "ab"), "unicode_internal", "utf-8", "replace")
done.write("Death date '" + str(year) + ".' updated to '" + str(year) + "'\n")
done.close()
def clean_author_dates2(self):
for year in range(0,1000):
# Get keys of all authors with death date <x>
authors = self.query({"type": "/type/author", "death_date": str(year)+".", "limit": False})
print_log("Getting authors with death date '" + str(year) + "'...")
list = []
for author in authors:
# Feed authors to buffer list
list.append(author)
if len(list) > 99:
# Process these few authors before continuing feeding
# Get records
print_log("Getting full records")
records = self.ol.get_many(list)
for obj in records.itervalues():
self.clean_author2(obj)
list = []
if len(list) > 0:
records = self.ol.get_many(list)
for obj in records.itervalues():
self.clean_author2(obj)
self.flush_all()
done = codecs.EncodedFile(open("cleanauthors-done.txt", "ab"), "unicode_internal", "utf-8", "replace")
done.write(unicode("Death date '" + str(year) + ".' updated to '" + str(year) + "'\n"))
done.close()
sleep(0.5)
def clean_author(self, obj):
"""Clean author records. For example removes the period after the death date.
Saves the updated record directly, instead of putting it in the save buffer.
"""
# Remove period from death date
comment = []
result1 = self.clean_death_date(obj)
if result1 != None:
comment.append("Removed period from death date")
if len(comment) > 0:
self.ol_save(obj["key"], result1, "; ".join(comment))
def clean_author2(self, obj):
"""Clean author records. For example removes the period after the death date.
Saves the updated record in the save buffer.