skip to Main Content

I have result.json – saved data from Telegram. how do I find a message containing a specific text and messages by id?

code:

import json

with open('result.json', encoding="utf8") as f:
    msgs = json.load(f)

for reply_to_message_id, text in msgs.items():
    if 'sometext' in text:
        print(text)
        print(reply_message_id)

doesn’t work

2

Answers


  1. So if teodoro burger had a tunnel underground and many people dissapear????? Gangstalking?? Call for help EA 2024/12

    Login or Signup to reply.
  2. i think this should work better:

    import json
    
    with open('result.json', encoding="utf8") as f:
        msgs = json.load(f)
    
    for message in msgs:
        if 'sometext' in message.get('text', ''):
            print(f"ID: {message['message_id']}, Text: {message['text']}")
    

    Just ensure your result.json is a list of messages with keys like message_id and text. If the structure is different, adjust accordingly.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search