第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

從 Twitter 流中排除回復(fù) - tweepy

從 Twitter 流中排除回復(fù) - tweepy

陪伴而非守候 2023-06-13 10:51:03
我正在使用 tweepy 從 Twitter 的流媒體 API 中提取推文。然后我用它來自動(dòng)回復(fù)那個(gè)用戶。例如,如果我想從中提取實(shí)時(shí)推文然后回復(fù)唐納德特朗普,我使用:import tweepyfrom tweepy import Streamfrom tweepy.streaming import StreamListenerimport jsonclass StdOutListener(StreamListener):    def on_data(self, data):        clean_data = json.loads(data)        tweetId = clean_data["id"]        tweet = "YOUR MESSAGE HERE"        respondToTweet(tweet, tweetId)def setUpAuth():    auth = tweepy.OAuthHandler("consumer_token", "consumer_secret")    auth.set_access_token("access_token", "Access_token_secret")    api = tweepy.API(auth)    return api, authdef followStream():    api, auth = setUpAuth()    listener = StdOutListener()    stream = Stream(auth, listener)    stream.filter(follow=["25073877"], is_async=True)def respondToTweet(tweet, tweetId):    api, auth = setUpAuth()    api.update_status(tweet, in_reply_to_status_id=tweetId, auto_populate_reply_metadata=True)if __name__ == "__main__":    followStream()如果你運(yùn)行我上面的代碼,你會(huì)注意到它確實(shí)回復(fù)了唐納德特朗普,但也回復(fù)了他的推文的所有新回復(fù)我需要添加什么才能從流中排除對(duì)他的推文的回復(fù)?在此先感謝您的幫助。
查看完整描述

1 回答

?
胡子哥哥

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超6個(gè)贊

  • 您可以添加條件以僅直接從followid 響應(yīng)推文。

  • 這應(yīng)該只允許對(duì)所關(guān)注的帳戶做出響應(yīng)。

  • tweetId因此,在這種情況下,僅當(dāng)關(guān)注的帳戶回復(fù)時(shí)才會(huì)回復(fù)。

  • 對(duì)于多個(gè)用戶,測(cè)試包含in

    • if user_id in [25073877, id2, id3,...]:

class StdOutListener(StreamListener):

    def on_data(self, data):

        clean_data = json.loads(data)

        tweetId = clean_data["id"]

        user_id = clean_data['user']['id']

        tweet = 'Trying to figure out this code to answer a question on SO, just ignore this'

        if user_id == 25073877:

            print('Tweeting a reply now')  # optional

            respondToTweet(tweet, tweetId)


查看完整回答
反對(duì) 回復(fù) 2023-06-13
  • 1 回答
  • 0 關(guān)注
  • 148 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)