How to use the art.art.artError function in art

To help you get started, we’ve selected a few art examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sepandhaghighi / art / art / art.py View on Github external
:type chr_ignore: bool
    :param letters: font letters table
    :type letters: dict
    :return: ascii art as str
    """
    split_list = []
    result_list = []
    splitter = "\n"
    for i in word:
        if (ord(i) == 9) or (ord(i) == 32 and font == "block"):
            continue
        if (i not in letters.keys()):
            if (chr_ignore):
                continue
            else:
                raise artError(str(i) + " is invalid.")
        if len(letters[i]) == 0:
            continue
        split_list.append(letters[i].split("\n"))
    if font in ["mirror", "mirror_flip"]:
        split_list.reverse()
    if len(split_list) == 0:
        return ""
    for i in range(len(split_list[0])):
        temp = ""
        for j in range(len(split_list)):
            if j > 0 and (
                    i == 1 or i == len(
                        split_list[0]) -
                    2) and font == "block":
                temp = temp + " "
            temp = temp + split_list[j][i]
github sepandhaghighi / art / art / art.py View on Github external
def text2art(text, font=DEFAULT_FONT, chr_ignore=True):
    r"""
    Return art text (support \n).

    :param text: input text
    :type text:str
    :param font: input font
    :type font:str
    :param chr_ignore: ignore not supported character
    :type chr_ignore:bool
    :return: ascii art text as str
    """
    letters = standard_dic
    text_temp = text
    if isinstance(text, str) is False:
        raise artError(TEXT_TYPE_ERROR)
    if isinstance(font, str) is False:
        raise artError(FONT_TYPE_ERROR)
    font = font.lower()
    if font != "mix":
        font = indirect_font(font, text)
        letters = get_font_dic(font)
        if FONT_MAP[font][1]:
            text_temp = text.lower()
        if font in UPPERCASE_FONTS:
            text_temp = text.upper()
    else:
        letters = mix_letters()
    word_list = text_temp.split("\n")
    result = ""
    for word in word_list:
        if len(word) != 0:
github sepandhaghighi / art / art / art.py View on Github external
Return art text (support \n).

    :param text: input text
    :type text:str
    :param font: input font
    :type font:str
    :param chr_ignore: ignore not supported character
    :type chr_ignore:bool
    :return: ascii art text as str
    """
    letters = standard_dic
    text_temp = text
    if isinstance(text, str) is False:
        raise artError(TEXT_TYPE_ERROR)
    if isinstance(font, str) is False:
        raise artError(FONT_TYPE_ERROR)
    font = font.lower()
    if font != "mix":
        font = indirect_font(font, text)
        letters = get_font_dic(font)
        if FONT_MAP[font][1]:
            text_temp = text.lower()
        if font in UPPERCASE_FONTS:
            text_temp = text.upper()
    else:
        letters = mix_letters()
    word_list = text_temp.split("\n")
    result = ""
    for word in word_list:
        if len(word) != 0:
            result = result + __word2art(word=word,
                                         font=font,
github sepandhaghighi / art / art / art.py View on Github external
:param chr_ignore: ignore not supported character
    :type chr_ignore:bool
    :param filename: output file name (only tsave)
    :type filename:str
    :param print_status : save message print flag (only tsave)
    :type print_status:bool
    :param overwrite : overwrite the saved file if true (only tsave)
    :type overwrite:bool
    :return: None
    """
    if isinstance(font, str) is False:
        raise artError(FONT_TYPE_ERROR)
    if isinstance(chr_ignore, bool) is False:
        raise artError(CHR_IGNORE_TYPE_ERROR)
    if isinstance(filename, str) is False:
        raise artError(FILE_TYPE_ERROR)
    if isinstance(print_status, bool) is False:
        raise artError(PRINT_STATUS_TYPE_ERROR)
    if isinstance(overwrite, bool) is False:
        raise artError(OVERWRITE_TYPE_ERROR)
    tprint.__defaults__ = (font, chr_ignore)
    tsave.__defaults__ = (font, filename, chr_ignore, print_status, overwrite)
    text2art.__defaults__ = (font, chr_ignore)
github sepandhaghighi / art / art / art.py View on Github external
raise artError(ART_TYPE_ERROR)
    artname = artname.lower()
    arts = sorted(art_dic.keys())
    if artname == "random" or artname == "rand" or artname == "rnd":
        filtered_arts = list(set(arts) - set(RANDOM_FILTERED_ARTS))
        artname = random.choice(filtered_arts)
    elif artname not in art_dic.keys():
        distance_list = list(map(lambda x: distance_calc(artname, x),
                                 arts))
        min_distance = min(distance_list)
        selected_art = arts[distance_list.index(min_distance)]
        threshold = max(len(artname), len(selected_art)) / 2
        if min_distance < threshold:
            artname = selected_art
        else:
            raise artError(ART_NAME_ERROR)
    art_value = art_dic[artname]
    if isinstance(number, int) is False:
        raise artError(NUMBER_TYPE_ERROR)
    if isinstance(art_value, str):
        return (art_value + " ") * number
    if isinstance(text, str) is False:
        raise artError(TEXT_TYPE_ERROR)
    return (art_value[0] + text + art_value[1] + " ") * number
github sepandhaghighi / art / art / art.py View on Github external
distance_list = list(map(lambda x: distance_calc(artname, x),
                                 arts))
        min_distance = min(distance_list)
        selected_art = arts[distance_list.index(min_distance)]
        threshold = max(len(artname), len(selected_art)) / 2
        if min_distance < threshold:
            artname = selected_art
        else:
            raise artError(ART_NAME_ERROR)
    art_value = art_dic[artname]
    if isinstance(number, int) is False:
        raise artError(NUMBER_TYPE_ERROR)
    if isinstance(art_value, str):
        return (art_value + " ") * number
    if isinstance(text, str) is False:
        raise artError(TEXT_TYPE_ERROR)
    return (art_value[0] + text + art_value[1] + " ") * number
github sepandhaghighi / art / art / art.py View on Github external
def art(artname, number=1, text=""):
    """
    Return 1-line art.

    :param artname: artname
    :type artname : str
    :param number: number of repeats
    :type number: int
    :param text: text for bipartite art
    :type text: str
    :return: ascii art as str
    """
    if isinstance(artname, str) is False:
        raise artError(ART_TYPE_ERROR)
    artname = artname.lower()
    arts = sorted(art_dic.keys())
    if artname == "random" or artname == "rand" or artname == "rnd":
        filtered_arts = list(set(arts) - set(RANDOM_FILTERED_ARTS))
        artname = random.choice(filtered_arts)
    elif artname not in art_dic.keys():
        distance_list = list(map(lambda x: distance_calc(artname, x),
                                 arts))
        min_distance = min(distance_list)
        selected_art = arts[distance_list.index(min_distance)]
        threshold = max(len(artname), len(selected_art)) / 2
        if min_distance < threshold:
            artname = selected_art
        else:
            raise artError(ART_NAME_ERROR)
    art_value = art_dic[artname]
github sepandhaghighi / art / art / art.py View on Github external
if artname == "random" or artname == "rand" or artname == "rnd":
        filtered_arts = list(set(arts) - set(RANDOM_FILTERED_ARTS))
        artname = random.choice(filtered_arts)
    elif artname not in art_dic.keys():
        distance_list = list(map(lambda x: distance_calc(artname, x),
                                 arts))
        min_distance = min(distance_list)
        selected_art = arts[distance_list.index(min_distance)]
        threshold = max(len(artname), len(selected_art)) / 2
        if min_distance < threshold:
            artname = selected_art
        else:
            raise artError(ART_NAME_ERROR)
    art_value = art_dic[artname]
    if isinstance(number, int) is False:
        raise artError(NUMBER_TYPE_ERROR)
    if isinstance(art_value, str):
        return (art_value + " ") * number
    if isinstance(text, str) is False:
        raise artError(TEXT_TYPE_ERROR)
    return (art_value[0] + text + art_value[1] + " ") * number