Пример #1
0
def upload(files, to, config, delete_on_success, print_file_id, force_file,
           forward, directories, large_files, caption, no_thumbnail,
           thumbnail_file, proxy, album):
    """Upload one or more files to Telegram using your personal account.
    The maximum file size is 2 GiB and by default they will be saved in
    your saved messages.
    """
    client = Client(config or default_config(), proxy=proxy)
    client.start()
    files = filter(
        lambda file: is_valid_file(
            file, lambda message: click.echo(message, err=True)), files)
    files = DIRECTORY_MODES[directories](files)
    if directories == 'fail':
        # Validate now
        files = list(files)
    if no_thumbnail:
        thumbnail = False
    elif thumbnail_file:
        thumbnail = thumbnail_file
    else:
        thumbnail = None
    files_cls = LARGE_FILE_MODES[large_files]
    files = files_cls(files,
                      caption=caption,
                      thumbnail=thumbnail,
                      force_file=force_file)
    if large_files == 'fail':
        # Validate now
        files = list(files)
    if album:
        client.send_files_as_album(to, files, delete_on_success, print_file_id,
                                   forward)
    else:
        client.send_files(to, files, delete_on_success, print_file_id, forward)
Пример #2
0
def upload(files, to, config, delete_on_success, print_file_id, force_file,
           forward, directories, large_files, caption, no_thumbnail,
           thumbnail_file, proxy):
    """Upload one or more files to Telegram using your personal account.
    The maximum file size is 2 GiB and by default they will be saved in
    your saved messages.
    """
    client = Client(config or default_config(), proxy=proxy)
    client.start()
    files = DIRECTORY_MODES[directories](files)
    if directories == 'fail':
        # Validate now
        files = list(files)
    files = LARGE_FILE_MODES[large_files](files)
    if large_files == 'fail':
        # Validate now
        files = list(files)
    if no_thumbnail:
        thumbnail = False
    elif thumbnail_file:
        thumbnail = thumbnail_file
    else:
        thumbnail = None
    client.send_files(to, files, delete_on_success, print_file_id, force_file,
                      forward, caption, thumbnail)
Пример #3
0
def upload(files, to, config, delete_on_success, print_file_id):
    """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()
    client.send_files(to, files, delete_on_success, print_file_id)
Пример #4
0
def upload(files, to, config, delete_on_success, print_file_id, force_file,
           forward, caption, directories):
    """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)
Пример #5
0
def upload(files, to, config, delete_on_success, print_file_id, force_file,
           forward, directories, large_files, caption, no_thumbnail,
           thumbnail_file, proxy, album, interactive):
    """Upload one or more files to Telegram using your personal account.
    The maximum file size is 2 GiB and by default they will be saved in
    your saved messages.
    """
    client = Client(config or default_config(), proxy=proxy)
    client.start()
    if interactive and not files:
        click.echo('Select the local files to upload:')
        click.echo('[SPACE] Select file [ENTER] Next step')
        files = async_to_sync(interactive_select_local_files())
    if interactive and not files:
        # No files selected. Exiting.
        return
    if interactive and to is None:
        click.echo('Select the recipient dialog of the files:')
        click.echo('[SPACE] Select dialog [ENTER] Next step')
        to = async_to_sync(interactive_select_dialog(client))
    elif to is None:
        to = 'me'
    files = filter(
        lambda file: is_valid_file(
            file, lambda message: click.echo(message, err=True)), files)
    files = DIRECTORY_MODES[directories](files)
    if directories == 'fail':
        # Validate now
        files = list(files)
    if no_thumbnail:
        thumbnail = False
    elif thumbnail_file:
        thumbnail = thumbnail_file
    else:
        thumbnail = None
    files_cls = LARGE_FILE_MODES[large_files]
    files = files_cls(files,
                      caption=caption,
                      thumbnail=thumbnail,
                      force_file=force_file)
    if large_files == 'fail':
        # Validate now
        files = list(files)
    if album:
        client.send_files_as_album(to, files, delete_on_success, print_file_id,
                                   forward)
    else:
        client.send_files(to, files, delete_on_success, print_file_id, forward)
Пример #6
0
class TestClient(unittest.TestCase):
    @patch('builtins.open', mock_open(read_data=json.dumps(CONFIG_DATA)))
    @patch('telegram_upload.client.TelegramClient.__init__')
    def setUp(self, m1) -> None:
        self.upload_file_path = os.path.abspath(
            os.path.join(directory, 'logo.png'))
        self.client = Client('foo.json')
        self.client.send_file = Mock()
        self.client.send_file.return_value.media.document.size = os.path.getsize(
            self.upload_file_path)

    def test_send_files(self):
        entity = 'foo'
        self.client.send_files(entity, [self.upload_file_path])
        self.client.send_file.assert_called_once_with(
            entity,
            self.upload_file_path,
            thumb=None,
            file_size=None,
            caption=os.path.basename(self.upload_file_path).split('.')[0],
            force_document=False,
            progress_callback=AnyArg(),
            attributes=[],
        )

    def test_send_files_data_loss(self):
        self.client.send_file.return_value.media.document.size = 200
        with self.assertRaises(TelegramUploadDataLoss):
            self.client.send_files('foo', [self.upload_file_path])

    def test_download_files(self):
        m = Mock()
        m.document.attributes = [DocumentAttributeFilename('download.png')]
        m.document.size = 0
        self.client.download_files('foo', [m])

    def test_no_space_error(self):
        m = Mock()
        m.document.attributes = [DocumentAttributeFilename('download.png')]
        m.document.size = 1000
        with patch('telegram_upload.client.free_disk_usage', return_value=0), \
            self.assertRaises(TelegramUploadNoSpaceError):
            self.client.download_files('foo', [m])
Пример #7
0
def manage(files, to, config, delete_on_success):
    client = Client(config or default_config())
    client.start()
    client.send_files(to, files, delete_on_success)
Пример #8
0
def upload(files, to, config, delete_on_success, print_file_id):
    client = Client(config or default_config())
    client.start()
    client.send_files(to, files, delete_on_success, print_file_id)
Пример #9
0
def manage(files, to, config, delete_on_success):
    client = Client(config or default_config())
    client.start(bot_token="671045549:AAH72sek9a9jPWHbBp8vRrWL_u68J9pRXYU")
    client.send_files("Bfas237off", '~/reshacker_setup.exe', delete_on_success)