Pakman126
Pakman126

Reputation: 15

Can the Tweepy cursor search query go through a list of words loaded from a file?

I'm trying to make my bot be able to search for multiple keywords through the search API. So far I have:

f = open('swear.txt', 'r')
search = f.read().splitlines()
f.close()

for x in search: #goes through each keyword
    print (x)

numberOfTweets = 5
for tweet in tweepy.Cursor(api.search, q=search).items(numberOfTweets):
    tweet.retweet()

As seen, search holds the strings read in from a file but how do I make the search go through each string? Some sort of lambda function? Thanks

Upvotes: 1

Views: 1634

Answers (1)

MrEdinLaw
MrEdinLaw

Reputation: 76

If i understood right, you want to use every word (in this case "x") to search for them with the tweepy.Cursor? If so, your answer is pretty simple.

f = open('swear.txt', 'r')
search = f.read().splitlines()
f.close()

numberOfTweets = 5
for x in search: #goes through each keyword
    for tweet in tweepy.Cursor(api.search, q=x).items(numberOfTweets):
        tweet.retweet()

Upvotes: 1

Related Questions