def sent_analysis(): positive = 0 negative = 0 neutral = 0 query() from paralleldots import set_api_key, sentiment # Setting API key set_api_key("F6IhnjekXoKsgzOwy1ZsGCX6ph76YK5F6SzFf968gOk") #Viewing API key paralleldots.get_api_key() for tweet in tweets: tweet_text = tweet.text sentiment_type = sentiment(tweet_text) sentiment_values = sentiment_type['sentiment'] if sentiment_values == "positive": positive = positive + 1 elif sentiment_values == "negative": negative = negative + 1 else: neutral = negative + 1 if positive > negative and positive > neutral: print("POSITIVE SENTIMENT with count" + " " + str(positive)) elif negative > positive and negative > neutral: print("NEGATIVE SENTIMENT with count" + " " + str(negative)) else: print("NEUTRAL SENTIMNET with count" + " " + str(neutral))
def sent_analysis(): positive = 0 negative = 0 neutral = 0 query() from paralleldots import set_api_key, sentiment set_api_key("") paralleldots.get_api_key() for tweet in tweets: tweet_text = tweet.text sentiment_type = sentiment(tweet_text) sentiment_values = sentiment_type['sentiment'] if sentiment_values == "positive": positive = positive + 1 elif sentiment_values == "negative": negative = negative + 1 else: neutral = negative + 1 if positive > negative and positive > neutral: print("POSITIVE SENTIMENT with count" + " " + str(positive)) elif negative > positive and negative > neutral: print("NEGATIVE SENTIMENT with count" + " " + str(negative)) else: print("NEUTRAL SENTIMNET with count" + " " + str(neutral))
def get_tweets(username): auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) api = tweepy.API(auth) tweets = api.user_timeline(screen_name=username, count=20) tmp = [] tweets_for_csv = [tweet.text for tweet in tweets] # CSV file created for j in tweets_for_csv: tmp.append(j) var1 = 0 var2 = 0 var3 = 0 print(tmp) from paralleldots import set_api_key, get_api_key, sentiment set_api_key("6dm9k0RomplpimtZETEkwp6JzMTrPSDhhMIiGPGmu68") get_api_key() for t in tmp: a = sentiment(t) print(t, "-->", a) time.sleep(1) if a['sentiment'] == 'positive': var1 += 1 if a['sentiment'] == 'negative': var2 += 1 if a['sentiment'] == 'neutral': var3 += 1 if (var1 > var2) and (var1 > var3): print("This user is positive on Twitter") if (var2 > var3) and (var2 > var1): print("This user is negative on Twitter") if (var3 > var2) and (var3 > var1): print("This user is neutral on Twitter")
def get_sentiments(query): p = 0 n = 0 ne = 0 set_api_key('2Z4UlTNyfjXwIn5CGLy4EvS5IaySrLFfJDiMSPGCo3o') get_api_key() public_tweets = api.search(query) for tweet in public_tweets: text = tweet.text print( colored( "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++", color='blue')) print(colored(tweet.text, color='red')) r = sentiment(tweet.text) print(colored(r, color='red')) result = r['sentiment'] if result == "positive": p = p + 1 elif r['sentiment'] == "neutral": n = n + 1 else: ne = ne + 1 print( colored( "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++", color='green')) print "Maximum positive comments: ", p print "Maximum neutral comments: ", n print "Maximum negative comments: ", ne print( colored( "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++", color='green'))
def sentimentAnalysis(): positive_sentiment=0; negative_sentiment=0; query() from paralleldots import set_api_key, get_api_key,sentiment set_api_key("8dyQhJPFerUALsn2lBpMAftocXOIr6bAFb6vJcrEYYM") get_api_key() for tweet in tweets: txt = tweet.text sentiment_value = sentiment(txt) value = sentiment_value['sentiment'] if value == "positive": positive_sentiment = positive_sentiment + 1 else: negative_sentiment = negative_sentiment + 1 if positive_sentiment > negative_sentiment : print("Sentiment is Positive ") else: print("Sentiment is Negative")
def Determine_the_sentiment(): auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) api = tweepy.API(auth) username = input("enter any user id:") tweets = api.user_timeline(screenname=username, count=20) tmp = [] tweets_for_csv = [tweet.text for tweet in tweets] for j in tweets_for_csv: tmp.append(j) pos = 0 neg = 0 neu = 0 print(tmp) from paralleldots import set_api_key, get_api_key, sentiment set_api_key("2S3zRrv1jxndgO6NQ989I4iJlEU8PHD1aOaAvCM4kw8") get_api_key() for t in tmp: a = sentiment(t) if a['sentiment'] == 'positive': pos += 1 if a['sentiment'] == 'negative': neg += 1 if a['sentiment'] == 'neutral': neu += 1 if (pos > neg) and (pos > neu): print("postive") if (neg > neu) and (neg > pos): print("negative") if (neu > neg) and (neu > pos): print("neutral")
def sentiment_analysis(): flagp = 0 flagn = 0 flagneg = 0 query() from paralleldots import set_api_key, get_api_key from paralleldots import similarity, ner, taxonomy, sentiment, keywords, intent, emotion, abuse, multilang_keywords set_api_key("") get_api_key() for tweet in tweets: text = tweet.text sentiment_value = sentiment(text) values1 = sentiment_value['sentiment'] if values1 == "positive": flagp = flagp + 1 elif values1 == "negative": flagneg = flagneg + 1 else: flagn = flagn + 1 if flagn > flagneg and flagn > flagp: print("Sentiment: Neutral") elif flagneg > flagn and flagneg > flagp: print("Sentiment: Negative") else: print("Sentiment: Positive")
def sixth(): auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) api = tweepy.API(auth) username = input("enter any user id:") tweets = api.user_timeline(screenname=username, count=20) tmp = [] tweets_for_csv = [tweet.text for tweet in tweets] for j in tweets_for_csv: tmp.append(j) flotpos = 0 flotneg = 0 flotneu = 0 print(tmp) from paralleldots import set_api_key, get_api_key, sentiment set_api_key("60TE8tX8lV1KIy8OhpGEUpLRa4RvyJaXA7IsIEXt6x4") get_api_key() for t in tmp: a = sentiment(t) if a['sentiment'] == 'positive': flotpos += 1 if a['sentiment'] == 'negative': flotneg += 1 if a['sentiment'] == 'neutral': flotneu += 1 if (flotpos > flotneg) and (flotpos > flotneu): print("postive") if (flotneg > flotneu) and (flotneg > flotpos): print("negative") if (flotneu > flotneg) and (flotneu > flotpos): print("neutral")
def get_tweets(username): #sentimental analysis auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) api = tweepy.API(auth) tweets = api.user_timeline(screen_name=username, count=20) tmp = [] tweets_for_csv = [tweet.text for tweet in tweets] # CSV file created for j in tweets_for_csv: tmp.append(j) # store the tweets in tmp list var1 = 0 var2 = 0 var3 = 0 print(tmp) from paralleldots import set_api_key, get_api_key, sentiment set_api_key("6dm9k0RomplpimtZETEkwp6JzMTrPSDhhMIiGPGmu68") get_api_key() for t in tmp: a = sentiment(t) print(a) if a['sentiment'] == 'positive': #checking positive tweets var1 += 1 if a['sentiment'] == 'negative': #checking negative tweets var2 += 1 if a['sentiment'] == 'neutral': #checking neutral tweets var3 += 1 if (var1 > var2) and (var1 > var3): #checking the person is positive or not print("positive") if (var2 > var3) and (var2 > var1): #checking the person is negative or not print("negative") if (var3 > var2) and (var3 > var1): #checking the person is neutrl or not print("neutral")
def sentimental(): auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) api = tweepy.API(auth) username = input("enter any user id:") tweets = api.user_timeline(screenname=username, count=20) tmp = [] tweets_for_csv = [tweet.text for tweet in tweets] for j in tweets_for_csv: tmp.append(j) count1 = 0 count2 = 0 count3 = 0 print(tmp) from paralleldots import set_api_key, get_api_key, sentiment set_api_key("M6aheAI13WZLXrxV9Gv3rsm8Fc8kXYKuYapZ7n2G8Wo") get_api_key() for t in tmp: a = sentiment(t) if a['sentiment'] == 'positive': count1 += 1 if a['sentiment'] == 'negative': count2 += 1 if a['sentiment'] == 'neutral': count3 += 1 if (count1 > count2) and (count1 > count3): print("postive") if (count2 > count3) and (count2 > count1): print("negative") if (count3 > count2) and (count3 > count1): print("neutral")
def get_highest_two_emotions(text): paralleldots.set_api_key(paralleldots_TOKEN) paralleldots.get_api_key() emotions = paralleldots.emotion(text)["emotion"] my_list = [k for k, v in emotions.items() if v == max(emotions.values())] if my_list[0] == "Fear": return "Sad" return my_list[0]
def analyze_text_w(text): paralleldots.set_api_key(paralleldots_TOKEN) paralleldots.get_api_key() emotions = paralleldots.emotion(text)["emotion"] pos = (emotions["Happy"] + emotions["Excited"]) / 2 neg = (emotions["Angry"] + emotions["Bored"] + emotions["Fear"] + emotions["Sad"]) / 4 print(pos, " ", neg)
def __init__(self): if os.path.isfile('settings.cfg'): """ If settings file already exists then no need to set up api key, this file is automatically generated by the set and get api key functions.""" print("Settings file already exists with appropriate API details.") else: # Setup api keys, this creates the settings.cfg file. set_api_key("") # Please enter your API key here. get_api_key()
def sentiment_analysis(): set_api_key(key_list) get_api_key() user = api.get_user('vivek_shivam007') stuff = api.user_timeline(screen_name='ippatel', count=10, include_rts=True) print("Sentiment Analysis Result:-") for status in stuff: text = status.text sentiment_value = sentiment(text) print(sentiment_value['sentiment'])
def sentiment_analysis(tweets): set_api_key("4U0rm3Hboel2L0HqxMPvErNT67FQZvr4gBrxwrY1geg") get_api_key() sentiment_ana = [] for text in tweets: value = sentiment(text) sentiment_value = sentiment(text) try: values1 = sentiment_value['sentiment'] sentiment_ana.append(values1) except: sentiment_ana.append("don't know") return sentiment_ana
def __init__(self, tweets): """TweetsAnalysis Class Constructor. :param tweets: List of JSON objects containing certain user's tweets. """ self.tweets = tweets # Setting ParalleDots API keys set_api_key(open('D:/TwitterScraper/ParallelDotsKey.txt', 'r').read()) get_api_key() #Dictionary to save analysis results self.emotions = {}
def run(text, lib='textblob'): try: if lib == 'paralleldot': # Setting your API key paralleldots.set_api_key(Config.PARALLEL_DOT_API_KEY) # Viewing your API key paralleldots.get_api_key() sentiment = paralleldots.sentiment(text)['sentiment'] return max(sentiment, key=sentiment.get) else: testimonial = TextBlob(text) return testimonial.sentiment.polarity except Exception as e: print(e) return 'neutral'
def get_sentiments(query): p = 0 n = 0 ne = 0 set_api_key('S97T8CaNZyl5jDc5HeKh8Xe6MxldTdNL9D4CKbcRy5o') get_api_key() public_tweets = api.search(query) for tweet in public_tweets: text = tweet.text print(colored(tweet.text, color='green')) r = sentiment(tweet.text) print(colored(r, color='green')) result = r['sentiment'] if result == "positive": positive = p + 1 elif r['sentiment'] == "neutral": n = n + 1 else: ne = ne + 1 print "Maximum positive comments: ", positive print "Maximum neutral comments: ", n print "Maximum negative comments: ", ne
def get_sentiments(query): p = 0 n = 0 ne = 0 set_api_key('YjTdGL5qoPMia9yaiziaUjTL2uEvRWFBFu3Rp0sdbd0') get_api_key() public_tweets = api.search(query) for tweet in public_tweets: text = tweet.text print( colored( "*****************************************************************************************" "********************************************************************************************", color='green')) print(colored(tweet.text, color='red')) r = sentiment(tweet.text) print(colored(r, color='red')) result = r['sentiment'] if result == "positive": p = p + 1 elif r['sentiment'] == "neutral": n = n + 1 else: ne = ne + 1 print( colored( "*****************************************************************************************" "********************************************************************************************", color='blue')) print "Maximum positive comments: ", p print "Maximum neutral comments: ", n print "Maximum negative comments: ", ne print( colored( "*****************************************************************************************" "********************************************************************************************", color='blue'))
def get_sentiments(query): p = 0 n = 0 ne = 0 set_api_key('nevysH2HFB0VkHllFav0tUJitebNhLvzU0O5IM9cOTc') get_api_key() public_tweets = api.search(query) for tweet in public_tweets: text = tweet.text print( colored( "-----------------------------------------------------------------------------------------" "----------------------------------------------------------------------------------------------", color='green')) print(colored(tweet.text, color='blue')) r = sentiment(tweet.text) print(colored(r, color='red')) result = r['sentiment'] if result == "positive": p = p + 1 elif r['sentiment'] == "neutral": n = n + 1 else: ne = ne + 1 print( colored( "------------------------------------------------------------------------------------------" "-----------------------------------------------------------------------------------------------", color='cyan')) print "Maximum positive comments: ", p print "Maximum neutral comments: ", n print "Maximum negative comments: ", ne print( colored( "-----------------------------------------------------------------------------------------" "----------------------------------------------------------------------------------------------", color='cyan'))
def get_sentiments(query): p = 0 n = 0 ne = 0 set_api_key('kQmnPQVgdkzuRHaPpQJgqXLAmWlYV6GCx62z8LuitUQ') get_api_key() public_tweets = api.search(query) for tweet in public_tweets: text = tweet.text print( colored( "*****************************************************************************************" "********************************************************************************************", color='green')) print(colored(tweet.text, color='blue')) r = sentiment(tweet.text) print(colored(r, color='red')) result = r['sentiment'] if result == "positive": p = p + 1 elif r['sentiment'] == "neutral": n = n + 1 else: ne = ne + 1 print( colored( "*****************************************************************************************" "********************************************************************************************", color='red')) print "Maximum positive comments: ", p print "Maximum neutral comments: ", n print "Maximum negative comments: ", ne print( colored( "*****************************************************************************************" "********************************************************************************************", color='red'))
def sentiment_analysis(): flagpos = 0 flagneu = 0 flagneg = 0 query() from paralleldots import similarity, taxonomy, sentiment, emotion, abuse set_api_key("fyumEzmg3hQyh3jz6Dhquuf9CYaVPB3TfrpJoR5Mhrs") get_api_key() for tweet in tweets: text = tweet.text sentiment_value = sentiment(text) values1 = sentiment_value['sentiment'] if values1 == "positive": flagpos = flagpos + 1 elif values1 == "negative": flagneg = flagneg + 1 else: flagneu = flagneu + 1 if flagneu > flagneg and flagneu > flagpos: print("Sentiment: Neutral") elif flagneg > flagneu and flagneg > flagpos: print("Sentiment: Negative") else: print("Sentiment: Positive")
def sentiment_analysis(): twpos = 0 twneu = 0 twneg = 0 query() from paralleldots import similarity, taxonomy, sentiment, emotion, abuse set_api_key("") get_api_key() for tweet in tweets: text = tweet.text sentiment_value = sentiment(text) values1 = sentiment_value if values1 == "positive": twpos = twpos + 1 elif values1 == "negative": twneg = twneg + 1 else: twneu = twneu + 1 if twneu > twneg and twneu > twpos: print("Sentiment: Neutral") elif twneg > twneu and twneg > twpos: print("Sentiment: Negative") else: print("Sentiment: Positive")
def is_abusive(text): # import pdb ; # pdb.set_trace() url = 'http://apis.paralleldots.com/v3/abuse' api_key = paralleldots.get_api_key() response = requests.post("https://apis.paralleldots.com/v3/abuse", data={ "api_key": api_key, "text": text }).text # payload = {'apikey': PKEY, 'text': text} text_type = json.loads(response) #text_type = requests.post(url, payload).json() if text_type['sentence_type'] == 'Abusive': print(text_type['confidence_score']) print(text_type['sentence_type']) return True else: return False
from keys import consumer_key, consumer_secret, access_token, access_secret import tweepy from paralleldots import set_api_key, get_api_key from paralleldots import * import nltk from nltk.corpus import * from collections import Counter nltk.download('stopwords') stop_word = set(stopwords.words('english')) set_api_key("IOEJcuuQyQwF0R1Ii7BbZO3jadNBpjVPsdaZLYdNJo4") get_api_key() oauth = tweepy.OAuthHandler(consumer_key, consumer_secret) oauth.set_access_token(access_token, access_secret) api = tweepy.API(oauth) def menu(): print('''1:-Retrieve Tweets 2:-Count the followers 3:-Determine the sentiment 4:-Determine location,language and time zone. 5:-Compare tweets 6:-Analyze top usage 7:-Tweet a message 8:-exit ''') def tweets(): q = input("enter what you want : ") search_results = api.search(q)
# Import import paralleldots import csv # Setting your API key paralleldots.set_api_key("API KEY") # Viewing your API key paralleldots.get_api_key() with open('Training document', mode='r', encoding="utf8") as csv_file: csv_reader = csv.DictReader(csv_file) line_count = 0 for row in csv_reader: if line_count == 0: print(f'Column names are {", ".join(row)}') line_count += 1 #print(f'\nID: {row["ID"]} \n\t with text: {row["Text"]} \n') lines = {row["Text"]} print('\nThe intent analysis results for' + '\033[1m' + ' ID: ' + f'{row["ID"]}' + '\033[0m' + ' in the file:') print("---------------------------------------------------------\n") response = paralleldots.intent(lines) print(response) line_count += 1
def take_picture_with_camera(): paralleldots.set_api_key("br13ubwK9UvtgVahL09oDrw2KxLtRGKygrgonAmLqjY") paralleldots.get_api_key() camera.start_preview() #camera.rotation(180) sleep(0.5) camera.capture('/home/pi/Desktop/image.jpg') camera.stop_preview() path = "/home/pi/Desktop/image.jpg" s = (paralleldots.facial_emotion(path)) ans = dict(s) if ("facial_emotion" in ans): a = list(ans['facial_emotion']) b = dict(a[0]) emotions = b['tag'] #while True: print(emotions) if (emotions == "Angry"): pygame.mixer.music.load("/home/pi/Sounds/Angry.mp3") pygame.mixer.music.play() else: if (emotions == "Disgust"): pygame.mixer.music.load("/home/pi/Sounds/Disgust.mp3") pygame.mixer.music.play() else: if (emotions == "Fear"): pygame.mixer.music.load("/home/pi/Sounds/Fear.mp3") pygame.mixer.music.play() else: if (emotions == "Happy"): pygame.mixer.music.load("/home/pi/Sounds/Happy.mp3") pygame.mixer.music.play() else: if (emotions == "Neutral"): pygame.mixer.music.load( "/home/pi/Sounds/Normal.mp3") pygame.mixer.music.play() else: if (emotions == "Normal"): pygame.mixer.music.load( "/home/pi/Sounds/Normal.mp3") pygame.mixer.music.play() else: if (emotions == "Sad"): pygame.mixer.music.load( "/home/pi/Sounds/Sad.mp3") pygame.mixer.music.play() else: if (emotions == "Surprise"): pygame.mixer.music.load( "/home/pi/Sounds/Surprise.mp3") pygame.mixer.music.play() if (emotions == "Neutral"): CODE("Normal") CODE(emotions) # morse code for the emotions else: print("Face is not detected clearly :( ") GPIO.output(buzzer, GPIO.HIGH) sleep(1) GPIO.output(buzzer, GPIO.LOW) # Play NoFace pygame.mixer.music.load("/home/pi/Sounds/NoFace.mp3") pygame.mixer.music.play() CODE("No Face")
def analyze_text(text): paralleldots.set_api_key(paralleldots_TOKEN) paralleldots.get_api_key() emotions = paralleldots.emotion(text)["emotion"] pos = (emotions["Happy"] + emotions["Excited"]) return pos
from paralleldots import get_api_key, sentiment get_api_key('rijmLUn8FESsEHkWLQLvolUI1mjc7tDmaj8CucrApKg') response = sentiment("GOOD") print response
import paralleldots import unicodedata import bs4 from bs4 import BeautifulSoup as soup from six.moves import urllib import json import sys print("test") # Setting your API key paralleldots.set_api_key("NlSzhn0HmhTaBrK9ufzeKMoyMbJI4uGBYpJkSLXz1uo") # Viewing your API key print("Our API key: " + paralleldots.get_api_key()) # Test getting emotion output from a string def getEmotionsDicFromText(input): text = input emotionsDic = paralleldots.emotion(text) emotionsUnicode = emotionsDic[u'emotion'][u'probabilities'] emotionsStringDic = {} for emotion in emotionsUnicode: emotionsStringDic[unicodedata.normalize('NFKD', emotion).encode( 'ascii', 'ignore')] = emotionsUnicode[emotion] return emotionsStringDic