Skip to content

unminder ¤

Unminder package.

Queue things in a list, review them later.

Functions:

  • get_parser –

    Return the CLI argument parser.

  • get_user_credentials –

    Read the Telegram username, API ID, and API hash from environment variables.

  • main –

    Run the main program.

  • review –

    Print the configured user's Telegram messages in oldest-first order.

get_parser ¤

get_parser() -> ArgumentParser

Return the CLI argument parser.

Returns:

Source code in src/unminder/_internal/cli.py
 94
 95
 96
 97
 98
 99
100
101
102
103
def get_parser() -> argparse.ArgumentParser:
    """Return the CLI argument parser.

    Returns:
        An argparse parser.
    """
    parser = argparse.ArgumentParser(prog="unminder")
    parser.add_argument("-V", "--version", action="version", version=f"%(prog)s {debug._get_version()}")
    parser.add_argument("--debug-info", action=_DebugInfo, help="Print debug information.")
    return parser

get_user_credentials ¤

get_user_credentials() -> tuple[str, int, str]

Read the Telegram username, API ID, and API hash from environment variables.

Source code in src/unminder/_internal/cli.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def get_user_credentials() -> tuple[str, int, str]:
    """Read the Telegram username, API ID, and API hash from environment variables."""
    try:
        username = os.environ["TELEGRAM_USERNAME"]
        api_id = int(os.environ["TELEGRAM_API_ID"])
        api_hash = os.environ["TELEGRAM_API_HASH"]
    except (TypeError, KeyError):
        print(
            "error: Please set the following environment variables:\n"
            "TELEGRAM_USERNAME, TELEGRAM_API_ID, TELEGRAM_API_HASH",
            file=sys.stderr,
        )
        sys.exit(1)
    return username, api_id, api_hash

main ¤

main(args: list[str] | None = None) -> int

Run the main program.

This function is executed when you type unminder or python -m unminder.

Parameters:

  • args ¤

    (list[str] | None, default: None ) –

    Arguments passed from the command line.

Returns:

  • int –

    An exit code.

Source code in src/unminder/_internal/cli.py
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
def main(args: list[str] | None = None) -> int:
    """Run the main program.

    This function is executed when you type `unminder` or `python -m unminder`.

    Parameters:
        args: Arguments passed from the command line.

    Returns:
        An exit code.
    """
    parser = get_parser()
    opts = parser.parse_args(args=args)
    print(opts)
    return 0

review ¤

review(args: list[str] | None = None) -> None

Print the configured user's Telegram messages in oldest-first order.

Print the message count before the text of each message.

Source code in src/unminder/_internal/cli.py
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
def review(args: list[str] | None = None) -> None:
    """Print the configured user's Telegram messages in oldest-first order.

    Print the message count before the text of each message.
    """
    parser = argparse.ArgumentParser(prog="review")
    opts = parser.parse_args(args=args)  # noqa: F841

    username, api_id, api_hash = get_user_credentials()
    client = TelegramClient("review", api_id, api_hash)
    client.start()

    messages = list(reversed(client.iter_messages(username)))
    print(len(messages))

    download_media = False
    for message in messages:
        if not message.message:
            if download_media:
                media = message.download_media()
                if media:
                    print(media)
        else:
            print(message.message)
            print()