当前位置: 首页>>代码示例>>Python>>正文


Python OpenLibrary.login方法代码示例

本文整理汇总了Python中olapi.OpenLibrary.login方法的典型用法代码示例。如果您正苦于以下问题:Python OpenLibrary.login方法的具体用法?Python OpenLibrary.login怎么用?Python OpenLibrary.login使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在olapi.OpenLibrary的用法示例。


在下文中一共展示了OpenLibrary.login方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: read_rc

# 需要导入模块: from olapi import OpenLibrary [as 别名]
# 或者: from olapi.OpenLibrary import login [as 别名]
from catalog.utils.query import query_iter, set_staging, withKey, get_mc
import sys, codecs, re
sys.path.append('/home/edward/src/olapi')
from olapi import OpenLibrary, Reference
from catalog.read_rc import read_rc
from catalog.get_ia import get_from_archive, get_from_local
from catalog.marc.fast_parse import get_first_tag, get_all_subfields
rc = read_rc()

sys.stdout = codecs.getwriter('utf-8')(sys.stdout)
set_staging(True)

ol = OpenLibrary("http://dev.openlibrary.org")
ol.login('EdwardBot', rc['EdwardBot'])

q = { 'type': '/type/edition', 'table_of_contents': None, 'subjects': None }
queue = []
count = 0
for e in query_iter(q, limit=100):
    key = e['key']
    mc = get_mc(key)
    if not mc:
        continue
    data = get_from_local(mc)
    line = get_first_tag(data, set(['041']))
    if not line:
        continue
    print key, line[0:2], list(get_all_subfields(line))

开发者ID:RaceList,项目名称:openlibrary,代码行数:30,代码来源:add_language.py

示例2: Shutt

# 需要导入模块: from olapi import OpenLibrary [as 别名]
# 或者: from olapi.OpenLibrary import login [as 别名]
#!/usr/bin/env python
# NondescriptBot
# by John Shutt (http://shutt.in)

import sys
from olapi import OpenLibrary
# secrets.py holds the login info, and is excluded from version control
from secrets import login_name, password

ol = OpenLibrary()

# Log in.
logged_in = False
print 'Trying to log in...'
for attempt in range(5):
    try:
        ol.login(login_name, password)
        logged_in = True
        print 'Login successful.'
        break
    except:
        print 'ol.login() error; retrying'
if not logged_in:
    sys.exit('Failed to log in.')
开发者ID:pemulis,项目名称:nondescript-bot,代码行数:26,代码来源:ndbot.py

示例3: OpenLibrary

# 需要导入模块: from olapi import OpenLibrary [as 别名]
# 或者: from olapi.OpenLibrary import login [as 别名]
#!/usr/bin/env python

from time import localtime, sleep, strftime
from olapi import OpenLibrary

ol = OpenLibrary()
ol.login("someBot", "somePassword")

def print_log(msg):
  timestamp = strftime("%Y%m%d_%H:%M:%S", localtime())
  print("[" + timestamp + "] " + msg)

def set_identifier(book, id_name, id_value):
  ids = book.setdefault("identifiers", {})
  ids[id_name] = [id_value]

def set_goodreads_id(olid, goodreads_id):
  book = ol.get(olid)
  set_identifier(book, "goodreads", goodreads_id)
  ol.save(book['key'], book, "Added goodreads ID.")

def map_id(olid, isbn, goodreads_id):
  book = ol.get(olid)
  if book.has_key('identifiers'):
    if book['identifiers'].has_key('goodreads'):
      if goodreads_id in book['identifiers']['goodreads']:
        return
  print_log("Adding Goodreads ID \"" + goodreads_id + "\" to Openlibrary ID \"" + olid + "\"")
  set_goodreads_id(olid, goodreads_id)

def load(filename):
开发者ID:artmedlar,项目名称:openlibrary,代码行数:33,代码来源:import_goodreads_ids.py

示例4: read_rc

# 需要导入模块: from olapi import OpenLibrary [as 别名]
# 或者: from olapi.OpenLibrary import login [as 别名]
from catalog.utils.query import query_iter, set_staging, withKey
import sys, codecs, re

sys.path.append("/home/edward/src/olapi")
from olapi import OpenLibrary, Reference
from catalog.read_rc import read_rc

rc = read_rc()

sys.stdout = codecs.getwriter("utf-8")(sys.stdout)
set_staging(True)

ol = OpenLibrary("http://dev.openlibrary.org")
ol.login("EdwardBot", rc["EdwardBot"])

re_skip = re.compile("\b([A-Z]|Co|Dr|Jr|Capt|Mr|Mrs|Ms|Prof|Rev|Revd|Hon)\.$")


def has_dot(s):
    return s.endswith(".") and not re_skip.search(s)


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}}
    if e.get("table_of_contents", None) and e["table_of_contents"][0]["type"] == "/type/text":
开发者ID:sribanta,项目名称:openlibrary,代码行数:33,代码来源:remove_subject_period.py

示例5: __init__

# 需要导入模块: from olapi import OpenLibrary [as 别名]
# 或者: from olapi.OpenLibrary import login [as 别名]
class VacuumBot:
  """VacuumBot can help clean up Open Library, just tell him what to do!
  
  The VacuumBot essentially has methods to do specific cleanup tasks.
  It needs the credentials of a bot account on Open Library and some instructions.
  """
  
  def __init__(self, username, password):
    self.ol = OpenLibrary()
    self.ol.login(username, password)
  
  def remove_classification_value(self, obj, type, value):
    """Removes a value from the list of <type> classifications.
    
    For example, can be used to remove the "B" value from 
    Dewey Decimal classifications.
    If the classifications list is empty afterwards, it is removed.
    If the classifications object in the record is empty (because
    removing the deleted list was the only one in it), it is removed 
    as well.
    """
    special = ["lc_classifications", "dewey_decimal_class"]
    if type in special and type in obj.keys():
      while value in obj[type]:
        obj[type].remove(value)
      if len(obj[type]) == 0:
        del obj[type]
    elif "classifications" in obj.keys() and type in obj["classifications"].keys():
      while value in obj["classifications"][type]:
        obj["classifications"][type].remove(value)
      if len(obj["classifications"][type]) == 0:
        del obj["classifications"][type]
        if len(obj["classifications"]) == 0:
          del obj["classifications"]
   
  def deduplicate_list(self, li):
    """Sorts a list and removes duplicate values in place."""
    
    a = len(li)
    c = 0
    li.sort()
    while c < a-1:
      if li[c] == li[c+1]:
        li.pop(c+1)
        a = a-1
      else:
        c = c+1
    
  def dedup(self, obj):
    """Removes duplicate values from an object.
    
    Calls deduplicate_list for lists.
    Calls itself on compound objects.
    Does nothing with strings or other types.
    """
    if isinstance(obj, str):
      return
    elif isinstance(obj, dict):
      for k in obj:
        dedup(obj[k])
    elif isinstance(obj, list):
      deduplicate_list(obj) 
    else:
      return

  def remove_key(self, olid, key):
    """Removes a key from a record
    
    Use with caution :)
    """
    object = ol.get(olid)
    if key in object:
      del object[key]
      ol.save(object['key'], object, "Sucked up \"" + key + "\".")
    

  def deduplicate_values(self, olid, key):
    """Removes duplicate values
    
    Reads the values of a key and removes duplicate values,
    leaving 1.
    """
    object = ol.get(olid)
    if key in object:
      dedup(object[key])

  def remove_classification(self, obj, classification):
    if "classifications" in obj:
      if classification in obj["classifications"]:
        del obj["classifications"][classification]

  def clean_lccn_permalink(self, olid):
    """Removes lccn_permalink from classifications
    
    Removes permalink from classifications and adds the LCCN to
    the identifiers, if is isn't there already.
    """
    object = ol.get(olid)
    if "classifications" in object:
      if "lccn_permalink" in object["classifications"]:
#.........这里部分代码省略.........
开发者ID:bencomp,项目名称:openlibrary,代码行数:103,代码来源:vacuumbot.py

示例6: OpenLibrary

# 需要导入模块: from olapi import OpenLibrary [as 别名]
# 或者: from olapi.OpenLibrary import login [as 别名]
#!/usr/bin/env python

from olapi import OpenLibrary

ol = OpenLibrary()
ol.login("VacuumBot", "somePassword")

# Top level classifications don't go in the classifications dict.
tl_classifications = ["lc_classifications","dewey_decimal_class"]

def upgrade_classifications(olid):
  """Changes classification from list of (name,value)-dict
  to dict of lists.
  """
  record = ol.get(olid)
  # Check if the classifications are a list:
  if not isinstance(record["classifications"], list):
    return
  
  # Create a new dict to replace the list:
  c = {}
  
  # Read the dicts from the classifications list:
  for k in record["classifications"]:
    if k["name"] in tl_classifications:
      if k["name"] in record.keys():
        record[k["name"]].append(k["value"])
      else:
        record[k["name"]] = [k["value"]]
    elif k["name"] not in c.keys():
      c["name"] = [k["value"]]
开发者ID:bencomp,项目名称:openlibrary,代码行数:33,代码来源:upgradeclassifications.py

示例7: read_rc

# 需要导入模块: from olapi import OpenLibrary [as 别名]
# 或者: from olapi.OpenLibrary import login [as 别名]
from openlibrary.catalog.read_rc import read_rc
import openlibrary.catalog.merge.amazon as amazon
from openlibrary.catalog.get_ia import *
from openlibrary.catalog.importer.db_read import withKey, get_mc
import openlibrary.catalog.marc.fast_parse as fast_parse
import xml.parsers.expat
import web, sys

sys.path.append("/home/edward/src/olapi")
from olapi import OpenLibrary
from time import sleep

rc = read_rc()

ol = OpenLibrary("http://openlibrary.org")
ol.login("ImportBot", rc["ImportBot"])

ia_db = web.database(dbn="mysql", db="archive", user=rc["ia_db_user"], pw=rc["ia_db_pass"], host=rc["ia_db_host"])
ia_db.printing = False

re_meta_marc = re.compile("([^/]+)_(meta|marc)\.(mrc|xml)")

threshold = 875
amazon.set_isbn_match(225)


def try_amazon(thing):
    if "isbn_10" not in thing:
        return None
    if "authors" in thing:
        authors = []
开发者ID:sribanta,项目名称:openlibrary,代码行数:33,代码来源:merge.py


注:本文中的olapi.OpenLibrary.login方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。