def validate_language_map(lang_codes): """ This function will tell you any blockers that you'll hit while running this command. All srt languages must exist in the language map; missing languages will cause errors during command running (which can be long). This function avoids that problem by doing the above consistency check. """ lang_codes = lang_codes or get_all_prepped_lang_codes() missing_langs = [] for lang_code in lang_codes: try: get_language_name(lcode_to_ietf(lang_code), error_on_missing=True) except LanguageNotFoundError: missing_langs.append(lang_code) if missing_langs: logging.warn("Please add the following language codes to %s:\n\t%s" % ( LANG_LOOKUP_FILEPATH, missing_langs, ))
def store_new_counts(lang_code, data_path=SUBTITLES_DATA_ROOT, locale_root=LOCALE_ROOT): """Write a new dictionary of srt file counts in respective download folders""" language_subtitle_count = {} subtitles_path = get_srt_path(lang_code) lang_name = get_language_name(lang_code) try: count = len(glob.glob("%s/*.srt" % subtitles_path)) language_subtitle_count[lang_name] = {} language_subtitle_count[lang_name]["count"] = count language_subtitle_count[lang_name]["code"] = lang_code except LanguageNameDoesNotExist as ldne: count = 0 logging.debug(ldne) except: count = 0 logging.info("%-4s subtitles for %-20s" % ("No", lang_name)) # Always write to disk. write_count_to_json(language_subtitle_count, data_path) return count