def main(): tweets = twt.make_tweets(raw_input('Enter tweet file name: ')) filename = raw_input('Please enter the file name where you want to '\ + 'write this information: ') twt.write_tweets(tweets, filename) print 'Making sentiment dictionary for you...' sentiment = twt.make_sentiments(raw_input('enter sentiments file name: ')) print 'Please be patient,adding sentiment values to ',filename, ' ...' names = twt.read_add_sentiments(filename, sentiment) print 'Enter a file name where you want the tweets with sentiments' file_out = raw_input('Enter the name of the output file: ') twt.write_filtered_tweets(names, file_out) print'The avg sentiment for this file is' print twt.avg_sentiment(names)
def main(): """Tests tweet sentiment compiler code in tweets.py""" print("\nParsing file and creating tweet dictionaries...") # inFile = some_tweets tweets = t.make_tweet(some_tweets) # list of tweet dictionaries that include avg sentiment # DOES NOT CREATE NEW LIST OF TWEET DICTIONARIES print("Adding sentiments...\n") t.add_sentiment(tweets, sentiment_file) # call function to create file of tweets with sentiments file = t.pass_tweets(tweets) # new list of rebuilt tweet dictionaries print("Rebuilding tweets...") new_tweets = t.rebuild_tweets(created_tweets) # verify successful rebuilding if new_tweets == tweets: print(file + "\n") # filters list of tweets according to desired word inputs filter_tweets = t.tweet_filter(tweets, *args) # !!!-UNCOMMENT TO SEE FILTERED TWEETS-!!! # pp.pprint([tweet["text"] for tweet in filter_tweets]) # returns average sentiment of filtered list of tweets avg_sentiment = t.avg_sentiment(filter_tweets) if avg_sentiment != None: print("The average sentiment for tweets with these filtered words is: " "%s." % avg_sentiment) else: print("The tweets with these filtered words either have no sentiment " "or don't exist.")