Explore the tweepy function
public_tweets = api.user_timeline(username)
for tweet in public_tweets:
print(tweet.text.encode('utf-8'))
My print has some \x symbols as I ran it on windows, which is hard to deal with some utf codes.
alltweets=tweepy.Cursor(api.search,q='Tenet').items(1)
for tweet in alltweets:
print(tweet.text.encode('utf-8'))
Test on different Google NLP APIs and mainly focus on sentiment analysis
Following the steps in natural language API quickstarts
- Create a project called Project2-Sentiment Analysis on cloud console
- Enable billing and cloud natural language API
- Create a service account and download private key file used in my environment (each new terminal has to reset the credentials again)
- Install and initialize cloud SDK
- Try the command line
gcloud ml language analyze-entities --content="Michelangelo Caravaggio, Italian painter, is known for 'The Calling of Saint Matthew'."
Succeed!
gcloud ml language analyze-sentiment --content="I love puppies."
Succeed! (I found that I have to use double quotes here, using single quotes leading to one word read)
I spent a lot of time on this part as at the beginning I found my python script fell into infinite loop. After searching I found I was blocked by the firewall as I can't make a post request to https://language.googleapis.com
curl language.googleapis.com
But after I set up the proxy in environment, I get access to google language server successfully.
Then I ran my python script Hello world which succeeded.
The result of script happy and joyful
The result of script sad