def analyze(handle): twitter_consumer_key = '' twitter_consumer_secret = '' twitter_access_token = '' twitter_access_secret = '' twitter_api = twitter.Api(consumer_key=twitter_consumer_key, consumer_secret=twitter_consumer_secret, access_token_key=twitter_access_token, access_token_secret=twitter_access_secret) statuses = twitter_api.GetUserTimeline(screen_name=handle, count=200, include_rts=False) statuses = twitter_api.GetUserTimeline(screen_name=handle, count=200, include_rts=False) text = "" for status in statuses: if (status.lang =='en'): #English tweets text += status.text.encode('utf-8') pi_username = '' pi_password = '' personality_insights = PersonalityInsights(username=pi_username, password=pi_password) pi_result = personality_insights.profile(text) return pi_result
def analyze(handle): # Interact with Twitter API twitter_api = twitter.Api(consumer_key = twitter_consumer_key, consumer_secret = twitter_consumer_secret, access_token_key = twitter_access_token, access_token_secret = twitter_access_secret) # this will retrieve user status statuses = twitter_api.GetUserTimeline(screen_name=handle, count=1200, include_rts=False) # this will be used to store the concatenated twitter posts text = "" for status in statuses: if (status.lang == 'en'): text += status.text.encode('utf-8') # The IBM Bluemix credentials for Personality Insights pi_username = username pi_password = password personality_insights = PersonalityInsights(username = pi_username, password = pi_password) pi_result = personality_insights.profile(text) return pi_result
def analyze(handle): twitter_consumer_key = 'kRCutYPdwXamqjWOMp8ovtAsM' twitter_consumer_secret = 'wYxVJOxAJTEgrvkzrK794sevWMip0puIAvF9ddG9vkSvlKPITD' twitter_access_token = '487095762-dwN6UmHQQjC3xtTyluY2x07rpp9DMODfDccP2FqZ' twitter_access_secret = '8rnOZ5djDRFLcuNHl6CpfENFctxf7UdNAqRkw4pfUzGxM' twitter_api = twitter.Api(consumer_key=twitter_consumer_key, consumer_secret=twitter_consumer_secret, access_token_key=twitter_access_token, access_token_secret=twitter_access_secret) statuses=twitter_api.GetUserTimeline(screen_name=handle, count=200, include_rts=False) text = "" for status in statuses: if(status.lang == 'en'): text += status.text.encode('utf-8') pi_username = '******' pi_password = '******' personality_insights = PersonalityInsights(username=pi_username, password=pi_password) pi_result = personality_insights.profile(text); return pi_result
def analyze(handle): #The Twitter API credentials twitter_consumer_key = 'AQZTpudfZb2BG0jLeMX4JeEoA' twitter_consumer_secret = 'OGYEV5aDs5N3hQoGLLRGkJ9UnDydkAEgsSvrrHfulK9cyCr0uf' twitter_access_token = '886288195494838272-I3cEYrOCRJEqBDOxM6PPZCK5rvdwYXm' twitter_access_secret = 'tYsVWxc17COz2fvky1R6ijAx9I8klsJPmk1HS0bIp5fth' #Invoking the Twitter API twitter_api = twitter.Api(consumer_key=twitter_consumer_key, consumer_secret=twitter_consumer_secret, access_token_key=twitter_access_token, access_token_secret=twitter_access_secret) #Retrieving the last 200 tweets from a user statuses = twitter_api.GetUserTimeline(screen_name=handle, count=200, include_rts=False) #Putting all 200 tweets into one large string called "text" text = "" for s in statuses: if (s.lang == 'en'): text += s.text.encode('utf-8') #Analyzing the 200 tweets with the Watson PI API pi_result = PersonalityInsights(username=pi.u, password=pi.p).profile(text) #Returning the Watson PI API results return pi_result
def analyze(handle): twitter_consumer_key = '0UAUzgrJqnbEHX8e6D6oeqAbT' twitter_consumer_secret = 'h2fczsDeMWgpXovgpZwsJ7zLtOknd3QRuDGrXWucpEVAmEKHwv' twitter_access_token = '839931355991535621-KiPSBgOFHHXVXj9XhYrGF1StFwR9usJ' twitter_access_secret = 'PiEbJp9qhpUblGU2MdphEdNE7TszzgxsASIj8xIWUiiCV' twitter_api = twitter.Api(consumer_key=twitter_consumer_key, consumer_secret=twitter_consumer_secret, access_token_key=twitter_access_token, access_token_secret=twitter_access_secret) statuses = twitter_api.GetUserTimeline(screen_name=handle, count=200, include_rts=False) text = "" for status in statuses: if (status.lang == 'en'): #English tweets text += status.text.encode('utf-8') #The IBM Bluemix credentials for Personality Insights! pi_username = '******' pi_password = '******' personality_insights = PersonalityInsights(username=pi_username, password=pi_password) pi_result = personality_insights.profile(text) return pi_result
def analyze(handle): twitter_consumer_key = 'EAmGMyOSwEAZpHo0lptAZ2iVN' twitter_consumer_secret = 'iyY3miy99t7bKIw74uis8gwBZPnmcyhfqQUjBibiWP3a0ZmD2i' twitter_access_token = '303258207-WwHLiL9YKBRDQQCTKOgqeAZTT0VXB0UQ0XhBBBCM' twitter_access_secret = '85EK988Vj1G0mA3jHif8dgkgemWaqe8mmdCczH0AlCJ8y' twitter_api = twitter.Api(consumer_key=twitter_consumer_key, consumer_secret=twitter_consumer_secret, access_token_key=twitter_access_token, access_token_secret=twitter_access_secret) statuses = twitter_api.GetUserTimeline(screen_name=handle, count=2, include_rts=False) text = "" for s in statuses: if s.lang == 'en': print(s.text) text += s.text pi_username = '******' pi_password = '******' personality_insights = PersonalityInsights(username=pi_username, password=pi_password) pi_result = personality_insights.profile(text) return pi_result
def analyze(handle): twitter_consumer_key = os.environ['TWITTER_CONSUMER_KEY'] twitter_consumer_secret = os.environ['TWITTER_CONSUMER_SECRET'] twitter_access_token = os.environ['TWITTER_ACCESS_TOKEN'] twitter_access_secret = os.environ['TWITTER_ACCESS_SECRET'] twitter_api = twitter.Api(consumer_key=twitter_consumer_key, consumer_secret=twitter_consumer_secret, access_token_key=twitter_access_token, access_token_secret=twitter_access_secret) statuses = twitter_api.GetUserTimeline(screen_name=handle, count=200, include_rts=False) text = "" for status in statuses: if (status.lang == 'en'): text += status.text pi_username = os.environ['WATSON_PI_USERNAME'] pi_password = os.environ['WATSON_PI_PASSWORD'] personality_insights = PersonalityInsights(username=pi_username, password=pi_password) pi_result = personality_insights.profile(text) return pi_result
def analyze(handle): #Invoking the Twitter API twitter_api = twitter.Api(consumer_key=consumer_key, consumer_secret=consumer_secret, access_token_key=access_token, access_token_secret=access_secret) #Retrieving the last 200 tweets from a candidate1 statuses = twitter_api.GetUserTimeline(screen_name=handle, count=200, include_rts=False) #Putting all 200 tweets into one large string called "text" text = "" for s in statuses: if (s.lang == 'en'): text += s.text.encode('utf-8') #Analyzing the 200 tweets with the Watson PI API pi_result = PersonalityInsights(username=pi_username, password=pi_password).profile(text) #Returning the Watson PI API results return pi_result
def __init__(self, handle): self.handle = handle twitter_consumer_key = 'DJNYG9zMErdfOu6pEuyP6G42l' twitter_consumer_secret = 'goURqOB0vN5BQvVQvcKTLkrIge9mjJkBV32pVeKK4zNgNAbRZw' twitter_access_token = '947704874409578498-FJAbBVEoqTd3Q2Wal0HpUaJCw2CIzDO' twitter_access_secret = 'pOxfJ8gecYnNldX9Thq2ydERYEnBuqr0zvWvgFGTemZnQ' pi_username = '******' pi_password = '******' twitter_api = twitter.Api(consumer_key=twitter_consumer_key, consumer_secret=twitter_consumer_secret, access_token_key=twitter_access_token, access_token_secret=twitter_access_secret) statuses = twitter_api.GetUserTimeline(screen_name=self.handle, count=200, include_rts=False) text = "" for status in statuses: if (status.lang == 'en'): text += status.text #.encode('utf-8') #py3 does not need the encode #creating instace of Watson API personality_insights = PersonalityInsights(username=pi_username, password=pi_password) #anaylze the body of text retrieved from Twitter self.pi_result = personality_insights.profile(text)
def analyze(handle): twitter_consumer_key = consumer_key twitter_consumer_secret = consumer_secret twitter_access_token = access_token twitter_access_secret = access_secret twitter_api = twitter.Api(consumer_key=twitter_consumer_key, consumer_secret=twitter_consumer_secret, access_token_key=twitter_access_token, access_token_secret=twitter_access_secret) statuses = twitter_api.GetUserTimeline(screen_name=handle, count=200, include_rts=False) text = "" for s in statuses: if (s.lang == 'en'): text += s.text.encode('utf-8') # Enter credentials from IBM Bluemix Watson Personality Insights pi_username = username pi_password = password personality_insights = PersonalityInsights(username=pi_username, password=pi_password) pi_result = personality_insights.profile(text) return pi_result
def analyze(handle): #The Twitter API credentials twitter_consumer_key = 'bn2Yeb7AsbVORjDH7wbcJIhzm' twitter_consumer_secret = 'A3XWXGCVC0i5f6u2oDuhzqmf96XQWtdArsVGmCM95SzrWdc4xA' twitter_access_token = '614159902-sh3Vc2NhX2HkR2pIhUWVuj5T21LnzpfHJj3IYxyc' twitter_access_secret = 'LsX9xHjEku0xmgViiZPv3zsaCy3tuqnlom8rBFpyyBvnD' #Invoking the Twitter API twitter_api = twitter.Api(consumer_key=twitter_consumer_key, consumer_secret=twitter_consumer_secret, access_token_key=twitter_access_token, access_token_secret=twitter_access_secret) #Retrieving the last 200 tweets from a user statuses = twitter_api.GetUserTimeline(screen_name=handle, count=200, include_rts=False) #Putting all 200 tweets into one large string called "text" text = "" for s in statuses: if (s.lang == 'en'): text += s.text.encode('utf-8') #Analyzing the 200 tweets with the Watson PI API pi_result = PersonalityInsights(username=pi.u, password=pi.p).profile(text) #Returning the Watson PI API results return pi_result
def analyze(handle): twitter_consumer_key = 'bGdNXwpmwC5HZfkeAaBxlD2W8' twitter_consumer_secret = '5KEUc9otby7ZyEPq6nRBKGtdg1O1FyF2e88aY64ZvjX3K4LMFq' twitter_access_token = '65173395-LN8bPsAjqIHrFtT1JXqLGKeSiKI9Zl1fokmhbJNEI' twitter_access_secret = 'piehxmwFJuAoACRiML6YGOlOQQl4vvzgZ7S6QjOv2PBji' twitter_api = twitter.Api(consumer_key=twitter_consumer_key, consumer_secret=twitter_consumer_secret, access_token_key=twitter_access_token, access_token_secret=twitter_access_secret) statuses = twitter_api.GetUserTimeline(screen_name=handle, count=200, include_rts=False) text = (b'') for status in statuses: if (status.lang == 'en'): text += status.text.encode('utf8') pi_username = '******' pi_password = '******' personality_insights = PersonalityInsights(username=pi_username, password=pi_password) pi_result = personality_insights.profile(text) return pi_result
def analyze(handle): #The Twitter API credentials twitter_consumer_key = 'ADD YOUR CONSUMER KEY HERE' twitter_consumer_secret = 'ADD YOUR CONSUMER SECRET HERE' twitter_access_token = 'ADD YOUR ACCESS TOKEN HERE' twitter_access_secret = 'ADD YOUR ACCESS SECRET HERE' #Invoking the Twitter API twitter_api = twitter.Api(consumer_key=twitter_consumer_key, consumer_secret=twitter_consumer_secret, access_token_key=twitter_access_token, access_token_secret=twitter_access_secret) #Retrieving the last 200 tweets from a user statuses = twitter_api.GetUserTimeline(screen_name=handle, count=200, include_rts=False) #Putting all 200 tweets into one large string called "text" text = "" for s in statuses: if (s.lang =='en'): text += s.text.encode('utf-8') #Analyzing the 200 tweets with the Watson PI API pi_result = PersonalityInsights(username=pi.u, password=pi.p).profile(text) #Returning the Watson PI API results return pi_result
def analyze(handle): # Get user's last 200 tweets statuses = twitter_api.GetUserTimeline(screen_name=handle, count=200, include_rts=False) # Convert tweet from Unicode to UTF-8 # Append UTF-8 encoded tweets to the text variable text = "" for status in statuses: if (status.lang == 'en'): text += status.text.encode('utf-8') # Initialize IBM Bluemix credentials for Personality Insights pi_username = '' pi_password = '' # Initialize PersonalityInsights personality_insights = PersonalityInsights(username=pi_username, password=pi_password) # Analyze tweets pi_result = personality_insights.profile(text) # Return results return pi_result
def analyze(handle): #The Twitter API credentials twitter_consumer_key = 'aGYdej7DSjm6cI5vzHaqk3jY0' twitter_consumer_secret = 'AtY8BCzXbTCClswe0jFtWwD4yMDUWP8XTC5pDr0RiEx7jtIBdv' twitter_access_token = '1425486745-TOs5Gajq44ofObjxC215Bz1LyQ49WOHBGI43MAM' twitter_access_secret = 'AzW5qRsLv9grVSWqHz8S56ktEebm8SSHuCfeuQ5r5csIX' #Invoking the Twitter API twitter_api = twitter.Api(consumer_key=twitter_consumer_key, consumer_secret=twitter_consumer_secret, access_token_key=twitter_access_token, access_token_secret=twitter_access_secret) #Retrieving the last 200 tweets from a user statuses = twitter_api.GetUserTimeline(screen_name=handle, count=300, include_rts=False) #Putting all 200 tweets into one large string called "text" text = "" for s in statuses: if (s.lang == 'en'): text += s.text.encode('utf-8') pi_username = '******' pi_password = '******' personality_insights = PersonalityInsights(username=pi_username, password=pi_password) #Analyzing the 200 tweets with the Watson PI API pi_result = personality_insights.profile(text) #Returning the Watson PI API results return pi_result
def analyze(handle): #This code should include the Twitter credentials, IBM credentials, #statuses, and Personality Insights results twitter_consumer_key = 'SSr4gQVk57aoo2Nf4WHWjSnN9' twitter_consumer_secret = 'p7VAgFeMlbJuINVXklOxa6bepU8SMKXTfrJYrBYfwTvb6AcKHa' twitter_access_token = '1365454350-DJJRdfYfrntQg25TlwbCMV0v92YDp4x0CIOpRU8' twitter_access_secret = 'mQdeTSfr7Cvh4zSRxGphwusfVEab4otChcKaGuziC2qyD' twitter_api = twitter.Api(consumer_key=twitter_consumer_key, consumer_secret=twitter_consumer_secret, access_token_key=twitter_access_token, access_token_secret=twitter_access_secret) statuses=twitter_api.GetUserTimeline(screen_name=handle, count=200, include_rts=False) text = "" for status in statuses: if (status.lang =='en'): #English tweets text += status.text.encode('utf-8') #The IBM Bluemix credentials for Personality Insights! pi_username = '******' pi_password = '******' personality_insights = PersonalityInsights(username=pi_username, password=pi_password) pi_result = personality_insights.profile(text) return pi_result
def analyze(handle): twitter_consumer_key = 'cXpt4ecNmEN7UujnnDZCTxv9U' twitter_consumer_secret = 'RyDbE95mi4qBRUkQOgnUY079Gr0S0a8HoFhVaRvf8ewsOEenzF' twitter_access_token = '849260818453737473-dbfMiKDQZpOB6Z4IFRTRlTaLXIcrGqu' twitter_access_secret = 'GHD8wl0iB2EtoF4RfCOYx4kRtf8gPNEqJLVfg940kabnb' twitter_api = twitter.Api(consumer_key=twitter_consumer_key, consumer_secret=twitter_consumer_secret, access_token_key=twitter_access_token, access_token_secret=twitter_access_secret) statuses = twitter_api.GetUserTimeline(screen_name=handle, count=200, include_rts=False) text = "" for status in statuses: if (status.lang == 'en'): text += status.text.encode('utf-8') pi_username = '******' pi_password = '******' personality_insights = PersonalityInsights(username=pi_username, password=pi_password) pi_result = personality_insights.profile(text) return pi_result
def analyze(handle): CONSUMER_KEY = '' CONSUMER_SECRET = '' OAUTH_TOKEN = '' OAUTH_TOKEN_SECRET = '' auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) auth.set_access_token(OAUTH_TOKEN, OAUTH_TOKEN_SECRET) api = tweepy.API(auth) print(api) statuses = api.user_timeline(screen_name=handle, count=100) text = "" for status in statuses: text += (status._json)['text'] #ibm bluemix personal insight credentials pi_username = '' pi_password = '' personality_insights = PersonalityInsights(username=pi_username, password=pi_password) pi_result = personality_insights.profile(text) return pi_result
def analyze(handle): #The Twitter API credentials twitter_consumer_key = 'IneKk1d3i6O0lo5ZZbM4EEfK7' twitter_consumer_secret = 'gffvWRNmNF9ZwHm0XPNZ9SFb6JsA0d7jR64BxQSiz49ro3VtVh' twitter_access_token = '15281154-OuJBpU0ns2yhwhbOlMutCFLBBNDwP9d05PzUfzotO' twitter_access_secret = 'muYF4xiuTZJHb7b2SyPLFfrsfbymFa04j985ofWhBiBmx' #Invoking the Twitter API twitter_api = twitter.Api(consumer_key=twitter_consumer_key, consumer_secret=twitter_consumer_secret, access_token_key=twitter_access_token, access_token_secret=twitter_access_secret) #Retrieving the last 200 tweets from a user statuses = twitter_api.GetUserTimeline(screen_name=handle, count=200, include_rts=False) #Putting all 200 tweets into one large string called "text" text = "" for s in statuses: if (s.lang =='en'): text += s.text.encode('utf-8') #Analyzing the 200 tweets with the Watson PI API pi_result = PersonalityInsights(username=pi.u, password=pi.p).profile(text) #Returning the Watson PI API results return pi_result
def analyze(handle): #The Twitter API credentials twitter_consumer_key = '' twitter_consumer_secret = '' twitter_access_token = '-' twitter_access_secret = '' #Invoking the Twitter API twitter_api = twitter.Api(consumer_key=twitter_consumer_key, consumer_secret=twitter_consumer_secret, access_token_key=twitter_access_token, access_token_secret=twitter_access_secret) #Retrieving the last 200 tweets from a user statuses = twitter_api.GetUserTimeline(screen_name=handle, count=200, include_rts=False) text = "" for s in statuses: if (s.lang =='en'): text += s.text.encode('utf-8') #Analyzing the 200 tweets with the Watson PI API pi_result = PersonalityInsights(username="******", password="******").profile(text) #Returning the Watson PI API results return pi_result
def analyze(handle): twitter_consumer_key= input('Twitter consumer key: \n') twitter_consumer_secret = input('Twitter consumer secret: \n') twitter_access_token= input('Twitter Access Token: \n') twitter_access_secret= input ('Twitter API: \n') twitter_api = twitter.Api(consumer_key=twitter_consumer_key, consumer_secret=twitter_consumer_secret, access_token_key=twitter_access_token, access_token_secret=twitter_access_secret) #Test # handle = "@realdonaldtrump" statuses = twitter_api.GetUserTimeline(screen_name=handle, count=200, include_rts=False) text = "" for status in statuses: # print status.text if (status.lang =='en'): #English tweets text += status.text.encode('utf-8') pi_username = '' pi_password = '' personality_insights = PersonalityInsights(username=pi_username, password=pi_password) pi_result = personality_insights.profile(text) return pi_result
def analyze(handle): #The Twitter API credentials twitter_consumer_key = 'eUYIWnmgkJ8qj5GGfJenojIqR' twitter_consumer_secret = 'ktHMKwAjDdxsILooxrK8awdwEmgAzBRB7FWtxImwJQuspFm39P' twitter_access_token = '3815186718-jDm0o3GzcABtJ9PJmpAcKxN661KNdwwHrXRLAlI' twitter_access_secret = 'ew62OaApFrEZJt1wZtw29XTc5QiqJFL6Z1A2xPFD47goD' #Invoking the Twitter API twitter_api = twitter.Api(consumer_key=twitter_consumer_key, consumer_secret=twitter_consumer_secret, access_token_key=twitter_access_token, access_token_secret=twitter_access_secret) #Retrieving the last 200 tweets from a user statuses = twitter_api.GetUserTimeline(screen_name=handle, count=200, include_rts=False) #Putting all 200 tweets into one large string called "text" text = "" for s in statuses: if (s.lang == 'en'): text += s.text.encode('utf-8') #Analyzing the 200 tweets with the Watson PI API pi_username = '******' pi_password = '******' pi_result = PersonalityInsights(username=pi_username, password=pi_password).profile(text) #Returning the Watson PI API results return pi_result
def analyze(handle): #The Twitter API credentials twitter_consumer_key = 'bXerZzt8GanD42o7kFHb0VPe3' twitter_consumer_secret = 'gHr7A2PJCIX08bv8ZmyxuQLmuRva5w5bxvoWUKRmrmh3iJxuFO' twitter_access_token = '211174890-8nY4AN2ZtZay6HnEchhmOrFgZSBLN5Ypxu13mSTG' twitter_access_secret = 'TqhSFF6K90e4FncJ048JZYjsxSBefR6YoQ4H3OwNnLC0f' #Invoking the Twitter API twitter_api = twitter.Api(consumer_key=twitter_consumer_key, consumer_secret=twitter_consumer_secret, access_token_key=twitter_access_token, access_token_secret=twitter_access_secret) #Retrieving the last 200 tweets from a user statuses = twitter_api.GetUserTimeline(screen_name=handle, count=200, include_rts=False) #Putting all 200 tweets into one large string called "text" text = "" for s in statuses: if (s.lang == 'en'): text += s.text.encode('utf-8') #Analyzing the 200 tweets with the Watson PI API pi_result = PersonalityInsights(username=pi.u, password=pi.p).profile(text) #Returning the Watson PI API results return pi_result
def analyze(handle): #The Twitter API credentials twitter_consumer_key = 'fUsUxkx9MgobZhpSJi2qZii60' twitter_consumer_secret = 'atzAGdDGycm7K5R6odlIwxX1Ohv04tGGkenL4Lf4jarg1PMwUm' twitter_access_token = '2431135844-LqVC9YhOjvaapOpAaFWs3X1mhU3G243nCBsZzkw' twitter_access_secret = 'FXM5d6o8Xf6WiE9ihfdwYkdjgAjojYVNifYwnaKcBx5Lh' #Invoking the Twitter API twitter_api = twitter.Api(consumer_key=twitter_consumer_key, consumer_secret=twitter_consumer_secret, access_token_key=twitter_access_token, access_token_secret=twitter_access_secret) #Retrieving the last 200 tweets from a user statuses = twitter_api.GetUserTimeline(screen_name=handle, count=200, include_rts=False) #Putting all 200 tweets into one large string called "text" text = "" for s in statuses: if (s.lang == 'en'): text += s.text.encode('utf-8') #Analyzing the 200 tweets with the Watson PI API pi_result = PersonalityInsights(username=pi.u, password=pi.p).profile(text) #Returning the Watson PI API results return pi_result
def analyzeUser(text): watson_username = '******' watson_password = '******' watson_result = PersonalityInsights(username=watson_username, password=watson_password).profile(text) return watson_result
def analyze(handle): statuses = twitter_api.GetUserTimeline(screen_name=handle, count=200, include_rts=False) text= "" for status in statuses: if status.lang=='en': text += status.text.encode('utf-8') personality_insights = PersonalityInsights(username=pi_username, password=pi_password) pi_result = personality_insights.profile(text) return pi_result
def analyze(text): # Watson PI API credentials watson_username = '******' watson_password = '******' watson_result = PersonalityInsights(username=watson_username, password=watson_password).profile(text) return watson_result
def get_pi_client(): try: # IBM Bluemix credentials for Personality Insights pi_username = os.environ['PI_USERNAME'] pi_password = os.environ['PI_PASSWORD'] except KeyError: sys.stderr.write("PI_* environment variables not set\n") sys.exit(1) # Create Personality Insights instance personality_insights = PersonalityInsights(username=pi_username, password=pi_password) return personality_insights
def analyze_tweets(self): """ Uploads the string of tweets to the Personality Insights AI of Watson to receive the values of the personality traits. """ personality_insights = PersonalityInsights(username=self.pi_username, password=self.pi_password) twitter_messages = "" for status in self.statuses: if (status.lang == 'en'): twitter_messages += str(status.text.encode('utf-8')) + " " self.pi_result = personality_insights.profile(twitter_messages)
def watson(commentlist, submissionlist): print() from watson_developer_cloud import PersonalityInsightsV2 as PersonalityInsights from IBM_Watson import PIusername, PIpassword if PIusername == '' or PIpassword == '': print("Watson Analysis was requested, but the password and username seem to be empty") return print('\033[92m' + "[+] IBM Watson Personality Insights Results" + '\033[0m') def flatten(orig): data = {} for c in orig['tree']['children']: if 'children' in c: for c2 in c['children']: if 'children' in c2: for c3 in c2['children']: if 'children' in c3: for c4 in c3['children']: if (c4['category'] == 'personality'): data[c4['id']] = c4['percentage'] if 'children' not in c3: if (c3['category'] == 'personality'): data[c3['id']] = c3['percentage'] return data text = "" for comment in commentlist: text += comment['data']['body'] personality_insights = PersonalityInsights(username=PIusername, password=PIpassword) pi_result = personality_insights.profile(text) flattened_result = flatten(pi_result) helperlist = [] for key in flattened_result.keys(): helperlist.append(len(key)) maxlen_key = max(helperlist) for key in flattened_result.keys(): print("- ", ("{:<%d}" % maxlen_key).format(key), ":", end="") value = "%.1f%%" % (flattened_result[key] * 100) print(("{:>4}").format(value))