Exemple #1
0
def generate_thumb(rosetta_links):
    """
    This function returns a thumbnail link in the format needed for personality pages
    :param rosetta_links: that contains IE PID
    :return: The part of a wiki-table to be used for displaying thumbnail
    """
    ies = generate_thumb_link(rosetta_links)
    if ies:
        return VIEW_TEMPLATE.format(ies[0])
    return ''
def generate_thumb(rosetta_links):
    """
    This function returns a thumbnail link in the format needed for personality pages
    :param rosetta_links: that contains IE PID
    :return: The part of a wiki-table to be used for displaying thumbnail
    """
    ies = generate_thumb_link(rosetta_links)
    if ies:
        return VIEW_TEMPLATE.format(ies[0])
    return ''
Exemple #3
0
def create_page_from_dictionary(item_dict, debug=None, create_category_pages=False, site=None):
    """
    create a wikipedia page from a dictionary that describes a primo item
    :param item_dict: primo item as a dictionary/json
    :param debug: if not debug then actually create the pages
    :param create_category_pages: whether to create empty category pages when encountered
    :return: page content in wiki markup
    """
    document_id = item_dict['control']['recordid']
    sourcerecordid = item_dict['control']['sourcerecordid']
    originalsourceid = item_dict['control']['originalsourceid']
    display = item_dict['display']
    try:
        title = display['title']
        if type(title) is list:
            title = title(0) # getting the main title short, the full title is displayed in another location in the page
    except:
        title = trim(item_dict['sort']['title'])
    item_type = display['type'].lower()

    try:
        display_type = type_dict[item_type][1]  # hebrew type as a definite article, e.g. כתב העת
        display_type += " "
    except Exception as e:
        display_type = ""
        print("Unrecognized type '{}'".format(item_type))

    creation_verb = type_dict[item_type][2]
    creators_field = display.get('creator')
    if display.get('contributor'):
        if creators_field:
            creators_field += creators_field + ';' + display.get('contributor')
        else:
            creators_field = display.get('contributor')

    creator = None
    if creators_field:
        authors_to_id = entries_to_authority_id(str_to_list(item_dict['browse']['author']))
        creators = creators_field.split(";")
        creator = ", ".join(set([person_name(authors_to_id, creator.strip()) for creator in creators]))
        creator = comma_and(creator)
    else:
        authors_to_id = {}

    summary = display.get('lds20')

    comments = str_to_list(display.get('lds05'))
    comments_section = None
    if comments:
        comments_section = CR.join(["* " + comment for comment in comments])

    # handle digital images: thumbnail display + links to digital images
    rosetta_link = item_dict["links"].get("linktorsrc")
    view_online = ''
    if rosetta_link:
        # handling the 'view' button & thumbnail image
        thumb_value = generate_thumb_link(rosetta_link)
        if thumb_value:
            view_online = VIEW_ONLINE
            view_online = view_online.replace('{IE}',thumb_value[0])
            view_online = view_online.replace('{title}', title)
    creationdate = display.get('creationdate')
    ispartof = display.get('ispartof')
    performed_by = display.get('lds35')  # list
    performed_by = str_to_list(performed_by)

    performed_by_str = None
    if performed_by:
        performed_by_str = ", ".join(person_name(authors_to_id, performer) for performer in performed_by)

    source = display['source']
    lib_link = display.get('lds21')
    if not lib_link:
        lib_link = item_dict['links']['linktorsrc']
        lib_link = lib_link[lib_link.find("http"):]

    # Building page's Wikicode
    content = "{{DISPLAYTITLE:%s}}\n" % title
    content += "{}'''{}''' {}".format(display_type, title, creation_verb)
    if creator:
        content += " על ידי {}".format(creator)

    if (creationdate):
        content += " בשנת {}".format(creationdate)
    content += CR
    if summary:
        content += CR + summary + CR

    if view_online:
        if len(view_online)>0:
            content += view_online + CR
    content += "==פרטים כלליים==" + CR
    if (performed_by_str):
        content += LIST_ITEM.format("שם מבצע", performed_by_str)
    if (ispartof):
        content += LIST_ITEM.format("מתוך", ispartof)
    if comments_section:
        content += comments_section
    content += CR + "==מידע נוסף==" + CR
    content += LIST_ITEM.format("מקור", source)
    content += "* מספר מערכת: [{} {}]\n".format(lib_link, sourcerecordid)
    content += "== קישורים נוספים ==\n"
    alef_link = ALEF_LINK.format(originalsourceid, sourcerecordid)
    content += "* [{} הפריט בקטלוג הספרייה הלאומית]\n".format(alef_link)

    browse = item_dict.get('browse')
    if browse:
        content += handle_categories(item_dict['browse'], create_category_pages)

    if debug:
        print(content)
    else:
        title = clean_title(title)
        if is_hebrew(title):
            title = limit_length(title)
            create_redirect_wiki_page(site, page_name=clean_title(title), redirect_to=document_id,
                                      summary="Creating redirect page for {}".format(document_id))
        create_wiki_page(site, page_name=document_id, summary="Created from primo", content=content)

    return content
Exemple #4
0
def create_page_from_dictionary(item_dict,
                                debug=None,
                                create_category_pages=False,
                                site=None):
    """
    create a wikipedia page from a dictionary that describes a primo item
    :param item_dict: primo item as a dictionary/json
    :param debug: if not debug then actually create the pages
    :param create_category_pages: whether to create empty category pages when encountered
    :return: page content in wiki markup
    """
    document_id = item_dict['control']['recordid']
    sourcerecordid = item_dict['control']['sourcerecordid']
    originalsourceid = item_dict['control']['originalsourceid']
    display = item_dict['display']
    try:
        title = display['title']
        if type(title) is list:
            title = title(
                0
            )  # getting the main title short, the full title is displayed in another location in the page
    except:
        title = trim(item_dict['sort']['title'])
    item_type = display['type'].lower()

    try:
        display_type = type_dict[item_type][
            1]  # hebrew type as a definite article, e.g. כתב העת
        display_type += " "
    except Exception as e:
        display_type = ""
        print("Unrecognized type '{}'".format(item_type))

    creation_verb = type_dict[item_type][2]
    creators_field = display.get('creator')
    if display.get('contributor'):
        if creators_field:
            creators_field += creators_field + ';' + display.get('contributor')
        else:
            creators_field = display.get('contributor')

    creator = None
    if creators_field:
        authors_to_id = entries_to_authority_id(
            str_to_list(item_dict['browse']['author']))
        creators = creators_field.split(";")
        creator = ", ".join(
            set([
                person_name(authors_to_id, creator.strip())
                for creator in creators
            ]))
        creator = comma_and(creator)
    else:
        authors_to_id = {}

    summary = display.get('lds20')

    comments = str_to_list(display.get('lds05'))
    comments_section = None
    if comments:
        comments_section = CR.join(["* " + comment for comment in comments])

    # handle digital images: thumbnail display + links to digital images
    rosetta_link = item_dict["links"].get("linktorsrc")
    view_online = ''
    if rosetta_link:
        # handling the 'view' button & thumbnail image
        thumb_value = generate_thumb_link(rosetta_link)
        if thumb_value:
            view_online = VIEW_ONLINE
            view_online = view_online.replace('{IE}', thumb_value[0])
            view_online = view_online.replace('{title}', title)
    creationdate = display.get('creationdate')
    ispartof = display.get('ispartof')
    performed_by = display.get('lds35')  # list
    performed_by = str_to_list(performed_by)

    performed_by_str = None
    if performed_by:
        performed_by_str = ", ".join(
            person_name(authors_to_id, performer)
            for performer in performed_by)

    source = display['source']
    lib_link = display.get('lds21')
    if not lib_link:
        lib_link = item_dict['links']['linktorsrc']
        lib_link = lib_link[lib_link.find("http"):]

    # Building page's Wikicode
    content = "{{DISPLAYTITLE:%s}}\n" % title
    content += "{}'''{}''' {}".format(display_type, title, creation_verb)
    if creator:
        content += " על ידי {}".format(creator)

    if (creationdate):
        content += " בשנת {}".format(creationdate)
    content += CR
    if summary:
        content += CR + summary + CR

    if view_online:
        if len(view_online) > 0:
            content += view_online + CR
    content += "==פרטים כלליים==" + CR
    if (performed_by_str):
        content += LIST_ITEM.format("שם מבצע", performed_by_str)
    if (ispartof):
        content += LIST_ITEM.format("מתוך", ispartof)
    if comments_section:
        content += comments_section
    content += CR + "==מידע נוסף==" + CR
    content += LIST_ITEM.format("מקור", source)
    content += "* מספר מערכת: [{} {}]\n".format(lib_link, sourcerecordid)
    content += "== קישורים נוספים ==\n"
    alef_link = ALEF_LINK.format(originalsourceid, sourcerecordid)
    content += "* [{} הפריט בקטלוג הספרייה הלאומית]\n".format(alef_link)

    browse = item_dict.get('browse')
    if browse:
        content += handle_categories(item_dict['browse'],
                                     create_category_pages)

    if debug:
        print(content)
    else:
        title = clean_title(title)
        if is_hebrew(title):
            title = limit_length(title)
            create_redirect_wiki_page(
                site,
                page_name=clean_title(title),
                redirect_to=document_id,
                summary="Creating redirect page for {}".format(document_id))
        create_wiki_page(site,
                         page_name=document_id,
                         summary="Created from primo",
                         content=content)

    return content