def main(): # prompts user for the files that they would like to analyze tweetFile = input( "Please enter the name of the tweet file you wish to process: ") keyFile = input( "Please enter the name of the keyword file you wish to use: ") # takes the files and uses the function compute_tweets to return a list of values values = compute_tweets(tweetFile, keyFile) # takes the list of values and prints them in a readable fashion print("\nEastern Region Results") print("%-35s" % "Happiness score:", values[0][0], "\n%-35s" % "Number of keyword tweets:", values[0][1], "\n%-35s" % "Total number of tweets:", values[0][2]) print("\nCentral Region Results") print("%-35s" % "Happiness score:", values[1][0], "\n%-35s" % "Number of keyword tweets:", values[1][1], "\n%-35s" % "Total number of tweets:", values[1][2]) print("\nMountain Region Results") print("%-35s" % "Happiness score:", values[2][0], "\n%-35s" % "Number of keyword tweets:", values[2][1], "\n%-35s" % "Total number of tweets:", values[2][2]) print("\nPacific Region Results") print("%-35s" % "Happiness score:", values[3][0], "\n%-35s" % "Number of keyword tweets:", values[3][1], "\n%-35s" % "Total number of tweets:", values[3][2])
def main(): tweet_file_name = str(input("Please submit the file with the tweets: ") ) # Get's the file with the tweets keyword_file_name = str(input("Please submit the file with the keywords: ") ) # Get's the file with the keywords files = file_extension( tweet_file_name, keyword_file_name) # Checks the extensions on the file names sentiments = sentiment_analysis.compute_tweets(files[0], files[1]) print("Eastern tweet results: Average: " + str(sentiments[0][0]) + ", number of keyword tweets: " + str(sentiments[0][1]) + ", number of tweets in region: " + str(sentiments[0][2])) # Prints the value compute tweets returns print("Central tweet results: Average: " + str(sentiments[1][0]) + ", number of keyword tweets: " + str(sentiments[1][1]) + ", number of tweets in region: " + str(sentiments[1][2])) # Prints the value compute tweets returns print("Mountain tweet results: Average: " + str(sentiments[2][0]) + ", number of keyword tweets: " + str(sentiments[2][1]) + ", number of tweets in region: " + str(sentiments[2][2])) # Prints the value compute tweets returns print("Pacific tweet results: Average: " + str(sentiments[3][0]) + ", number of keyword tweets: " + str(sentiments[3][1]) + ", number of tweets in region: " + str(sentiments[3][2])) # Prints the value compute tweets returns
def main(): tweetFile = input("Please enter the name of the file containing tweets: ") keywordFile = input("Please enter the name of the file containing keywords: ") timezoneHappinessList = compute_tweets(tweetFile, keywordFile) if timezoneHappinessList == []: print(timezoneHappinessList) else: eastern = timezoneHappinessList[0] central = timezoneHappinessList[1] mountain = timezoneHappinessList[2] pacific = timezoneHappinessList[3] print('Eastern timezone: average "happiness value" = %s, number of tweets = %d' % (str(eastern[0]), eastern[1])) print('Central timezone: average "happiness value" = %s, number of tweets = %d' % (str(central[0]), central[1])) print('Mountain timezone: average "happiness value" = %s, number of tweets = %d' % (str(mountain[0]), mountain[1])) print('Pacific timezone: average "happiness value" = %s, number of tweets = %d' % (str(pacific[0]), pacific[1])) return
def main(): # Introductory statement print("Welcome to the Sentiment Calculator.") print("") # Prompt the user to input the name of the file of tweets and the file of keywords tweets = input("Please enter the name of the file with the Tweets: ") keywords = input("Please enter the name of the file with the Keywords: ") # Send the two files to function "compute_tweets" and set the return list value as scoreData scoreData = compute_tweets(tweets, keywords) print("") # Only perform actions in if-statement if scoreData is not an empty list if len(scoreData) != 0: # Print out the results in 4 sections based on time-zone for i in range(0,4): if i == 0: print("EASTERN REGION") elif i == 1: print("CENTRAL REGION") elif i == 2: print("MOUNTAIN REGION") else: print("PACIFIC REGION") # Print the associated average happiness score, number of keyword tweets and number of tweets # of each time-zone. This is stored in scoreData. print("") print("Average Happiness Score: ",scoreData[i][0]) print("Number of Keyword Tweets: ",scoreData[i][1]) print("Number of Tweets: ",scoreData[i][2]) print("") print("")
from sentiment_analysis import compute_tweets # Imports the function from the sentiment_analysis file done = False # Defines done as false while not done: # Loop runs as long as done is false try: print() keywords = input( "Please enter the name of the file containing keywords" ) # Prompts user for keyword file tweets = input("Please enter the name of the file containing tweets" ) # Prompts user for tweets file results = compute_tweets( tweets, keywords) # Calls the compute_tweets function to get results print("** Sentiment analysis complete! **") # End statement is printed print(results) # Results are printed print() done = True # Makes done become true and exits the while loop # This segment handles various errors with the use of exceptions except IOError: print( "TWEET COUNT ZERO: One or more files were not found. Empty list returned, please try again." ) except ValueError: print("TWEET COUNT ZERO: file contents invalid, please try again.") except ZeroDivisionError:
from sentiment_analysis import compute_tweets #Asking the user to input which files they would like to use tweets = str(input("Which tweet list do you want?")) keylist = str(input("Which keylist do you want?")) #If the name they entered does not contain .txt then you would add it for them if ".txt" not in tweets: tweets = tweets + ".txt" if ".txt" not in keylist: keylist = keylist + ".txt" #Creating the list of timezones and computing it for all of them #Output each item in the list and what they are mass_list = compute_tweets(tweets, keylist) for n in range(len(mass_list)): if n == 0: print("Eastern time: ") print("Happiness Score:", mass_list[n][0]) print("Number of keyword tweets", mass_list[n][1]) print("Number of tweets", mass_list[n][2]) if n == 1: print("Central time: ") print("Happiness Score:", mass_list[n][0]) print("Number of keyword tweets", mass_list[n][1]) print("Number of tweets", mass_list[n][2]) if n == 2: print("Mountain time: ") print("Happiness Score:", mass_list[n][0]) print("Number of keyword tweets", mass_list[n][1]) print("Number of tweets", mass_list[n][2]) if n == 3:
# # # from sentiment_analysis import compute_tweets # ask for user input to determine analysis fileName = input("Enter the name of your file: ") keyword_fileName = input("Enter the name of your keywords list file: ") file_analysis = compute_tweets(fileName, keyword_fileName) # printing readable version of data to 3 decimals for each region print("\nEastern Data") print("Average happiness: %.3f" % file_analysis[0][0]) print("Number of key tweets: ", file_analysis[0][1]) print("Number of Eastern tweets: ", file_analysis[0][2]) print() print("Central Data") print("Average happiness: %.3f " % file_analysis[1][0]) print("Number of key tweets: ", file_analysis[1][1]) print("Number of Eastern tweets: ", file_analysis[1][2]) print() print("Mountain Data") print("Average happiness: %.3f" % file_analysis[2][0]) print("Number of key tweets: ", file_analysis[2][1]) print("Number of Eastern tweets: ", file_analysis[2][2]) print() print("Pacific Data")
## # Name: Abdalla Abdelhady # Student Number: 250856115 # This module defines a functions that takes two files, one with tweets and one with keywords and sentiment values, #and calculates an average sentiment value for each timezone in continental United States # #This part imports the module with the function that calculates sentiment values import sentiment_analysis #This part asks the user for the names of the files tfile = input("What is the name of the file with tweets? ") kfile = input("What is the name of the file with keywords? ") finalvalues = sentiment_analysis.compute_tweets(tfile, kfile) #This part outputs the results from the function in a format the user can read print( "The (happiness_score, number_of_keyword_tweets, number_of_tweets) in the eastern, central, mountain and pacific regions respectively are as shown below:\n", finalvalues)
# Nov 14 2018 # Filip Durca # This program asks the user for the name of the files containing the tweets and the keywords, and then outputs the results from each timezone #imports import sentiment_analysis #Variables timezones = ["Eastern", "Central", "Mountain", "Pacific"] #Ask the user for the file names tweetFile = input("What file are the tweets located in? ") keywordFile = input("What file are the keywords located in? ") #Get the results results = sentiment_analysis.compute_tweets(tweetFile, keywordFile) #Print the results only if file is found if len(results) > 0: for i in range(4): print("Timezone:", timezones[i]) print("Average:", results[i][0], " Number of tweets:", results[i][1])
""" Name: Jessica Yang Program: Assignment 3, Sentiment Analysis Program Description: analyzes twitter data and sentiment values """ import sentiment_analysis as s # prompts user for tweet and key word list tweet = input("Which tweet? ") keyword = input("Which keyword list? ") # calculates the scores from the given tweet and keywords master_list = s.compute_tweets(tweet, keyword) # print statements for empty master list if master_list == (0, 0, 0, 0): for x in range(4): if x == 0: print("Eastern") if x == 1: print("Central") if x == 2: print("Mountain") if x == 3: print("Pacific") for y in range(3): if y == 0: print("Happiness Score: ", "0") if y == 1:
from sentiment_analysis import compute_tweets tweets = input("Please enter the name of the tweets file") poskey = input("Please enter the name of the positive keywords file") negkey = input("Please enter the name of the negative keywords file") results = compute_tweets( tweets, poskey, negkey) #calling the compute function to find the results for each region print("Total positive tweets is ", results[0], "and total negative tweets is ", results[1], "out of ", results[2], "total tweets") print("The overall score is ", results[3])
from sentiment_analysis import compute_tweets # My name is Connor Haines, and this is my sentiment analysis assignment. # This software uses a combination of files and functions, to calculate the average # sentiment per tweet in specific timezones. The program refers to files full of # tweets and keywords which are inputted by the user. finalList = [] # Getting user to input file names. tfilename = input("Enter the name of a tweets file: ") kfilename = input("Enter the name of a keywords file: ") # Executing "compute_tweets" function. finalList = compute_tweets(tfilename, kfilename) # Finally outputting values in a readable fashion. print("") print("----------(Average Sentiment, Number of Tweets)----------") print("") if len(finalList) > 1: print("Eastern Timezone: ", finalList[0]) print("Central Timezone: ", finalList[1]) print("Mountain Timezone: ", finalList[2]) print("Pacific Timezone: ", finalList[3]) # Checking if empty list was returned and outputting a message. else: print("Empty list returned. Invalid file name(s).")
from sentiment_analysis import compute_tweets tweets = input("Please enter the name of the tweets file") keywords = input("Please enter the name of the keywords file") results = compute_tweets( tweets, keywords ) #calling the compute function to find the results for each region #printing out the results in a readable form if results != []: print("EASTERN:", "\nHappiness Score: ", results[0][0], "\nNumber of Tweets in Timezone: ", results[0][1], "\nTotal Number of Tweets in Timezone: ", results[0][2], "\n") print("CENTRAL:", "\nHappiness Score: ", results[1][0], "\nNumber of Tweets in Timezone: ", results[1][1], "\nTotal Number of Tweets in Timezone: ", results[1][2], "\n") print("MOUNTAIN:", "\nHappiness Score: ", results[2][0], "\nNumber of Tweets in Timezone: ", results[2][1], "\nTotal Number of Tweets in Timezone: ", results[2][2], "\n") print("PACIFIC:", "\nHappiness Score: ", results[3][0], "\nNumber of Tweets in Timezone: ", results[3][1], "\nTotal Number of Tweets in Timezone: ", results[3][2]) else: print("EASTERN:", "\nHappiness Score: 0", "\nNumber of Tweets in Timezone: 0", "\nTotal Number of Tweets in Timezone: 0", "\n") print("CENTRAL:", "\nHappiness Score: 0", "\nNumber of Tweets in Timezone: 0", "\nTotal Number of Tweets in Timezone: 0", "\n") print("MOUNTAIN:", "\nHappiness Score: 0", "\nNumber of Tweets in Timezone: 0",
# imports from sentiment_analysis import compute_tweets # asking for user input tweets = input("Please enter the file name for the tweets: ") keywords = input("Please enter the file name for the keywords: ") # setting variable and using compute_tweets function tupleList = compute_tweets(tweets, keywords) # checks to see if the output was a [], if so that means the keywords file did not exist if tupleList != []: # formatting output print("\nEASTERN:\nAverage happiness score:", tupleList[0][0], "\nTotal number of keyword tweets:", tupleList[0][1], "\nTotal number of tweets is:", tupleList[0][2]) print("\nCENTRAL:\nAverage happiness score:", tupleList[1][0], "\nTotal number of keyword tweets:", tupleList[1][1], "\nTotal number of tweets is:", tupleList[1][2]) print("\nMOUNTAIN:\nAverage happiness score:", tupleList[2][0], "\nTotal number of keyword tweets:", tupleList[2][1], "\nTotal number of tweets is:", tupleList[2][2]) print("\nPACIFIC:\nAverage happiness score:", tupleList[3][0], "\nTotal number of keyword tweets:", tupleList[3][1], "\nTotal number of tweets is:", tupleList[3][2]) else: print(tupleList)
from sentiment_analysis import compute_tweets from sentiment_analysis import printer fileName = input("Please enter a tweets file: ") keyName = input("Please enter a key: ") finalAnswer = compute_tweets(fileName, keyName) finalAnswer = list(finalAnswer) for i in range(0, len(finalAnswer)): finalAnswer[i] = list(finalAnswer[i]) try: Eastern = finalAnswer[0] Eastern.append("Eastern") Central = finalAnswer[1] Central.append("Central") Mountain = finalAnswer[2] Mountain.append("Mountain") Pacific = finalAnswer[3] Pacific.append("Pacific") print(" ") print("SENTIMENT VALUE RESULTS:") print(" ") printer(Eastern) printer(Central) printer(Mountain) printer(Pacific) except IndexError: print(finalAnswer)
from sentiment_analysis import compute_tweets #importing the necessary function from the sentiment_analysis module userFile = input("Enter the name of the file with the tweets: ") #taking user input userKey = input("Enter the name of the file with keywords: ") output = compute_tweets(userFile, userKey) #using the compute_tweets function to output the results after file processing def formatOutput(output): #this function outputs the values for the user print("Happiness Value: ", round(output[0],3)) #rounding the happiness value in a region to 3 digits print("Tweet with Keywords: ", output[1]) print("Total Number of Tweets: ", output[2]) if len(output) > 0: #prints the output if the list contains anything (so that if an exception is generated the empty list doesn't get formatted) print("\nEASTERN: ") formatOutput(output[0]) print("\nCENTRAL: ") formatOutput(output[1]) print("\nMOUNTAIN: ") formatOutput(output[2]) print("\nPACIFIC: ") formatOutput(output[3]) else: print(output)
from sentiment_analysis import compute_tweets TWEET_FILE=input('Please enter the name of the tweet file: ') KEYWORD_FILE=input('Please enter the name of the keyword file: ') print('') x=compute_tweets(TWEET_FILE,KEYWORD_FILE) #try is used so if the wrong file is entered then it would simply ask to input a right file try: #int(x[0][1]) #this is used to compare the regions happiness score and find out which region is the happiest if x[0][0]>x[1][0] and x[0][0]>x[2][0] and x[0][0]>x[3][0]: print('The Eastern Time Zone is the happiest region') elif x[1][0]>x[0][0] and x[1][0]>x[2][0] and x[1][0]>x[3][0]: print('The Central Time Zone is the happiest region') elif x[2][0]>x[0][0] and x[2][0]>x[1][0] and x[2][0]>x[3][0]: print('The Mountain Time Zone is the happiest region') elif x[3][0]>x[0][0] and x[3][0]>x[1][0] and x[3][0]>x[2][0]: print('The Pacific Time Zone is the happiest region') #print statments for the happiness value, keyword tweets & total number of tweets for all regions print('') print('The happiness value for the EASTERN TIME ZONE is : ', x[0][0]) print('The total number of key word tweets for the EASTERN TIME ZONE is: ',x[0][1]) print('The total number of tweets for EASTERN TIME ZONE is: ',x[0][2]) print('') print('The happiness value for the CENTRAL TIME ZONE is : ',x[1][0]) print('The total number of key word tweets for the CENTRAL TIME ZONE is: ',x[1][1]) print('The total number of tweets for CENTRAL TIME ZONE is: ',x[1][2]) print('') print('The happiness value for the MOUNTAIN TIME ZONE is : ',x[2][0])
#Assignment 3: Sentiment Analysis #Andrea Lee 250836721 import sentiment_analysis input_tweet = input( 'Enter tweet file name:\n') #prompt user for tweet file name input_keyword = input( 'Enter keyword file name:\n') #prompt user for keyword file name scores = sentiment_analysis.compute_tweets( input_tweet, input_keyword ) #call compute_tweets function from sentiment_analysis module to get happiness scores and number of counted tweets for each region #print output print() if len(scores) == 0: #blank list is returned if invalid file name print('File name does not exist.' ) #if blank list is returned, print file name does not exist) else: eastern_score = scores[0] eastern_happiness_score = eastern_score[0] eastern_counted_tweet = eastern_score[1] central_score = scores[1] central_happiness_score = central_score[0] central_counted_tweet = central_score[1]
# Name: Carrie Lu # Date: November 18, 2020 # Description: This program performs a simple sentiment analysis on Twitter data and # determines the happiness score, number of tweets, and total number of tweets in each timezone (Eastern, Central, Mountain, Pacific). from sentiment_analysis import compute_tweets # Prompt user to enter the name of the file containing the tweets and the file containing the keywords user_file = input('Enter name of file with tweets:') user_keywords_file = input('Enter file name of file with keywords:') results = compute_tweets(user_file, user_keywords_file) # Output the results in a readable form if results != []: print("EASTERN:", "\nHappiness Score: ", results[0][0], "\nNumber of Tweets in Timezone: ", results[0][1], "\nTotal Number of Tweets in Timezone: ", results[0][2], "\n") print("CENTRAL:", "\nHappiness Score: ", results[1][0], "\nNumber of Tweets in Timezone: ", results[1][1], "\nTotal Number of Tweets in Timezone: ", results[1][2], "\n") print("MOUNTAIN:", "\nHappiness Score: ", results[2][0], "\nNumber of Tweets in Timezone: ", results[2][1], "\nTotal Number of Tweets in Timezone: ", results[2][2], "\n") print("PACIFIC:", "\nHappiness Score: ", results[3][0], "\nNumber of Tweets in Timezone: ", results[3][1], "\nTotal Number of Tweets in Timezone: ", results[3][2]) else: print("EASTERN:", "\nHappiness Score: 0", "\nNumber of Tweets in Timezone: 0", "\nTotal Number of Tweets in Timezone: 0", "\n") print("CENTRAL:", "\nHappiness Score: 0", "\nNumber of Tweets in Timezone: 0", "\nTotal Number of Tweets in Timezone: 0", "\n") print("MOUNTAIN:", "\nHappiness Score: 0", "\nNumber of Tweets in Timezone: 0", "\nTotal Number of Tweets in Timezone: 0", "\n") print("PACIFIC:", "\nHappiness Score: 0", "\nNumber of Tweets in Timezone: 0", "\nTotal Number of Tweets in Timezone: 0")
# import the tweeting computing function from the sentiment analysis module created from sentiment_analysis import compute_tweets # This will be used to loop the input requests # If an invalid file name is entered valid = True print("Hello!") # Request the keyword and tweet file tweets = input("Please enter the name of the file containing the tweets:") key = input("Please enter the name of the file containing the key words:") print("Thank you! Now I will be able to process the tweets.\n") # Use the function to process the tweets' average sentiment and counted tweet values by region results = compute_tweets(tweets, key) # Until an invalid file is entered while valid: # Split the tuples of the happiness average and counted tweets if they exist try: eastResult = str(results[0]).split(",") centralResult = str(results[1]).split(",") mountainResult = str(results[2]).split(",") pacificResult = str(results[3]).split(",") # Display calculated results print("\nIn the Eastern region, the happiness average is,", eastResult[0].replace("(", ""), "with", eastResult[1].replace(")", ""), "counted tweets.")
from sentiment_analysis import compute_tweets #importing function #if a user enters a correct file validFile = False while not validFile: try: #prompting the user to input desired files tweets = input("Please enter a file containing tweets: ") keywords = input("Please enter a file containing keywords: ") output = (compute_tweets(tweets, keywords)) #calling the function #printing the results for each region print("\nFor the Eastern timezone, the average score of happiness is:", output[0][0]) print("There were", output[0][1], "tweets counted. \n") print("For the Central timezone, the average score of happiness is:", output[1][0]) print("There were", output[1][1], "tweets counted. \n") print("For the Mountain timezone, the average score of happiness is:", output[2][0]) print("There were", output[2][1], "tweets counted. \n") print("For the Pacific timezone, the average score of happiness is:", output[3][0]) print("There were", output[3][1], "tweets counted. \n") #determining and printing which region is the happiest if output[0][0] > output[1][0] and output[0][0] > output[2][ 0] and output[0][0] > output[3][0]: print("The Eastern region is the happiest :D")
# # Import compute_tweets function from "sentiment_analysis' module from sentiment_analysis import compute_tweets from string import punctuation # Prompt user for the names of their tweet and keyword files tweets = input("Enter tweet file: ") keywords = input("Enter keyword file: ") # Call the compute_tweets function with tweet and keyword files as parameters result = compute_tweets(tweets, keywords) print(result, "\n") # Print results in readable format if result != []: print("Eastern Region: ") print(" Happiness score: ", result[0][0]) print(" Number of keyword tweets: ", result[0][1]) print(" Total number of tweets: ", result[0][2], "\n") print("Central Region: ") print(" Happiness score: ", result[1][0]) print(" Number of keyword tweets: ", result[1][1]) print(" Total number of tweets: ", result[1][2], "\n") print("Mountain Region: ") print(" Happiness score: ", result[2][0]) print(" Number of keyword tweets: ", result[2][1]) print(" Total number of tweets: ", result[2][2], "\n")
# # Driver for testing ... tests combinations of test files by calling call compute_tweets # from sentiment_analysis import compute_tweets print() print("** Test 1") results = compute_tweets("tweets.txt", "keywords.txt") print(results) print() print() print("** Test 2") results = compute_tweets("tweets1.txt", "key2.txt") print(results) print() print() print("** Test 3") results = compute_tweets("tweets2.txt", "key1.txt") print(results) print() print() print("** Test 4") results = compute_tweets("tweets2.txt", "key2.txt") print(results) print()
from sentiment_analysis import compute_tweets tweetData = input("Enter the name of the file containing tweets: ") keyData = input("Enter the name of the file containing Keywords: ") results = compute_tweets(tweetData,keyData) print("****************************************************") print("Eastern:") print("Average Happiness: {:.2f}".format(results[0][0])) print("Number of Keyword Tweets: {}".format(results[0][1])) print("Number of Tweets: {}".format(results[0][2])) print("****************************************************") print("Central:") print("Average Happiness: {:.2f}".format(results[1][0])) print("Number of Keyword Tweets: {}".format(results[1][1])) print("Number of Tweets: {}".format(results[1][2])) print("****************************************************") print("Mountain:") print("Average Happiness: {:.2f}".format(results[2][0])) print("Number of Keyword Tweets: {}".format(results[2][1])) print("Number of Tweets: {}".format(results[2][2])) print("****************************************************") print("Pacific:") print("Average Happiness: {:.2f}".format(results[3][0])) print("Number of Keyword Tweets: {}".format(results[3][1])) print("Number of Tweets: {}".format(results[3][2])) print("****************************************************")