I'm a beginner Python programmer I am finding it hard to figure out a simple Tweepy Streaming api.
Basically I am trying to do the below.
Stream tweets in Portuguese language.
Show the sentiment of each tweets.
I am unable to stream language tweets. Could someone please help me in figuring out what is it that I am doing wrong.
import tweepy
from textblob import TextBlob
### I have the keys updated on those veriables
auth = tweepy.OAuthHandler(CONSUMER_KEY,CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN,ACCESS_TOKEN_SECRET)
API = tweepy.API(auth)
class MyStreamListener(tweepy.StreamListener):
def on_status(self, status):
print("--------------------")
print(status.text)
analysis = TextBlob(status.text)
if analysis.sentiment.polarity > 0:
print("sentiment is positiv")
elif analysis.sentiment.polarity == 0:
print("sentiment is Neutral")
else:
print("sentiment is Negative")
print("--------------------\n")
myStreamListener = MyStreamListener()
myStream = tweepy.Stream(auth = API.auth, listener=myStreamListener, tweet_mode='extended', lang='pt')
myStream.filter(track=['trump'])
The example o/p is
RT @SAGEOceanTweets: Innovation Hack Week 2019: @nesta_uk is exploring the possibility of holding a hack week in 2019, focused on state-of-�
However it stops after few tweets and I get this error
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode
character '\U0001f4ca' in position 76: character maps to <undefined>
[Finished in 85.488s]
And also the tweets are not in Portuguese. How can I stream continuously and also get tweets which are in portuguese and perform a Sentiment analysis
Could you folks please also guide me on how to even stream language tweets and then analyze the sentiment using textblob.
Thank you