コード例 #1
0
def list_works(this_isbn):
    works = find_others(this_isbn, rc['amazon_other_editions'])
    print('<a name="work">')
    print('<h2>Other editions of the same work</h2>')
    if not works:
        print('no work found')
        return
    print('<table>')
    print(
        '<tr><th>ISBN</th><th>Amazon edition</th><th></th><th>MARC titles</th></tr>'
    )
    for isbn, note in works:
        if note.lower().find('audio') != -1:
            continue
        locs = db_isbn[isbn].split(' ') if isbn in db_isbn else []
        #        titles = [read_full_title(get_first_tag(marc_data(i), set(['245'])), accept_sound = True) for i in locs]
        titles = [(marc_title(marc_data(i)), i) for i in locs]
        num = len(locs)
        #print '<tr><td><a href="/?isbn=%s">%s</a></td><td>%s</td><td>%d</td><td>%s</td></tr>' % (isbn, isbn, note, len(locs), list_to_html(titles))
        print(
            '<tr><td><a href="/?isbn=%s">%s</a></td><td>%s</td><td>%d</td><td>'
            % (isbn, isbn, note, len(locs)))
        print(counts_html(titles))
        print('</td></tr>')
    print('</table>')
コード例 #2
0
def list_works(this_isbn):
    works = find_others(this_isbn, rc['amazon_other_editions'])
    print('<a name="work">')
    print('<h2>Other editions of the same work</h2>')
    if not works:
        print('no work found')
        return
    print('<table>')
    print('<tr><th>ISBN</th><th>Amazon edition</th><th></th><th>MARC titles</th></tr>')
    for isbn, note in works:
        if note.lower().find('audio') != -1:
            continue
        locs = db_isbn[isbn].split(' ') if isbn in db_isbn else []
#        titles = [read_full_title(get_first_tag(marc_data(i), set(['245'])), accept_sound = True) for i in locs]
        titles = [(marc_title(marc_data(i)), i) for i in locs]
        num = len(locs)
        #print '<tr><td><a href="/?isbn=%s">%s</a></td><td>%s</td><td>%d</td><td>%s</td></tr>' % (isbn, isbn, note, len(locs), list_to_html(titles))
        print('<tr><td><a href="/?isbn=%s">%s</a></td><td>%s</td><td>%d</td><td>' % (isbn, isbn, note, len(locs)))
        print(counts_html(titles))
        print('</td></tr>')
    print('</table>')
コード例 #3
0
ファイル: find.py プロジェクト: Arpanray01/Open-Library
def search(title, author):
    q = {'type': '/type/author', 'name': author}
    print(q)
    authors = site.things(q)
    print(authors)
    seen = set()
    pool = set()
    #    for a in authors:
    #        q = { 'type': '/type/edition', 'authors': a, 'title': title }
    #        pool.update(site.things(q))
    found_titles = {}
    found_isbn = {}
    author_keys = ','.join("'%s'" % a for a in authors)

    print(author_keys)
    iter = web.query(
        "select id, key from thing where thing.id in (select thing_id from edition_ref, thing where edition_ref.key_id=11 and edition_ref.value = thing.id and thing.key in ("
        + author_keys + "))")
    key_to_id = {}
    id_to_key = {}
    for row in iter:
        print(row)
        key_to_id[row.key] = row.id
        id_to_key[row.id] = row.key

    iter = web.query(
        "select thing_id, edition_str.value as title from edition_str where key_id=3 and thing_id in (select thing_id from edition_ref, thing where edition_ref.key_id=11 and edition_ref.value = thing.id and thing.key in ("
        + author_keys + "))")
    id_to_title = {}
    title_to_key = {}
    for row in iter:
        print(row)
        t = row.title.lower().strip('.')
        id_to_title[row.thing_id] = row.title
        title_to_key.setdefault(t, []).append(id_to_key[row.thing_id])

    if title.lower() not in title_to_key:
        print('title not found')
        return

    pool = set(title_to_key[title.lower()])

    editions = []
    while pool:
        key = pool.pop()
        print(key)
        seen.add(key)
        e = site.withKey(key)
        translation_of = None
        if e.notes:
            m = re_translation_of.search(e.notes)
            if m:
                translation_of = m.group(1).lower()
                pool.update(k for k in title_to_key[translation_of]
                            if k not in seen)
                found_titles.setdefault(translation_of, []).append(key)
        if e.isbn_10:
            for i in e.isbn_10:
                found_isbn.setdefault(i, []).append(key)
            join_isbn = ', '.join(map(isbn_link, e.isbn_10))
        else:
            join_isbn = ''
        rec = {
            'key':
            key,
            'publish_date':
            e.publish_date,
            'publishers':
            ', '.join(p.encode('utf-8') for p in (e.publishers or [])),
            'isbn':
            join_isbn,
        }
        editions.append(rec)

        if e.work_titles:
            for t in e.work_titles:
                t = t.strip('.')
                pool.update(k for k in title_to_key.get(t.lower(), [])
                            if k not in seen)
                found_titles.setdefault(t, []).append(key)
        if e.other_titles:
            for t in e.other_titles:
                t = t.strip('.')
                pool.update(k for k in title_to_key.get(t.lower(), [])
                            if k not in seen)
                found_titles.setdefault(t, []).append(key)

    print('<table>')
    for e in sorted(
            editions,
            key=lambda e: e['publish_date'] and e['publish_date'][-4:]):
        print('<tr>')
        print('<td>', ol_link(e['key']))
        print('<td>', e['publish_date'], '</td><td>', e['publishers'], '</td>')
        print('<td>', e['isbn'], '</td>')
        print('</tr>')
    print('</table>')

    if found_titles:
        print('<h2>Other titles</h2>')
        print('<ul>')
        for k, v in found_titles.iteritems():
            if k == title:
                continue
            print('<li><a href="/?title=%s&author=%s">%s</a>' % (k, author, k),
                  end=' ')
            print('from', ', '.join(ol_link(i) for i in v))
        print('</ul>')

    extra_isbn = {}
    for k, v in found_isbn.iteritems():
        for isbn, note in find_others(k, rc['amazon_other_editions']):
            if note.lower().find('audio') != -1:
                continue
            if isbn not in found_isbn:
                extra_isbn.setdefault(isbn, []).extend(v)

    if extra_isbn:
        print('<h2>Other ISBN</h2>')
        print('<ul>')
        for k in sorted(extra_isbn):
            print('<li>', isbn_link(k), end=' ')
            print('from', ', '.join(ol_link(i) for i in extra_isbn[k]))
        print('</ul>')
コード例 #4
0
ファイル: web_ui.py プロジェクト: RaceList/openlibrary
def search(title, author):

    title_to_key = get_title_to_key(author)
    norm_title = normalize(title).strip('.')

    if norm_title not in title_to_key:
        print 'title not found'
        return

    pool = set(title_to_key[norm_title])

    editions = []
    seen = set()
    found_titles = {}
    found_isbn = {}
    while pool:
        key = pool.pop()
        seen.add(key)
        e = site.withKey(key)
        translation_of = None
        if False and e.notes:
            m = re_translation_of.search(e.notes)
            if m:
                translation_of = m.group(1).lower()
                pool.update(k for k in title_to_key[translation_of] if k not in seen)
                found_titles.setdefault(translation_of, []).append(key)
        if False and e.isbn_10:
            for i in e.isbn_10:
                found_isbn.setdefault(i, []).append(key)
            join_isbn = ', '.join(map(isbn_link, e.isbn_10))
        else:
            join_isbn = ''
        rec = {
            'key': key,
            'publish_date': e.publish_date,
            'publishers': ', '.join(p.encode('utf-8') for p in (e.publishers or [])),
            'isbn': join_isbn,
        }
        editions.append(rec)

        if e.work_titles:
            for t in e.work_titles:
                t=t.strip('.')
                pool.update(k for k in title_to_key.get(t.lower(), []) if k not in seen)
                found_titles.setdefault(t, []).append(key)
        if e.other_titles:
            for t in e.other_titles:
                t=t.strip('.')
                pool.update(k for k in title_to_key.get(t.lower(), []) if k not in seen)
                found_titles.setdefault(t, []).append(key)

    print '<table>'
    for e in sorted(editions, key=lambda e: e['publish_date'] and e['publish_date'][-4:]):
        print '<tr>'
        print '<td>', ol_link(e['key'])
        print '<td>', e['publish_date'], '</td><td>', e['publishers'], '</td>'
        print '<td>', e['isbn'], '</td>'
        print '</tr>'
    print '</table>'

    if found_titles:
        print '<h2>Other titles</h2>'
        print '<ul>'
        for k, v in found_titles.iteritems():
            if k == title:
                continue
            print '<li><a href="/?title=%s&author=%s">%s</a>' % (k, author, k),
            print 'from', ', '.join(ol_link(i) for i in v)
        print '</ul>'

    extra_isbn = {}
    for k, v in found_isbn.iteritems():
        for isbn, note in find_others(k, rc['amazon_other_editions']):
            if note.lower().find('audio') != -1:
                continue
            if isbn not in found_isbn:
                extra_isbn.setdefault(isbn, []).extend(v)

    if extra_isbn:
        print '<h2>Other ISBN</h2>'
        print '<ul>'
        for k in sorted(extra_isbn):
            print '<li>', isbn_link(k),
            print 'from', ', '.join(ol_link(i) for i in extra_isbn[k])
        print '</ul>'
コード例 #5
0
def search(title, author):

    title_to_key = get_title_to_key(author)
    norm_title = normalize(title).strip('.')

    if norm_title not in title_to_key:
        print 'title not found'
        return

    pool = set(title_to_key[norm_title])

    editions = []
    seen = set()
    found_titles = {}
    found_isbn = {}
    while pool:
        key = pool.pop()
        seen.add(key)
        e = site.withKey(key)
        translation_of = None
        if False and e.notes:
            m = re_translation_of.search(e.notes)
            if m:
                translation_of = m.group(1).lower()
                pool.update(k for k in title_to_key[translation_of]
                            if k not in seen)
                found_titles.setdefault(translation_of, []).append(key)
        if False and e.isbn_10:
            for i in e.isbn_10:
                found_isbn.setdefault(i, []).append(key)
            join_isbn = ', '.join(map(isbn_link, e.isbn_10))
        else:
            join_isbn = ''
        rec = {
            'key':
            key,
            'publish_date':
            e.publish_date,
            'publishers':
            ', '.join(p.encode('utf-8') for p in (e.publishers or [])),
            'isbn':
            join_isbn,
        }
        editions.append(rec)

        if e.work_titles:
            for t in e.work_titles:
                t = t.strip('.')
                pool.update(k for k in title_to_key.get(t.lower(), [])
                            if k not in seen)
                found_titles.setdefault(t, []).append(key)
        if e.other_titles:
            for t in e.other_titles:
                t = t.strip('.')
                pool.update(k for k in title_to_key.get(t.lower(), [])
                            if k not in seen)
                found_titles.setdefault(t, []).append(key)

    print '<table>'
    for e in sorted(
            editions,
            key=lambda e: e['publish_date'] and e['publish_date'][-4:]):
        print '<tr>'
        print '<td>', ol_link(e['key'])
        print '<td>', e['publish_date'], '</td><td>', e['publishers'], '</td>'
        print '<td>', e['isbn'], '</td>'
        print '</tr>'
    print '</table>'

    if found_titles:
        print '<h2>Other titles</h2>'
        print '<ul>'
        for k, v in found_titles.iteritems():
            if k == title:
                continue
            print '<li><a href="/?title=%s&author=%s">%s</a>' % (k, author, k),
            print 'from', ', '.join(ol_link(i) for i in v)
        print '</ul>'

    extra_isbn = {}
    for k, v in found_isbn.iteritems():
        for isbn, note in find_others(k, rc['amazon_other_editions']):
            if note.lower().find('audio') != -1:
                continue
            if isbn not in found_isbn:
                extra_isbn.setdefault(isbn, []).extend(v)

    if extra_isbn:
        print '<h2>Other ISBN</h2>'
        print '<ul>'
        for k in sorted(extra_isbn):
            print '<li>', isbn_link(k),
            print 'from', ', '.join(ol_link(i) for i in extra_isbn[k])
        print '</ul>'
コード例 #6
0
ファイル: use_amazon.py プロジェクト: RaceList/openlibrary
        print '  ', loc
#        keys.update([k for k in rec.keys() if k.find('title') != -1 or k in ('authors', 'title', 'contributions', 'work_title')])
        keys.update(rec.keys())
    print
    for k in keys:
        print k
        for loc, rec in recs:
            print "  ", rec.get(k, '###')
        print
    print

dir = sys.argv[1]
for filename in os.listdir(dir):
    if not filename[0].isdigit():
        continue
    l = find_others(filename, dir)
    if not l:
        continue
    print filename
    for k in site.things({'isbn_10': filename, 'type': '/type/edition'}):
        t = site.withKey(k)
        num = len(t.isbn_10)
        if num == 1:
            num = ''
        print '  OL:', k, t.title, num
        get_records_from_marc(filename)
    for asin, extra in l:
        print asin, extra
        things = site.things({'isbn_10': asin, 'type': '/type/edition'})
        if things:
            for k in things:
コード例 #7
0
        print '  ', loc
        #        keys.update([k for k in rec.keys() if k.find('title') != -1 or k in ('authors', 'title', 'contributions', 'work_title')])
        keys.update(rec.keys())
    print
    for k in keys:
        print k
        for loc, rec in recs:
            print "  ", rec.get(k, '###')
        print
    print

dir = sys.argv[1]
for filename in os.listdir(dir):
    if not filename[0].isdigit():
        continue
    l = find_others(filename, dir)
    if not l:
        continue
    print filename
    for k in site.things({'isbn_10': filename, 'type': '/type/edition'}):
        t = site.withKey(k)
        num = len(t.isbn_10)
        if num == 1:
            num = ''
        print '  OL:', k, t.title, num
        get_records_from_marc(filename)
    for asin, extra in l:
        print asin, extra
        things = site.things({'isbn_10': asin, 'type': '/type/edition'})
        if things:
            for k in things:
コード例 #8
0
ファイル: find.py プロジェクト: RaceList/openlibrary
def search(title, author):
    q = { 'type': '/type/author', 'name': author }
    print q
    authors = site.things(q)
    print authors
    seen = set()
    pool = set()
#    for a in authors:
#        q = { 'type': '/type/edition', 'authors': a, 'title': title }
#        pool.update(site.things(q))
    found_titles = {}
    found_isbn = {}
    author_keys = ','.join("'%s'" % a for a in authors)

    print author_keys
    iter = web.query("select id, key from thing where thing.id in (select thing_id from edition_ref, thing where edition_ref.key_id=11 and edition_ref.value = thing.id and thing.key in (" + author_keys + "))")
    key_to_id = {}
    id_to_key = {}
    for row in iter:
        print row
        key_to_id[row.key] = row.id
        id_to_key[row.id] = row.key


    iter = web.query("select thing_id, edition_str.value as title from edition_str where key_id=3 and thing_id in (select thing_id from edition_ref, thing where edition_ref.key_id=11 and edition_ref.value = thing.id and thing.key in (" + author_keys + "))")
    id_to_title = {}
    title_to_key = {}
    for row in iter:
        print row
        t = row.title.lower().strip('.')
        id_to_title[row.thing_id] = row.title
        title_to_key.setdefault(t, []).append(id_to_key[row.thing_id])

    if title.lower() not in title_to_key:
        print 'title not found'
        return

    pool = set(title_to_key[title.lower()])

    editions = []
    while pool:
        key = pool.pop()
        print key
        seen.add(key)
        e = site.withKey(key)
        translation_of = None
        if e.notes:
            m = re_translation_of.search(e.notes)
            if m:
                translation_of = m.group(1).lower()
                pool.update(k for k in title_to_key[translation_of] if k not in seen)
                found_titles.setdefault(translation_of, []).append(key)
        if e.isbn_10:
            for i in e.isbn_10:
                found_isbn.setdefault(i, []).append(key)
            join_isbn = ', '.join(map(isbn_link, e.isbn_10))
        else:
            join_isbn = ''
        rec = {
            'key': key,
            'publish_date': e.publish_date,
            'publishers': ', '.join(p.encode('utf-8') for p in (e.publishers or [])),
            'isbn': join_isbn,
        }
        editions.append(rec)

        if e.work_titles:
            for t in e.work_titles:
                t=t.strip('.')
                pool.update(k for k in title_to_key.get(t.lower(), []) if k not in seen)
                found_titles.setdefault(t, []).append(key)
        if e.other_titles:
            for t in e.other_titles:
                t=t.strip('.')
                pool.update(k for k in title_to_key.get(t.lower(), []) if k not in seen)
                found_titles.setdefault(t, []).append(key)

    print '<table>'
    for e in sorted(editions, key=lambda e: e['publish_date'] and e['publish_date'][-4:]):
        print '<tr>'
        print '<td>', ol_link(e['key'])
        print '<td>', e['publish_date'], '</td><td>', e['publishers'], '</td>'
        print '<td>', e['isbn'], '</td>'
        print '</tr>'
    print '</table>'

    if found_titles:
        print '<h2>Other titles</h2>'
        print '<ul>'
        for k, v in found_titles.iteritems():
            if k == title:
                continue
            print '<li><a href="/?title=%s&author=%s">%s</a>' % (k, author, k),
            print 'from', ', '.join(ol_link(i) for i in v)
        print '</ul>'

    extra_isbn = {}
    for k, v in found_isbn.iteritems():
        for isbn, note in find_others(k, rc['amazon_other_editions']):
            if note.lower().find('audio') != -1:
                continue
            if isbn not in found_isbn:
                extra_isbn.setdefault(isbn, []).extend(v)

    if extra_isbn:
        print '<h2>Other ISBN</h2>'
        print '<ul>'
        for k in sorted(extra_isbn):
            print '<li>', isbn_link(k),
            print 'from', ', '.join(ol_link(i) for i in extra_isbn[k])
        print '</ul>'