d60/twikit

monitor reply,like tweets or retweet?

Closed this issue · 4 comments

Can you add the ability to listen for replies or like tweets or retweets against one of your own tweets?

@tanlentboy
You can use streaming to listen for engagement updates for specific tweets.

from twikit.streaming import Topic

# Input the ids of the tweets you want to listen for
tweet_ids = ['1792444629666927026', '1792502527164125517']

# Define the list of topics to listen for events.
topics = {
    Topic.tweet_engagement(id) for id in tweet_ids
}

# Initialize the streaming session.
streaming_session = client.get_streaming_session(topics)

# Iterate through the streaming session and detect events.
for topic, payload in streaming_session:
    if payload.tweet_engagement:
        engagement_event = payload.tweet_engagement

        # Extract the tweet id from the topic string.
        tweet_id = topic.split('/')[-1]

        like_count = engagement_event.like_count
        reply_count = engagement_event.reply_count
        view_count = engagement_event.view_count
        quote_count = engagement_event.quote_count
        retweet_count = engagement_event.retweet_count

        print(f'Engagement Updated ({tweet_id})')
        if like_count is not None:
            print(f'Like Count: {like_count}')
        if reply_count is not None:
            print(f'Reply Count: {reply_count}')
        if view_count is not None:
            print(f'View Count: {view_count}')
        if quote_count is not None:
            print(f'Quote Count: {quote_count}')
        if retweet_count:
            print(f'Retweet Count: {retweet_count}')
        print('===================================')

well

Document : https://twikit.readthedocs.io/en/latest/twikit.html#streaming

Dear Sir, Thank you for your answer, can I also ask you, you are demonstrating to get the number of REPLY or LIKE, can you get the content of the REPLY?

d60 commented

@tanlentboy
retrieve the latest reply using search_tweet when a reply update event received.
Example:

reply = client.search_tweet('conversation_id:1792571239103418577', 'Latest')[0]

@tanlentboy

retrieve the latest reply using search_tweet when a reply update event received.

Example:

reply = client.search_tweet('conversation_id:1792571239103418577', 'Latest')[0]

@d60

Wow, that's brilliant, thank you for your reply. Have a great day every day.