本文整理汇总了Python中olapi.OpenLibrary.get方法的典型用法代码示例。如果您正苦于以下问题:Python OpenLibrary.get方法的具体用法?Python OpenLibrary.get怎么用?Python OpenLibrary.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类olapi.OpenLibrary
的用法示例。
在下文中一共展示了OpenLibrary.get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: open
# 需要导入模块: from olapi import OpenLibrary [as 别名]
# 或者: from olapi.OpenLibrary import get [as 别名]
test_dir = '/home/edward/ol/test_data'
re_edition = re.compile('^/b/OL\d+M$')
re_meta_mrc = re.compile('^([^/]*)_meta.mrc:0:\d+$')
#out = open('source_records', 'w')
for f in os.listdir(test_dir):
key = f.replace('_', '/')
if not re_edition.match(key):
continue
print key
continue
mc = get_mc(key)
print key, mc
if not mc:
continue
e = ol.get(key)
if e.get('source_records', []):
continue
if mc.startswith('ia:') or mc.startswith('amazon:'):
sr = mc
else:
m = re_meta_mrc.match(mc)
sr = 'marc:' + mc if not m else 'ia:' + m.group(1)
e['source_records'] = [sr]
print >> out, (key, sr)
print ol.save(key, e, 'add source record')
#out.close()
示例2: get_with_retry
# 需要导入模块: from olapi import OpenLibrary [as 别名]
# 或者: from olapi.OpenLibrary import get [as 别名]
rec_no = 0
chunk = 50
load_count = 0
archive_id = sys.argv[1]
def get_with_retry(key):
for i in range(3):
try:
return ol.get(key)
except urllib2.HTTPError, error:
if error.code != 500:
raise
print 'retry save'
sleep(10)
return ol.get(key)
def save_with_retry(key, data, comment):
for i in range(3):
try:
return ol.save(key, data, comment)
except urllib2.HTTPError, error:
if error.code != 500:
raise
print 'retry save'
sleep(10)
# urllib2.HTTPError: HTTP Error 500: Internal Server Error
def percent(a, b):
return float(a * 100.0) / b