Exemplo n.º 1
0
def merge_authors(ol, keys, debug=False):
    #    print 'merge author %s:"%s" and %s:"%s"' % (author['key'], author['name'], merge_with['key'], merge_with['name'])
    #    print 'becomes: "%s"' % repr(new_name)
    authors = [
        a for a in (withKey(k) for k in keys)
        if a['type']['key'] != '/type/redirect'
    ]
    not_redirect = set(a['key'] for a in authors)
    if debug:
        for a in authors:
            print(a)

    assert all(a['type']['key'] == '/type/author' for a in authors)
    name1 = authors[0]['name']
    for a in authors:
        print(repr(a['key'], a['name']))
    assert all(match_with_bad_chars(a['name'], name1) for a in authors[1:])

    best_key = pick_best_author(authors)['key']

    imgs = [
        a['key'] for a in authors
        if a['key'] != '/a/OL2688880A' and has_image(a['key'])
    ]
    if len(imgs) == 1:
        new_key = imgs[0]
    else:
        new_key = "/a/OL%dA" % min(key_int(a) for a in authors)
        # Molière and O. J. O. Ferreira
        if len(imgs) != 0:
            print('imgs:', imgs)
            return  # skip
        if not (imgs == [u'/a/OL21848A', u'/a/OL4280680A'] \
                or imgs == [u'/a/OL325189A', u'/a/OL266422A'] \
                or imgs == [u'/a/OL5160945A', u'/a/OL5776228A']):
            print(imgs)
            assert len(imgs) == 0

    print(new_key)
    print(best_key)

    do_normalize(new_key, best_key, authors)
    old_keys = set(k for k in keys if k != new_key)
    print('old keys:', old_keys)

    for old in old_keys:
        # /b/OL21291659M
        switch_author(ol, old, new_key, old_keys, debug=True)
        if old in not_redirect:
            make_redirect(ol, old, new_key)
        q = {
            'authors': old,
            'type': '/type/edition',
        }
        if list(get_things(q)) != []:
            switch_author(ol, old, new_key, old_keys, debug=True)
Exemplo n.º 2
0
def get_langs():
    lang = []
    offset = 0
    while True:
        i = get_things({'type': '/type/language', 'limit': 100, 'offset': offset})
        lang += i
        if len(i) != 100:
            break
        offset += 100
    return set(lang)
Exemplo n.º 3
0
def merge_authors(ol, keys, debug=False):
#    print 'merge author %s:"%s" and %s:"%s"' % (author['key'], author['name'], merge_with['key'], merge_with['name'])
#    print 'becomes: "%s"' % repr(new_name)
    authors = [a for a in (withKey(k) for k in keys) if a['type']['key'] != '/type/redirect']
    not_redirect = set(a['key'] for a in authors)
    if debug:
        for a in authors:
            print(a)

    assert all(a['type']['key'] == '/type/author' for a in authors)
    name1 = authors[0]['name']
    for a in authors:
        print(repr(a['key'], a['name']))
    assert all(match_with_bad_chars(a['name'], name1) for a in authors[1:])

    best_key = pick_best_author(authors)['key']

    imgs = [a['key'] for a in authors if a['key'] != '/a/OL2688880A' and has_image(a['key'])]
    if len(imgs) == 1:
        new_key = imgs[0]
    else:
        new_key = "/a/OL%dA" % min(key_int(a) for a in authors)
        # Molière and O. J. O. Ferreira
        if len(imgs) != 0:
            print('imgs:', imgs)
            return # skip
        if not (imgs == [u'/a/OL21848A', u'/a/OL4280680A'] \
                or imgs == [u'/a/OL325189A', u'/a/OL266422A'] \
                or imgs == [u'/a/OL5160945A', u'/a/OL5776228A']):
            print(imgs)
            assert len(imgs) == 0

    print(new_key)
    print(best_key)

    do_normalize(new_key, best_key, authors)
    old_keys = set(k for k in keys if k != new_key)
    print('old keys:', old_keys)

    for old in old_keys:
        # /b/OL21291659M
        switch_author(ol, old, new_key, old_keys, debug=True)
        if old in not_redirect:
            make_redirect(ol, old, new_key)
        q = { 'authors': old, 'type': '/type/edition', }
        if list(get_things(q)) != []:
            switch_author(ol, old, new_key, old_keys, debug=True)