Last active
March 28, 2021 14:01
-
-
Save c0d3x27/1eb4eb9a6d8e29cdb6775f7229a55910 to your computer and use it in GitHub Desktop.
Sentiment Comparation Engine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tweepy | |
from textblob import TextBlob | |
import preprocessor as p | |
import statistics | |
from typing import List | |
from keys import consumer_key, consumer_secret | |
import preprocessor | |
import time | |
import os | |
from banner import __header__ | |
import emoji | |
auth = tweepy.AppAuthHandler(consumer_key, consumer_secret) | |
api = tweepy.API(auth) | |
def recived_tweets(keyword: str) -> List[str]: | |
whole_tweets = [] | |
for tweet in tweepy.Cursor(api.search, q=keyword, tweet_mode="extended", lang="en").items(110): | |
whole_tweets.append(tweet.full_text) | |
return whole_tweets | |
def purified_tweets(whole_tweets: List[str]) -> List[str]: | |
pure_text = [] | |
for tweet in whole_tweets: | |
pure_text.append(p.clean(tweet)) | |
return pure_text | |
def get_feeling(whole_tweets: List[str]) -> List[float]: | |
feeling_results = [] | |
for tweet in whole_tweets: | |
blob = TextBlob(tweet) | |
feeling_results.append(blob.sentiment.polarity) | |
return feeling_results | |
def make_percentage_feeling_score(keyword: str) -> int: | |
tweets = recived_tweets(keyword) | |
pure_text = purified_tweets(tweets) | |
feelings_results = get_feeling(pure_text) | |
make_percentage = statistics.mean(feelings_results) | |
return make_percentage | |
print(__header__) | |
print("\n\n") | |
print("""\ | |
Use this tool to compare people, objects, ect. Using realtime feedback from tweets | |
all around the world. | |
Let us start by.... | |
what is your name? | |
""") | |
if __name__ == '__main__': | |
username = str(input()).title() | |
print("\n") | |
print("Hi, " + username + ". Let's see what does the world prefer today""\n") | |
print("\n\n") | |
print("Here, write down only the name or thing you want to compare?") | |
print("\n\n") | |
first_name = str(input()).title() | |
print("\n\n") | |
print("Against") | |
print("\n\n") | |
second_name = str(input()).title() | |
print("\n\n") | |
first_percentage = make_percentage_feeling_score(first_name) | |
second_percentage = make_percentage_feeling_score(second_name) | |
if (first_name > second_name): | |
print(emoji.emojize(f"Today the world prefers: {first_name} :raised_hands: over {second_name} :thumbs_down:)")) | |
else: | |
print(emoji.emojize(f"Today the world prefers: {second_name} :raised_hands: over {first_name} :thumbs_down:)")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment