def print_sentiment(filename):
 credentials = GoogleCredentials.get_application_default()
 service = discovery.build('language', 'v1', credentials=credentials)
 with io.open(filename, 'r') as review_file:
  review_file_contents = review_file.read()
 service_request = service.documents().analyzeSentiment(body={'document': {'type': 'PLAIN_TEXT', 'content': review_file_contents}})
 response = service_request.execute()
 score = response['documentSentiment']['score']
 magnitude = response['documentSentiment']['magnitude']
 for (n, sentence) in enumerate(response['sentences']):
  sentence_sentiment = sentence['sentiment']['score']
  print 'Sentence {} has a sentiment score of {}'.format(n, sentence_sentiment)
 print 'Overall Sentiment: score of {} with magnitude of {}'.format(score, magnitude)

def print_sentiment ( filename ) : credentials = GoogleCredentials . get_application_default ( ) service = discovery . build ( 'language' , 'v1' , credentials = credentials ) with io . open ( filename , 'r' ) as review_file : review_file_contents = review_file . read ( ) service_request = service . documents ( ) . analyzeSentiment ( body = { 'document' : { 'type' : 'PLAIN_TEXT' , 'content' : review_file_contents } } ) response = service_request . execute ( ) score = response [ 'documentSentiment' ] [ 'score' ] magnitude = response [ 'documentSentiment' ] [ 'magnitude' ] for ( n , sentence ) in enumerate ( response [ 'sentences' ] ) : sentence_sentiment = sentence [ 'sentiment' ] [ 'score' ] print 'Sentence {} has a sentiment score of {}' . format ( n , sentence_sentiment ) print 'Overall Sentiment: score of {} with magnitude of {}' . format ( score , magnitude )
prints sentiment analysis on a given file contents .