A
A
alekssamos2021-01-16 08:41:40
Python
alekssamos, 2021-01-16 08:41:40

How to collect all hashtags from a Telegram chat?

You need to get, upon request, a list of all hashtags from a particular chat.
How to do it? The telethon library comes to mind. Collect the entire history of messages and if there is a sign there #, then this is a tag.
But when I do: It still prints all the messages. Then I decided this:client.get_messages(chat, 10, search='#')

while True:
    history = await client(GetHistoryRequest(
      peer=channel,
      offset_id=offset_msg,
      offset_date=None, add_offset=0,
      limit=limit_msg, max_id=0, min_id=0,
      hash=0))
    if not history.messages:
      break
    messages = history.messages
    for message in messages:
      # ...Если есть решётка, значит это хештег, 
      # извлекаем, возможно, регулярным выражением
      #добавляем его в список

Will this work as I intended
or is there a better way? Because if there are a million messages in the group, he will scan each one like that, will there be too many requests and you can reach the limit or block?
Sources: 1 2

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Shitskov, 2021-01-16
@Zarom

Check/filter messages when searching by entity type - in your case hashtag
https://core.telegram.org/bots/api#messageentity

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question