Skip to content

cli.py

Module that contains the command line application.

get_user_credentials() ¤

Utility function to get a user's credentials from environment variables.

Source code in unminder/cli.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
def get_user_credentials():
    """Utility function to get a user's credentials 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

queue(args=None) ¤

The queue command.

Source code in unminder/cli.py
37
38
39
40
41
42
def queue(args=None):
    """The queue command."""
    parser = argparse.ArgumentParser(prog="queue")
    opts = parser.parse_args(args=args)
    print(opts)
    return 0

review(args=None) ¤

The review command.

Source code in unminder/cli.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
def review(args=None):
    """The review command."""
    parser = argparse.ArgumentParser(prog="review")
    opts = parser.parse_args(args=args)  # noqa

    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()

    return 0