Пример #1
0
def generate_zim_menu_def(perma_ref, menu_def_name, zim_info):
    # this looks only to be used by zims
    # do not generate a menuDef for the test zim
    if perma_ref == 'tes': return ""

    zim_lang = zim_info['language']
    menu_def_lang = iiab.kiwix_lang_to_iso2(zim_lang)
    #filename = menu_def_lang + '-' + perma_ref + '.json'
    # create a stub for this zim
    menu_def = {}
    default_logo = get_default_logo(perma_ref, menu_def_lang)
    menu_def["intended_use"] = "zim"
    menu_def["lang"] = menu_def_lang
    menu_def["logo_url"] = default_logo
    #menuitem = menu_def_lang + '-' + perma_ref
    menu_def["menu_item_name"] = menu_def_name
    menu_def["title"] = zim_info.get('title', '')
    menu_def["zim_name"] = perma_ref
    menu_def["start_url"] = ''
    menu_def["description"] = zim_info.get('description', '')
    menu_def["extra_description"] = ""
    menu_def["extra_html"] = ""
    menu_def[
        "footnote"] = 'Size: ##SIZE##, Articles: ##ARTICLE_COUNT##, Media: ##MEDIA_COUNT##, Date: ##zim_date##'

    menu_def["edit_status"] = "generated"

    #if not os.path.isfile(menu_defs_dir + default_name): # logic to here can still overwrite existing menu def
    #    print(("creating %s"%menu_defs_dir + default_name))
    #    with open(menu_defs_dir + default_name,'w') as menufile:
    #        menufile.write(json.dumps(menuDef,indent=2))

    return menu_def
Пример #2
0
def get_substitution_data(perma_ref, zim_versions, zims_installed,
                          path_to_id_map):
    #reconstruct the path in the id map
    path = 'content/' + zim_versions[perma_ref]['file_name'] + '.zim'
    zim_id = path_to_id_map[path]
    item = zims_installed[zim_id]

    if len(item) != 0 or perma_ref == 'test':
        mediacount = item.get('mediaCount', '')
        articlecount = item.get('articleCount', '')
        size = item.get('size', '')
        tags = item.get('tags', '')
        zim_lang = item.get('language')
        menu_def_lang = iiab.kiwix_lang_to_iso2(zim_lang)
        date = item.get('date', '')
        return (articlecount, mediacount, size, tags, menu_def_lang, date)
    return ('0', '0', '0', '0', '0', '0')
Пример #3
0
def get_substitution_data(perma_ref, zim_versions, zims_installed, path_to_id_map):
    #reconstruct the path in the id map
    path = 'content/' + zim_versions[perma_ref]['file_name'] + '.zim'
    try:
        zim_id = path_to_id_map[path]
        item = zims_installed[zim_id]
    except:
        print("Zim files and library.xml are out of sync. Please run iiab-make-kiwix-lib.")
        sys.exit(1)

    if len(item) != 0 or perma_ref == 'test':
        mediacount = item.get('mediaCount', '')
        articlecount = item.get('articleCount', '')
        size = item.get('size', '')
        tags = item.get('tags', '')
        zim_lang = item.get('language')
        menu_def_lang = iiab.kiwix_lang_to_iso2(zim_lang)
        date = item.get('date', '')
        return (articlecount, mediacount, size, tags, menu_def_lang, date)
    return ('0', '0', '0', '0', '0', '0')