当前位置: 首页>>代码示例>>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;未经允许,请勿转载。