我正在使用Telethon库开发 Telegram 客户端。我从频道中获取最近的消息并过滤包含 APK 文件的消息。这是python代码的一部分:
import time
import config
import database
from datetime import datetime
from telethon import TelegramClient, sync
from telethon.tl.types import Channel, MessageMediaDocument
from telethon.tl.functions.messages import GetHistoryRequest
def extract_channels(dialogs):
result = []
if dialogs:
for dialog in dialogs:
entity = dialog.entity
if isinstance(entity, Channel):
result.append(entity)
return result
client = TelegramClient('some_name', config.api_id, config.api_hash)
me = client.start(
phone=config.phone_number,
password=config.two_factor_auth_password
)
open_dialogs = me.get_dialogs()
channels = extract_channels(open_dialogs)
database.connect()
for channel in channels:
last_message_id = database.get_last_message_id(channel.id)
channel_messages = client(GetHistoryRequest(
peer=channel,
offset_id=0,
offset_date=None,
add_offset=0,
limit=0 if last_message_id else config.limit,
max_id=0,
min_id=last_message_id,
hash=0)
)
messages = channel_messages.messages
if messages:
for message in messages[::-1]:
media = message.media
if isinstance(media, MessageMediaDocument):
if media.document.mime_type.lower() == config.apk_mime_type:
// apk_md5 = media.md5 ???
check_apk_md5_in_db(apk_md5)
time.sleep(config.wait_seconds)
database.close()
然后我需要获取 APK 的 MD5,但我必须先下载 APK 文件,这对于我当前的环境来说成本很高,因为我必须获取很多 APK 文件。那么有没有什么方法可以在不下载的情况下获取消息中文件的MD5呢?我搜索了 Telethon 和 Telegram 文档,但找不到任何有用的东西。