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): # 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): 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): 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): # 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 = '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= 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): 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 credentials 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) text = "" for s in statuses: if (s.lang =='en'): text += s.text.encode('utf-8') # IBM username 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 = '' 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) 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 __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): #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): #Invoke 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') 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): #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): #The Twitter API credentials 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) text = "" for status in statuses: if (status.lang == 'en'): #English tweets text += status.text.encode('utf-8') #IBM 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): 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): 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_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))
def __init__(self, path): """ Instantiates an instance of the LogParser :param str username: Service Credential username :param str password: Service Credential password """ with open('./' + path, 'r') as f: initparser = configparser.ConfigParser() initparser.read_file(f) initparser.keys() self.personality_client = PersonalityInsightsV2( username=initparser['p']['username'], password=initparser['p']['password']) self.tone_client = ToneAnalyzerV3( username=initparser['tone']['username'], password=initparser['tone']['password'], version="2016-02-11") self.decision_client = TradeoffAnalyticsV1( username=initparser['decision']['username'], password=initparser['decision']['password']) self.logs = [] self.lenlog = [len(self.logs)] self.axes = defaultdict(lambda: [0] * (len(self.lenlog) - 1)) self.axes['x'] = self.lenlog
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) text = b'' statuses = twitter_api.GetUserTimeline(screen_name=handle,count=200,include_rts=False) for status in statuses: if(status.lang == 'en'): print (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_file = open("twitter-consumer-key.txt", "r") twitter_consumer_key = twitter_consumer_key_file.read() twitter_consumer_key_file.close() twitter_consumer_secret_file = open("twitter-consumer-secret.txt", "r") twitter_consumer_secret = twitter_consumer_secret_file.read() twitter_consumer_secret_file.close() twitter_access_token_file = open("twitter-access-token.txt", "r") twitter_access_token = twitter_access_token_file.read() twitter_access_token_file.close() twitter_access_secret_file = open("twitter-access-secret.txt", "r") twitter_access_secret = twitter_access_secret_file.read() twitter_access_secret_file.close() 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 #Adjusting for all types of Python if sys.version_info < (3, 0, 0): text += status.text.encode('utf-8') else: text += status.text #The IBM Bluemix credentials for Personality Insights! pi_username_file = open("ibm-username.txt", "r") pi_username = pi_username_file.read() pi_username_file.close() pi_password_file = open("ibm-password.txt", "r") pi_password = pi_password_file.read() pi_password_file.close() personality_insights = PersonalityInsights(username=pi_username, password=pi_password) pi_result = personality_insights.profile(text) return pi_result
def analyse(username): statuses = api.GetUserTimeline(screen_name=username, count=200, include_rts=False) text = "" for s in statuses: if (s.lang == 'en'): text += s.text user_personality = PersonalityInsightsV2(username=USERNAME, password=PASSWORD).profile(text) return user_personality
def analyze(handle): twitter_consumer_key = 'rykNr9mmDA2ivJ0ER2gGi6cfk' twitter_consumer_secret = 't7ZHC9yp0faXr3rDONpWnHnT6eTQAIeDmDV7y2Dz7ilhBilZ89' twitter_access_token = '922168537086681088-oLF3OxVY5gFyNtWpwLTY2uPCbo8DwHi' twitter_access_secret = 'L3tF40kuO2195VTLfP4jAMukNNtQI6qEIz0fsBc9adzOw' 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') 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 = '52uvSUMNZaUayWR43pzAwFcMy' twitter_consumer_secret = 'nGjYIbIshdOQDb1zNWRCVIzUtvZHeih8zOmiS21eoFQeqt1Tmk' twitter_access_token = '989427693031739393-x6yjx5zDHLhvEGOJLbYeL4AEpuDt1XA' twitter_access_secret = 'bOrhE5WTFpiuYC7p0alge3LwNeDRBHvzy3bCGCva3AGPK' 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 += str(s.text.encode('utf-8')) pi_username = '******' # Personality insight credentials pi_password = '******' # Personality insight credentials personality_insights = PersonalityInsights(username=pi_username, password=pi_password) pi_result = personality_insights.profile(text) return pi_result
def analyze(handle): #Enter twitter APP data 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) text = "" for status in statuses: if (status.lang == 'en'): text += status.text.encode('utf-8') pi_username = '' #Enter Personality insights username and password after logging onto IBM website 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 = 'uQ4KRrLXJuAHtPiwaURf4cgSk' twitter_consumer_secret = 'ng1ZWQWZTyKBRfJAkU7teaBiX463F242xqP6GQC4ACzPTvMMRk' twitter_access_token = '2810898171-4lynaBEOrQuCgzjWAAcuVLiqlJ9vrFb6ERfKVpD' twitter_access_secret = 'lR7Q8pw5nc1ngKt6TQvWqMpZ4H3F4nfSxExi4F7FOcG7o' 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=500, include_rts=False) text = b"" 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): #twitter API credentials twitter_consumer_key = 'vsyuJFpJ4tPJ2inHfs0V0BUrR' twitter_consumer_secret = 'EKkFsJriLowri4blYmlULID0Iotlwk5ONshHGR1eT7pJTSxwEB' twitter_access_token = '746320405-LnHEzc4OP6citqes0j3ETFBvIwqVYkXPId8z113k' twitter_access_secret = '4YMuFrg9KEYcpqmLWVAedoDbtNsnEI0Ua19DNYT42tb8x' #create instance of twitter package by calling API method 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) #make a call to the API, pick twitter handles #handle = "@Codecademy" statuses = twitter_api.GetUserTimeline(screen_name=handle, count=200, include_rts=False) #use a for loop to print out tweets, must be connected to internet #print only text of tweets, not metadata text = b"" for status in statuses: if (status.lang =='en'): #English tweets text += status.text.encode('utf-8') #print results #print(text) #IBM credentials for PI pi_username = '******' pi_password = '******' personality_insights = PersonalityInsights(username=pi_username, password=pi_password) pi_results = personality_insights.profile(text) return pi_results
def analyze(handle): twitter_consumer_key = '' #Enter Key twitter_consumer_secret = '' #Enter Consumer Secret Key twitter_access_token = '' #Enter Access Token twitter_access_secret = '' #Enter Secret Access Token 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) # handle = "@jeevi146" 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') # IBM Bluemix credentials for Personality Insights API pi_username = '' #Enter Username pi_password = '' #Enter 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 = 't3< >z' twitter_consumer_secret = 'aM42MIh< >iV7hKhmE' twitter_access_token = '300155156-0k< >1VLoqs' twitter_access_secret = 'l3fNPlb< >HT1r3fDP3' 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) #handle = "@jeevi146" 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') #IBM Bluemix credentials for Personality Insights API pi_username = '******' pi_password = '******' personality_insights = PersonalityInsights(username=pi_username, password=pi_password) pi_result = personality_insights.profile(text) return pi_result
import json from os.path import join, dirname from watson_developer_cloud import PersonalityInsightsV2 as PersonalityInsights personality_insights = PersonalityInsights(username='******', password='******') with open(join(dirname(__file__), 'personality.txt')) as personality_text: print(json.dumps(personality_insights.profile( text=personality_text.read()), indent=2)) # with open(join(dirname(__file__), '../resources/personality.txt') as personality_text: # personality_insights_json = {"contentItems": [ # {"id": "245160944223793152", "userid": "bob", "sourceid": "twitter", "created": 1427720427, # "updated": 1427720427, "contenttype": "text/plain", "charset": "UTF-8", "language": "en-us", # "content": personality_text.read(), "parentid": "", "reply": "false", "forward": "false"}]} # print(json.dumps(personality_insights.profile(text=personality_insights_json), indent=2)) # with open(join(dirname(__file__), '../resources/personality.es.txt') as personality_text: # print(json.dumps(personality_insights.profile(text=personality_text.read(), language='es'), indent=2))