在烧瓶中使用电报上传上传文件?

Upload file using telegram-upload in flask?

我们可以通过在终端

上使用以下命令使用telegram-upload库上传文件
telegram-upload file1.mp4 /path/to/file2.mkv

但是如果我想在python函数中调用它,我应该怎么做。我的意思是在 python 函数中,如果用户将文件路径作为参数传递,那么该函数应该能够将文件上传到电报 server.It 文档中没有提到。
换句话说,我想问一下如何从 python 函数内部执行或 运行 shell 命令?

我找到了 solution.Using os 模块,我们可以在 python 函数中 运行 命令行字符串,即 os.system('telegram-upload file1.mp4 /path/to/file2.mkv')

对于telegram-upload,您可以在telegram_upload.management
中使用upload方法 对于 telegram-download 在同一文件中使用 download 方法。

或者你可以在那里看到它们是如何实现的。

from telegram_upload.client import Client
from telegram_upload.config import default_config, CONFIG_FILE
from telegram_upload.exceptions import catch
from telegram_upload.files import NoDirectoriesFiles, RecursiveFiles

DIRECTORY_MODES = {
    'fail': NoDirectoriesFiles,
    'recursive': RecursiveFiles,
}

def upload(files, to, config, delete_on_success, print_file_id, force_file, forward, caption, directories,
           no_thumbnail):
    """Upload one or more files to Telegram using your personal account.
    The maximum file size is 1.5 GiB and by default they will be saved in
    your saved messages.
    """
    client = Client(config or default_config())
    client.start()
    files = DIRECTORY_MODES[directories](files)
    if directories == 'fail':
        # Validate now
        files = list(files)
    client.send_files(to, files, delete_on_success, print_file_id, force_file, forward, caption, no_thumbnail)