I am working on text mining in Python using twitter data to study sentiments on IPO(Initial Public Offering) for Indian Companies. I need help to extract tweets that have multiple terms in them – all inclusive. For example I want tweets in which all three words "Mahindra", "Logistics" and "IPO" is there. Is there a way to do this using the stream function in Python?
I have attached my code also
if __name__ == '__main__':
#This handles Twitter authetification and the connection to Twitter Streaming API
l = StdOutListener()
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
stream = Stream(auth, l)
#This line filter Twitter Streams to capture data by the keywords: 'Mahindra' 'Logistics' 'IPO'
stream.filter(track=['Mahindra,Logistics,IPO'])
3
Answers
I was not able to comment on your question so I had to post an answer.
I haven’t looked into Twitter APIs I do have an alternative though. You can use Twitter Scraper and achieve the same without having to do a lot of coding.
Your code seems to be only a (incomplete) python fragment, but it still looks familiar to me.
I use the following script to fetch data from the Twitter Stream API:
Create an output dir first, and a file config.py
Then call it like this:
I had this exact issue (and I needed to look for tweets that were more than a week old). And since existing packages were too slow I decided to create a small package called Twper. I think you might find it interesting. There’s an example in the Readme that solves ur exact issue.
Disclaimer: I am the author of this package and it is relatively new but hopefully it’ll help.