本文整理汇总了Python中openlibrary.api.OpenLibrary.autologin方法的典型用法代码示例。如果您正苦于以下问题:Python OpenLibrary.autologin方法的具体用法?Python OpenLibrary.autologin怎么用?Python OpenLibrary.autologin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openlibrary.api.OpenLibrary
的用法示例。
在下文中一共展示了OpenLibrary.autologin方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from openlibrary.api import OpenLibrary [as 别名]
# 或者: from openlibrary.api.OpenLibrary import autologin [as 别名]
def main():
options, args = parse_args()
if options.src.startswith("http://"):
src = OpenLibrary(options.src)
else:
src = Disk(options.src)
if options.dest.startswith("http://"):
dest = OpenLibrary(options.dest)
section = "[%s]" % web.lstrips(options.dest, "http://").strip("/")
if section in read_lines(os.path.expanduser("~/.olrc")):
dest.autologin()
else:
dest.login("admin", "admin123")
else:
dest = Disk(options.dest)
for list_key in options.lists:
copy_list(src, dest, list_key, comment=options.comment)
keys = args
keys = list(expand(src, keys))
copy(src, dest, keys, comment=options.comment, recursive=options.recursive)
示例2: main
# 需要导入模块: from openlibrary.api import OpenLibrary [as 别名]
# 或者: from openlibrary.api.OpenLibrary import autologin [as 别名]
def main(server):
ol = OpenLibrary(server)
ol.autologin()
volumes = ol.query({'type': '/type/volume', 'limit': False, '*': None, 'edition': {'*': None}})
volumes = dict((v['key'], v) for v in volumes)
editions = dict((v['edition']['key'], v['edition']) for v in volumes.values() if v['edition'])
def make_volume(v):
d = {}
v.pop('edition')
v['type'] = {'key': '/type/volume'}
for k in ['type', 'ia_id', 'volume_number']:
if k in v:
d[k] = v[k]
return d
for e in editions.values():
e['volumes'] = []
for v in volumes.values():
if v.get('edition'):
e = editions[v.get('edition')['key']]
e['volumes'].append(make_volume(v))
for e in editions.values():
e['volumes'] = sorted(e['volumes'], key=lambda v: v['volume_number'])
print 'linking volumes to %d editions' % len(editions)
ol.save_many(editions.values(), 'link volumes')
示例3: load
# 需要导入模块: from openlibrary.api import OpenLibrary [as 别名]
# 或者: from openlibrary.api.OpenLibrary import autologin [as 别名]
def load():
"""Loads documents to http://0.0.0.0:8080"""
documents = {}
for f in find("data"):
doc = simplejson.load(open(f))
documents[doc['key']] = doc
keys = topological_sort(documents.keys(),
get_children=lambda key: [k for k in get_references(documents[key]) if not k.startswith("/type/")])
from openlibrary.api import OpenLibrary
ol = OpenLibrary("http://0.0.0.0:8080")
ol.autologin()
print ol.save_many([documents[k] for k in keys], comment="documents copied from openlibrary.org")
示例4: main
# 需要导入模块: from openlibrary.api import OpenLibrary [as 别名]
# 或者: from openlibrary.api.OpenLibrary import autologin [as 别名]
def main():
ol = OpenLibrary()
ol.autologin()
plugin = sys.argv[1]
all_docs = []
for pattern in sys.argv[2:]:
docs = ol.query({"key~": pattern, "*": None}, limit=1000)
all_docs.extend(docs)
for doc in all_docs:
doc['plugin'] = plugin
print ol.save_many(all_docs, comment="Marked as part of %s plugin." % plugin)
示例5: write_to_ol
# 需要导入模块: from openlibrary.api import OpenLibrary [as 别名]
# 或者: from openlibrary.api.OpenLibrary import autologin [as 别名]
def write_to_ol(olkey, oljson):
ol = OpenLibrary("http://openlibrary.org")
# Log in [daniel, sam]
logged_in = False
for attempt in range(5):
try:
ol.autologin()
logged_in = True
break
except:
print 'ol.autologin() error; retrying'
if not logged_in:
sys.exit('Failed to log in.')
ol.save(olkey, oljson, 'Adding Table of Contents')
示例6: main
# 需要导入模块: from openlibrary.api import OpenLibrary [as 别名]
# 或者: from openlibrary.api.OpenLibrary import autologin [as 别名]
def main(server):
ol = OpenLibrary(server)
ol.autologin()
scan_records = ol.query(type='/type/scan_record', limit=False, edition={'*': None})
editions = (r['edition'] for r in scan_records)
# process 1000 editions at a time.
while True:
chunk = take(1000, editions)
if not chunk:
break
print 'linking %d editions' % len(chunk)
for e in chunk:
e['scan_records'] = [{'key': '/scan_record' + e['key']}]
ol.save_many(chunk, 'link scan records')
示例7: get_ol
# 需要导入模块: from openlibrary.api import OpenLibrary [as 别名]
# 或者: from openlibrary.api.OpenLibrary import autologin [as 别名]
def get_ol():
ol = OpenLibrary()
ol.autologin()
return ol
示例8: dict
# 需要导入模块: from openlibrary.api import OpenLibrary [as 别名]
# 或者: from openlibrary.api.OpenLibrary import autologin [as 别名]
if d.get('type') == '/type/text':
return dict(title=d['value'])
else:
return d
toc = doc.get('table_of_contents')
if toc:
if type(toc) == dict:
doc['table_of_contents'] = [f(x) for x in toc]
return doc
# Log in
logged_in = False
for attempt in range(5):
try:
ol.autologin()
logged_in = True
break
except:
print 'ol.autologin() error; retrying'
if not logged_in:
sys.exit('Failed to log in.')
# Go through the csv file in batches until done
batch_count = 0
done = False
while not done:
olids = []
ltids = []
iddict = {}
data = []
示例9: main
# 需要导入模块: from openlibrary.api import OpenLibrary [as 别名]
# 或者: from openlibrary.api.OpenLibrary import autologin [as 别名]
def main(site, date=None):
ol = OpenLibrary(site)
ol.autologin("StatsBot")
today = date or datetime.date.today().isoformat()
print ol._request("/admin/stats/" + today, method='POST', data="").read()