/Tweepy-and-Google-NLP-Exercise

Test on tweepy and different Google NLP APIs but mainly focus on sentiment analysis

Primary LanguagePythonMIT LicenseMIT

Tweepy

Explore the tweepy function

Grad the recent 20 tweets of specific user

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.

Search tweets

alltweets=tweepy.Cursor(api.search,q='Tenet').items(1)
for tweet in alltweets:
	print(tweet.text.encode('utf-8'))

Google-NLP

Test on different Google NLP APIs and mainly focus on sentiment analysis

Command Line Exercise

Following the steps in natural language API quickstarts

  1. Create a project called Project2-Sentiment Analysis on cloud console
  2. Enable billing and cloud natural language API
  3. Create a service account and download private key file used in my environment (each new terminal has to reset the credentials again)
  4. Install and initialize cloud SDK
  5. Try the command line

Entity

gcloud ml language analyze-entities --content="Michelangelo Caravaggio, Italian painter, is known for 'The Calling of Saint Matthew'."

Succeed!

Sentiment

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)

Client Library Exercise

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