本文整理汇总了Python中olapi.OpenLibrary.write方法的典型用法代码示例。如果您正苦于以下问题:Python OpenLibrary.write方法的具体用法?Python OpenLibrary.write怎么用?Python OpenLibrary.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类olapi.OpenLibrary
的用法示例。
在下文中一共展示了OpenLibrary.write方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: query_iter
# 需要导入模块: from olapi import OpenLibrary [as 别名]
# 或者: from olapi.OpenLibrary import write [as 别名]
q = { 'type': '/type/edition', 'table_of_contents': None, 'subjects': None }
queue = []
count = 0
for e in query_iter(q):
if not e.get('subjects', None) or not any(has_dot(s) for s in e['subjects']):
continue
subjects = [s[:-1] if has_dot(s) else s for s in e['subjects']]
q = {
'key': e['key'],
'subjects': {'connect': 'update_list', 'value': subjects },
}
# need to fix table_of_contents to pass validation
toc = e['table_of_contents']
if toc and (isinstance(toc[0], six.string_types) or toc[0]['type'] == '/type/text'):
if isinstance(toc[0], six.string_types):
assert all(isinstance(i, six.string_types) for i in toc)
new_toc = [{'title': i, 'type': '/type/toc_item'} for i in toc]
else:
assert all(i['type'] == '/type/text' for i in toc)
new_toc = [{'title': i['value'], 'type': '/type/toc_item'} for i in toc]
q['table_of_contents'] = {'connect': 'update_list', 'value': new_toc }
queue.append(q)
count += 1
if len(queue) == 100:
print(count, 'writing to db')
print(ol.write(queue, "remove trailing period from subjects"))
queue = []
print(ol.write(queue, "remove trailing period from subjects"))