當前位置: 首頁>>代碼示例>>Python>>正文


Python types.DocumentAttributeFilename方法代碼示例

本文整理匯總了Python中telethon.tl.types.DocumentAttributeFilename方法的典型用法代碼示例。如果您正苦於以下問題:Python types.DocumentAttributeFilename方法的具體用法?Python types.DocumentAttributeFilename怎麽用?Python types.DocumentAttributeFilename使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在telethon.tl.types的用法示例。


在下文中一共展示了types.DocumentAttributeFilename方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: download_files

# 需要導入模塊: from telethon.tl import types [as 別名]
# 或者: from telethon.tl.types import DocumentAttributeFilename [as 別名]
def download_files(self, entity, messages: Iterable[Message], delete_on_success: bool = False):
        messages = reversed(list(messages))
        for message in messages:
            filename_attr = next(filter(lambda x: isinstance(x, DocumentAttributeFilename),
                                        message.document.attributes), None)
            filename = filename_attr.file_name if filename_attr else 'Unknown'
            if message.document.size > free_disk_usage():
                raise TelegramUploadNoSpaceError(
                    'There is no disk space to download "{}". Space required: {}'.format(
                        filename, sizeof_fmt(message.document.size - free_disk_usage())
                    )
                )
            progress = get_progress_bar('Downloading', filename, message.document.size)
            self.download_media(message, progress_callback=progress)
            if delete_on_success:
                self.delete_messages(entity, [message])
            print() 
開發者ID:Nekmo,項目名稱:telegram-upload,代碼行數:19,代碼來源:client.py

示例2: check_media

# 需要導入模塊: from telethon.tl import types [as 別名]
# 或者: from telethon.tl.types import DocumentAttributeFilename [as 別名]
def check_media(reply_message):
    if reply_message and reply_message.media:
        if reply_message.photo:
            data = reply_message.photo
        elif reply_message.document:
            if DocumentAttributeFilename(file_name='AnimatedSticker.tgs') in reply_message.media.document.attributes:
                return False
            if reply_message.gif or reply_message.video or reply_message.audio or reply_message.voice:
                return False
            data = reply_message.media.document
        else:
            return False
    else:
        return False

    if not data or data is None:
        return False
    else:
        return data 
開發者ID:mkaraniya,項目名稱:BotHub,代碼行數:21,代碼來源:deepfry.py

示例3: send_files

# 需要導入模塊: from telethon.tl import types [as 別名]
# 或者: from telethon.tl.types import DocumentAttributeFilename [as 別名]
def send_files(self, entity, files, delete_on_success=False, print_file_id=False,
                   force_file=False, forward=(), caption=None):
        for file in files:
            progress = get_progress_bar('Uploading', os.path.basename(file), os.path.getsize(file))
            name = '.'.join(os.path.basename(file).split('.')[:-1])
            thumb = None
            try:
                thumb = get_file_thumb(file)
            except ThumbError as e:
                click.echo('{}'.format(e), err=True)
            caption = caption[:CAPTION_MAX_LENGTH] if caption else caption
            caption = caption or ((name[:CAPTION_MAX_LENGTH] + '..') if len(name) > CAPTION_MAX_LENGTH else name)
            try:
                if force_file:
                    attributes = [DocumentAttributeFilename(file)]
                else:
                    attributes = get_file_attributes(file)
                message = self.send_file(entity, file, thumb=thumb,
                                         caption=caption, force_document=force_file,
                                         progress_callback=progress, attributes=attributes)
            except Exception:
                raise
            finally:
                if thumb:
                    os.remove(thumb)
            click.echo()
            if print_file_id:
                click.echo('Uploaded successfully "{}" (file_id {})'.format(file, pack_bot_file_id(message.media)))
            if delete_on_success:
                click.echo('Deleting {}'.format(file))
                os.remove(file)
            self.forward_to(message, forward) 
開發者ID:Nekmo,項目名稱:telegram-upload,代碼行數:34,代碼來源:client.py

示例4: upload_block

# 需要導入模塊: from telethon.tl import types [as 別名]
# 或者: from telethon.tl.types import DocumentAttributeFilename [as 別名]
def upload_block(hash_uid):
    try:
        hash_uid = str(hash_uid)
        os.chdir(path_home)
        entity = client.get_entity(client.get_me())
        FIFO = f"upipe_{hash_uid}"

        import errno
        try:
            os.mkfifo(FIFO)
        except OSError as oe:
            if oe.errno != errno.EEXIST:
                raise
        messages = client.get_messages(entity, limit=1, search=hash_uid)   
        with open(FIFO, 'rb') as bytesin:
            if len(messages):
                bytesin.read(1)
                bytesin.close()
                return 0
            message = client.send_file(entity,
                                       file=bytesin,
                                       caption=f'{hash_uid}',
                                       attributes=[DocumentAttributeFilename(f'{hash_uid}')],
                                       allow_cache=False,
                                       part_size_kb=512,
                                       force_document=True,
                                       progress_callback=on_upload_progress)
        return 0
    except Exception:
        return -1
    finally:
        client.disconnect() 
開發者ID:SlavikMIPT,項目名稱:tgcloud,代碼行數:34,代碼來源:download_service.py


注:本文中的telethon.tl.types.DocumentAttributeFilename方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。