def shorten_to_len(text, max_len):
    """
    Take a text of arbitrary length and split on new lines.
    Keep adding whole lines until max_len is reached or surpassed.

    Returns the new shorter text.
    """
    shorter_text = ''
    text_parts = text.split("\n")

    while text_parts and len(shorter_text) < max_len:
        shorter_text += text_parts[0] + "\n"
        text_parts = text_parts[1:]

    return shorter_text.rstrip()