本文整理汇总了Python中openlibrary.api.OpenLibrary.login方法的典型用法代码示例。如果您正苦于以下问题:Python OpenLibrary.login方法的具体用法?Python OpenLibrary.login怎么用?Python OpenLibrary.login使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openlibrary.api.OpenLibrary
的用法示例。
在下文中一共展示了OpenLibrary.login方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from openlibrary.api import OpenLibrary [as 别名]
# 或者: from openlibrary.api.OpenLibrary import login [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: add_cover_to_work
# 需要导入模块: from openlibrary.api import OpenLibrary [as 别名]
# 或者: from openlibrary.api.OpenLibrary import login [as 别名]
def add_cover_to_work(w):
if 'cover_edition' in w:
return
q = {'type':'/type/edition', 'works':w['key'], 'publish_date': None, 'languages': '/l/eng'}
cover_edition = pick_cover(query_iter(q))
if not cover_edition:
q = {'type':'/type/edition', 'works':w['key'], 'publish_date': None}
cover_edition = pick_cover(query_iter(q))
if not cover_edition:
return
w['cover_edition'] = Reference(cover_edition)
if ol is None:
rc = read_rc()
ol = OpenLibrary("http://openlibrary.org")
ol.login('WorkBot', rc['WorkBot'])
print ol.save(w['key'], w, 'added cover to work')
示例3: read_rc
# 需要导入模块: from openlibrary.api import OpenLibrary [as 别名]
# 或者: from openlibrary.api.OpenLibrary import login [as 别名]
from openlibrary.api import OpenLibrary
from catalog.read_rc import read_rc
import six
rc = read_rc()
marc_index = web.database(dbn='postgres', db='marc_index')
marc_index.printing = False
db_amazon = web.database(dbn='postgres', db='amazon')
db_amazon.printing = False
ol = OpenLibrary("http://openlibrary.org")
ol.login('ImportBot', rc['ImportBot'])
sys.stdout = codecs.getwriter('utf-8')(sys.stdout)
t0 = time()
t_prev = time()
rec_no = 0
chunk = 50
load_count = 0
archive_id = sys.argv[1]
def percent(a, b):
return float(a * 100.0) / b
def progress(archive_id, rec_no, start_pos, pos):
示例4: OpenLibrary
# 需要导入模块: from openlibrary.api import OpenLibrary [as 别名]
# 或者: from openlibrary.api.OpenLibrary import login [as 别名]
help="The openlibrary API host")
op.add_option("-k", "--nyt-api-key", dest="nyt_api_key",
help="API key for use with the nyt bestsellers api")
op.add_option("-u", "--bot-username", dest="username",
default="nyt_bestsellers_bot",
help="The bot username for accessing the Open Library API")
op.add_option("-p", "--bot-password", dest="password",
help="The bot password for accessing the Open Library API")
options, _ = op.parse_args()
global NYT_API_KEY
NYT_API_KEY = options.nyt_api_key
global OL
OL = OpenLibrary("http://%s" % options.openlibrary_host)
OL.login(options.username, options.password)
results = collections.defaultdict(list)
for ln in get_nyt_bestseller_list_names():
LOG("INFO", "processing list %s" % ln)
for i, book in enumerate(load_nyt_bestseller_list(ln)):
ol_keys = reconcile_book(book)
if not ol_keys:
LOG("WARN", "unable to reconcile '%s' by %s - no OL book found" % (
book['book_details'][0]['title'], book['book_details'][0]['author']
))
if not (key for key in ol_keys if key.startswith("/works/")):
LOG("WARN", "only editions for '%s' by %s: %s" % (
book['book_details'][0]['title'], book['book_details'][0]['author'], ol_keys
))
results[ln].append({
"nyt": book,
示例5: OpenLibrary
# 需要导入模块: from openlibrary.api import OpenLibrary [as 别名]
# 或者: from openlibrary.api.OpenLibrary import login [as 别名]
from __future__ import print_function
import MySQLdb, datetime, re, sys
sys.path.append('/1/src/openlibrary')
from openlibrary.api import OpenLibrary, Reference
from pprint import pprint
import six
conn = MySQLdb.connect(db='merge_editions')
cur = conn.cursor()
re_edition_key = re.compile('^/books/OL(\d+)M$')
re_work_key = re.compile('^/works/OL(\d+)W$')
ol = OpenLibrary('http://openlibrary.org/')
ol.login('EdwardBot', 'As1Wae9b')
re_iso_date = re.compile('^(\d{4})-\d\d-\d\d$')
re_end_year = re.compile('(\d{4})$')
def get_publish_year(d):
if not d:
return
m = re_iso_date.match(d)
if m:
return int(m.group(1))
m = re_end_year.match(d)
if m:
return int(m.group(1))
{'lc_classifications': ['PZ7.H558 Ru'], 'dewey_number': ['[E]']}
示例6: read_rc
# 需要导入模块: from openlibrary.api import OpenLibrary [as 别名]
# 或者: from openlibrary.api.OpenLibrary import login [as 别名]
from openlibrary.catalog.utils.query import query_iter, set_staging, query
from openlibrary.catalog.utils import mk_norm
from openlibrary.catalog.read_rc import read_rc
from collections import defaultdict
from pprint import pprint, pformat
from openlibrary.catalog.utils.edit import fix_edition
from openlibrary.catalog.importer.db_read import get_mc
import urllib2
from openlibrary.api import OpenLibrary, Reference
from lxml import etree
from time import sleep, time
rc = read_rc()
ol = OpenLibrary("http://openlibrary.org")
ol.login('WorkBot', rc['WorkBot'])
fh_log = open('/1/edward/logs/WorkBot', 'a')
def write_log(cat, key, title):
print >> fh_log, (("%.2f" % time()), cat, key, title)
sys.stdout = codecs.getwriter('utf-8')(sys.stdout)
re_skip = re.compile('\b([A-Z]|Co|Dr|Jr|Capt|Mr|Mrs|Ms|Prof|Rev|Revd|Hon|etc)\.$')
re_ia_marc = re.compile('^(?:.*/)?([^/]+)_(marc\.xml|meta\.mrc)(:0:\d+)?$')
ns = '{http://www.loc.gov/MARC21/slim}'
ns_leader = ns + 'leader'
ns_data = ns + 'datafield'
def has_dot(s):
示例7: OpenLibrary
# 需要导入模块: from openlibrary.api import OpenLibrary [as 别名]
# 或者: from openlibrary.api.OpenLibrary import login [as 别名]
import argparse
parser = argparse.ArgumentParser(description='scribe loader')
parser.add_argument('--skip_hide_books', action='store_true')
parser.add_argument('--item_id')
parser.add_argument('--config', default='openlibrary.yml')
args = parser.parse_args()
config_file = args.config
config.load(config_file)
import_bot_password = config.runtime_config['load_scribe']['import_bot_password']
# '/1/var/log/openlibrary/load_scribe'
load_scribe_log = config.runtime_config['load_scribe']['log']
ol = OpenLibrary("http://openlibrary.org")
ol.login('ImportBot', import_bot_password)
password = Popen(["/opt/.petabox/dbserver"], stdout=PIPE).communicate()[0]
db = web.database(dbn='mysql', host='dbmeta.us.archive.org', user='archive', \
passwd=password, db='archive')
db.printing = False
re_census = re.compile('^\d+(st|nd|rd|th)census')
re_edition_key = re.compile('^/(?:books|b)/(OL\d+M)$')
def read_short_title(title):
return str(fast_parse.normalize_str(title)[:25])
def make_index_fields(rec):
fields = {}
示例8: read_rc
# 需要导入模块: from openlibrary.api import OpenLibrary [as 别名]
# 或者: from openlibrary.api.OpenLibrary import login [as 别名]
from openlibrary.catalog.marc import fast_parse, is_display_marc
from openlibrary.catalog.marc.parse import read_edition, NoTitle
from openlibrary.catalog.marc.marc_subject import subjects_for_work
from time import time, sleep
from openlibrary.api import OpenLibrary, unmarshal
from pprint import pprint
import argparse
parser = argparse.ArgumentParser(description="scribe loader")
parser.add_argument("--skip_hide_books", action="store_true")
parser.add_argument("--item_id")
args = parser.parse_args()
rc = read_rc()
ol = OpenLibrary("http://openlibrary.org")
ol.login("ImportBot", rc["ImportBot"])
db_amazon = web.database(dbn="postgres", db="amazon")
db_amazon.printing = False
db = web.database(dbn="mysql", host=rc["ia_db_host"], user=rc["ia_db_user"], passwd=rc["ia_db_pass"], db="archive")
db.printing = False
re_census = re.compile("^\d+(st|nd|rd|th)census")
re_edition_key = re.compile("^/(?:books|b)/(OL\d+M)$")
def read_short_title(title):
return str(fast_parse.normalize_str(title)[:25])
示例9: set_staging
# 需要导入模块: from openlibrary.api import OpenLibrary [as 别名]
# 或者: from openlibrary.api.OpenLibrary import login [as 别名]
from __future__ import print_function
import sys
import codecs
from openlibrary.catalog.utils.query import query_iter, set_staging, query
from openlibrary.api import OpenLibrary, Reference
from openlibrary.catalog.read_rc import read_rc
from time import sleep
set_staging(True)
rc = read_rc()
ol = OpenLibrary("http://dev.openlibrary.org")
ol.login('EdwardBot', rc['EdwardBot'])
sys.stdout = codecs.getwriter('utf-8')(sys.stdout)
work_q = {
'type': '/type/work',
'authors': None,
'title': None,
}
queue = []
for w in query_iter(work_q):
if not w.get('authors'):
print('no authors')
continue
if any(isinstance(a, dict) and 'author' in a for a in w['authors']):
continue
print(len(queue), w['key'], w['title']) # , ol.get(w['authors'][0]['key'])['name']
full = ol.get(w['key'])
示例10: has
# 需要导入模块: from openlibrary.api import OpenLibrary [as 别名]
# 或者: from openlibrary.api.OpenLibrary import login [as 别名]
class VacuumBot:
"""VacuumBot can help clean up Open Library, just tell it what to do!
The VacuumBot has (its) methods to do specific cleanup tasks.
It needs the credentials of a bot account on Open Library and some instructions.
Naturally, it shows no mercy.
"""
def __init__(self, username, password):
"""Takes a username and password of a bot account to establish a connection to OL.
"""
self.ol = OpenLibrary()
self.ol.login(username, password)
self.pagreg = re.compile(r"[^\s]\s+[:;]$")
self.emptypagreg = re.compile(r"[,.:;]+$")
self.formatdict = simplejson.load(codecs.open("formatdict.json", "rb", "utf-8"))
self.enc2 = codecs.getencoder("ascii")
self.savebuffer = {}
self.badrecords = []
self.aucache = {}
self.wocache = {}
#self.formatcache = NKCache("ol_books_formats", api_key = "cfdeaeda-4a22-4ae7-a2bf-1634da98fa1b")
self.logfile = codecs.EncodedFile(open("vacuumbot-log.tsv", "ab"), "unicode_internal", "utf-8", "replace")
def enc(self, str):
return self.enc2(str, "backslashreplace")[0]
def flog(self, key, operation, message):
"""Log to file 'vacuumbot-log.tsv'. Lines are time, key, operation and message, tab-separated.
"""
self.logfile.write(unicode(strftime("%Y-%m-%d_%H:%M:%S", localtime()) + "\t" + key + "\t" + operation + "\t" + message + "\n"))
def save_error(self, key, message):
errorfile = codecs.EncodedFile(open("vacuumbot-errors.txt", "ab"), "unicode_internal", "utf-8", "replace")
errorfile.write(unicode("[" + strftime("%Y-%m-%d_%H:%M:%S", localtime()) + "] Could not save record for: " + key + ", error was: " + message + "\n"))
errorfile.close()
def query(self, query):
return self.ol.query(query)
def ol_save(self, key, record, message):
try:
self.ol.save(key, record, self.enc(message))
self.flog(key, "direct save", message)
print_log("Saved "+key+": "+message)
except OLError as e:
self.save_error(key, str(e))
print_log("Save failed: "+str(e))
def ol_save2(self, key, record, message):
if message != None:
record = marshal(record)
if message in self.savebuffer.keys():
self.savebuffer[message][key] = record
if len(self.savebuffer[message]) >= 100:
self.flush(message)
else:
self.savebuffer[message] = {}
self.savebuffer[message][key] = record
self.flog(key, "buffer save", message)
else:
raise Exception("Message for saving is missing!")
def flush(self, buffer_name):
try:
if len(self.savebuffer[buffer_name]) > 0:
self.ol.save_many(self.savebuffer[buffer_name].values(), self.enc(buffer_name))
for key in self.savebuffer[buffer_name].keys():
self.flog(key, "buffer flush", buffer_name)
print_log("Flushed buffer ("+str(len(self.savebuffer[buffer_name]))+" records): "+buffer_name)
self.savebuffer[buffer_name] = {}
sleep(1)
except OLError as e:
# Try to remove rejected record from buffer
err_mess = simplejson.loads(re.sub(r'^[^{]*', "", str(e)))
if err_mess["error"] == "bad_data":
k = err_mess["at"]["key"]
del self.savebuffer[buffer_name][k]
self.save_error(k, "Multisave failed: "+str(e)+"; removed record from buffer")
else:
k = self.savebuffer[buffer_name].keys()[0]
self.save_error(k, "Multisave failed: "+str(e))
def flush_all(self):
for m in self.savebuffer.keys():
self.flush(m)
def ol_get(self, key, v=None):
"""Gets a record from OL and catches OLErrors.
Make sure you check for None when you process this function's result.
"""
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):
#.........这里部分代码省略.........