如果多条tweet包含特定关键字| twitter API,如何将其保存到txt文件中

2024-09-30 18:26:44 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的密码

def mentionsGrabber():
#if user wants to scan mentions for a certin phrase then save the tweet that contains the phrase into a txt file

mentions = api.mentions_timeline()
#variables

for tweet in mentions:
    #checks mentions

    global keyword
    global replySave
    keyword = input("what word would you like to search for? | ")
    replySave = input("what '.txt' file would you like to save results too? | ")
    #user inputs

    tweetText = tweet.text
    keywordFind = tweetText.find(keyword)
    #finding tweet and finding keyword in tweet

    if keywordFind >= 0:
        fin = open(replySave, "wt")
        fin.write(tweetText)
        fin.close()

我想能够添加多个tweet到txt文件,而不要求每次搜索词和保存位置。现在,每当我开始它,有多个提到,它要求我为每一个提到的关键字


Tags: thetotxtforifsavekeywordtweet