Closed Isabelane closed 7 months ago
for tweet in ts.search_tweets_iterable(tso): #tso metadata print('created_at: ',tweet['created_at'], 'user_id: ',tweet['id_str'], 'Tweet: ',tweet['text'],' Like:',tweet['favorite_count'], 'RTs:', tweet['retweet_count'], 'geo:', tweet['geo'],'Source:',tweet['source'] ) created_at = tweet ['created_at'] user_id = tweet['id_str'] texto = tweet['text'] Like = tweet['favorite_count'] RTs = tweet['retweet_count'] geo = tweet['geo'] Source = tweet['source'] with open("tweet.json", "a+") as output: data = { "created_at": created_at, "user_id": user_id, "tweet":texto, "favorite_count":Like, "retweet_count":RTs, "geo":geo, "Source":Source} output.write("{}\n".format(json.dumps(data)))
except TwitterSearchException as e: print(e)
pd = pd.read_json("tweet.json", lines = True)
contador=0
def clean_tweet(tweet): return ' '.join(re.sub("(@[A-Za-z0-9]+)|([^0-9A-Za-z \t])|(\w+:\/\/\S+)", " ", tweet).split()) def analize_sentimentEN(tweet): print("Executando função: analize_sentimentEN") global contador contador+=1 print(contador) analysis = TextBlob(tweet) time.sleep(1.6)
if analysis.detect_language() != 'en': analysis = TextBlob(str(analysis.translate(from_lang= 'pt', to_lang='en'))) time.sleep(1.8) if analysis.sentiment.polarity > 0: return 1 elif analysis.sentiment.polarity == 0: return 0 else: return -1
listaTweets = pd['tweet'].tolist()
listaResultadoSentimentos = []
for elemento in listaTweets: listaResultadoSentimentos.append(analize_sentimentEN(elemento))
pd['Sentimento'] = listaResultadoSentimentos
listaResultado = pd["Sentimento"].tolist() listaClassificada = []
for elemento in listaResultado: print(elemento) if elemento == 1: listaClassificada.append("Positivo") elif elemento == 0: listaClassificada.append("Neutro") elif elemento == -1: listaClassificada.append("Negativo")
pd["Classificacao"] = listaClassificada
HTTPError Traceback (most recent call last)
@sloria help please
Same problem
language detection and translation have been removed from textblob. it is recommended that you use the google translate API directly
except TwitterSearchException as e: print(e)
pd = pd.read_json("tweet.json", lines = True)
contador=0
def clean_tweet(tweet): return ' '.join(re.sub("(@[A-Za-z0-9]+)|([^0-9A-Za-z \t])|(\w+:\/\/\S+)", " ", tweet).split()) def analize_sentimentEN(tweet): print("Executando função: analize_sentimentEN") global contador contador+=1 print(contador) analysis = TextBlob(tweet) time.sleep(1.6)
listaTweets = pd['tweet'].tolist()
listaResultadoSentimentos = []
for elemento in listaTweets: listaResultadoSentimentos.append(analize_sentimentEN(elemento))
pd['Sentimento'] = listaResultadoSentimentos
listaResultado = pd["Sentimento"].tolist() listaClassificada = []
for elemento in listaResultado: print(elemento) if elemento == 1: listaClassificada.append("Positivo") elif elemento == 0: listaClassificada.append("Neutro") elif elemento == -1: listaClassificada.append("Negativo")
pd["Classificacao"] = listaClassificada
HTTPError Traceback (most recent call last)