Exemplo n.º 1
0
def try_amazon(key):
    thing = withKey(key)
    if 'isbn_10' not in thing:
        return None
    if 'authors' in thing:
        authors = []
        for a in thing['authors']:
            author_thing = withKey(a['key'])
            if 'name' in author_thing:
                authors.append(author_thing['name'])
    else:
        authors = []
    return amazon.build_amazon(thing, authors)
Exemplo n.º 2
0
def try_amazon(key):
    thing = withKey(key)
    if 'isbn_10' not in thing:
        return None
    if 'authors' in thing:
        authors = []
        for a in thing['authors']:
            author_thing = withKey(a['key'])
            if 'name' in author_thing:
                authors.append(author_thing['name'])
    else:
        authors = []
    return amazon.build_amazon(thing, authors)
Exemplo n.º 3
0
    def GET(self):
        web.header('Content-Type','text/html; charset=utf-8', unique=True)
        input = web.input()
        title = 'Tidy author'
        if 'author' in input and input.author:
            author = input.author
            name = withKey(author)['name']
            q_name = web.htmlquote(name)
            title = q_name + ' - Tidy author'
        else:
            author = None
        ret = "<html>\n<head>\n<title>%s</title>" % title

        ret += '''
<style>
th { text-align: left }
td { padding: 5px; background: #eee }
</style>'''

        ret += '</head><body><a name="top">'
        ret += '<form name="main" method="get"><table><tr><td align="right">Author</td><td>'
        if author:
            ret += '<input type="text" name="author" value="%s">' % web.htmlquote(author)
        else:
            ret += '<input type="text" name="author">'
        ret += '</td>'
        ret += '<td><input type="submit" value="find"></td></tr>'
        ret += '</table>'
        ret += '</form>'
        if author:
            ret += 'Author: <a href="http://openlibrary.org%s">%s</a><br>' % (author, name)
            ret += search(author, name)
        ret += "</body></html>"
        return ret
Exemplo n.º 4
0
    def GET(self):
        web.header('Content-Type','text/html; charset=utf-8', unique=True)
        input = web.input()
        title = 'Tidy author'
        if 'author' in input and input.author:
            author = input.author
            name = withKey(author)['name']
            q_name = web.htmlquote(name)
            title = q_name + ' - Tidy author'
        else:
            author = None
        ret = "<html>\n<head>\n<title>%s</title>" % title

        ret += '''
<style>
th { text-align: left }
td { padding: 5px; background: #eee }
</style>'''

        ret += '</head><body><a name="top">'
        ret += '<form name="main" method="get"><table><tr><td align="right">Author</td><td>'
        if author:
            ret += '<input type="text" name="author" value="%s">' % web.htmlquote(author)
        else:
            ret += '<input type="text" name="author">'
        ret += '</td>'
        ret += '<td><input type="submit" value="find"></td></tr>'
        ret += '</table>'
        ret += '</form>'
        if author: 
            ret += 'Author: <a href="http://openlibrary.org%s">%s</a><br>' % (author, name)
            ret += search(author, name)
        ret += "</body></html>"
        return ret
Exemplo n.º 5
0
def other_editions(title, wkey, work_author):
    # look for other editions with the same title
    wakey = work_author['key']
    q = {'type': '/type/edition', 'title': title}
    for k in 'works', 'title_prefix', 'key', 'authors':
        q[k] = None
    found = []
    for e in query_iter(q):
        if not e.get('authors', None):
            continue
        if e.get('works', None) and any(i['key'] == wkey for i in e['works']):
            continue
        if any(i['key'] == wakey for i in e['authors']):
            continue
        for akey in (a['key'] for a in e.get('authors', [])):
            a = withKey(akey)
            name = a.get('name', '')
            if match_name(name, work_author['name'], last_name_only_ok=True):
                yield (e, a)
Exemplo n.º 6
0
def other_editions(title, wkey, work_author):
    # look for other editions with the same title
    wakey = work_author['key']
    q = { 'type': '/type/edition', 'title': title }
    for k in 'works', 'title_prefix', 'key', 'authors':
        q[k] = None
    found = []
    for e in query_iter(q):
        if not e.get('authors', None):
            continue
        if e.get('works', None) and any(i['key'] == wkey for i in e['works']):
            continue
        if any(i['key'] == wakey for i in e['authors']):
            continue
        for akey in (a['key'] for a in e.get('authors', [])):
            a = withKey(akey)
            name = a.get('name', '')
            if match_name(name, work_author['name'], last_name_only_ok=True):
                yield (e, a)
Exemplo n.º 7
0
                yield (e, a)


q = {'type': '/type/work'}
for k in 'key', 'title', 'authors':
    q[k] = None

for w in query_iter(q):
    wkey = w['key']
    titles = set([w['title']])
    q = {'type': '/type/edition', 'works': wkey}
    for k in 'title', 'title_prefix', 'key', 'authors':
        q[k] = None

    wakey = w['authors'][0]['key']
    work_author = withKey(wakey)

    for e in query_iter(q):
        if not e.get('title', None):
            continue
        titles.update([get_title(e), e['title']])

    found = []
    for title in titles:
        found += list(other_editions(title, wkey, work_author))

    if not found:
        continue
    print w
    print titles
    print wakey + ':', fmt_author(work_author)
Exemplo n.º 8
0
    if not edition_pool:
        load(loc, ia)
        continue

    e1 = build_marc(rec)

    match = False
    seen = set()
    for k, v in edition_pool.iteritems():
        for edition_key in v:
            if edition_key in seen:
                continue
            thing = None
            while not thing or thing['type']['key'] == '/type/redirect':
                seen.add(edition_key)
                thing = withKey(edition_key)
                assert thing
                if thing['type']['key'] == '/type/redirect':
                    print 'following redirect %s => %s' % (edition_key, thing['location'])
                    edition_key = thing['location']
            if try_merge(e1, edition_key, thing):
                add_source_records(edition_key, ia)
                match = True
                break
        if match:
            break

    if not match:
        load(loc, ia)

print "finished"
Exemplo n.º 9
0
            if match_name(name, work_author['name'], last_name_only_ok=True):
                yield (e, a)

q = { 'type':'/type/work' }
for k in 'key', 'title', 'authors':
    q[k] = None

for w in query_iter(q):
    wkey = w['key']
    titles = set([w['title']])
    q = { 'type': '/type/edition', 'works': wkey }
    for k in 'title', 'title_prefix', 'key', 'authors':
        q[k] = None

    wakey = w['authors'][0]['key']
    work_author = withKey(wakey)

    for e in query_iter(q):
        if not e.get('title', None): 
            continue
        titles.update([get_title(e), e['title']])

    found = []
    for title in titles:
        found += list(other_editions(title, wkey, work_author))

    if not found:
        continue
    print w
    print titles
    print wakey + ':', fmt_author(work_author)