def test_calculate_sentiment(): """ tests calculate_tweet_sentiment """ tweet_dic = ts.create_sentiment_dictionary(open('AFINN-111.txt')) tweet_list = ts.parse_tweets(open('problem_1_submission.txt')) for tweet in tweet_list: print(ts.calculate_tweet_sentiment(tweet, tweet_dic))
def result(): if 'username' not in session: return render_template('login.jsp') option = session['option'] n = session['topn'] if option == 1: headers = ['HashTag', 'Frequency'] results = top_tags.calculate_top_tags(session['tweet_count'], n) if not results: return redirect(url_for('result')) else: return render_template('result.jsp', results=results, headers=headers) elif option == 2: headers = ['Word', 'Frequency'] results = top_terms.calculate_term_frequency(session['tweet_count'], n) if not results: return redirect(url_for('result')) else: return render_template('result.jsp', results=results, headers=headers) elif option == 3: headers = ['Tweet', 'Score'] results = tweet_sentiment.calculate_tweet_sentiment('resources/AFINN-111.txt', session['tweet_count'], n, 1) if not results: return redirect(url_for('result')) else: resp = make_response(render_template('result.jsp', results=results, headers=headers)) resp.headers['Content-Type'] = 'text/html; charset=utf-8' return resp elif option == 4: headers = ['Tweet', 'Score'] results = tweet_sentiment.calculate_tweet_sentiment('resources/AFINN-111.txt', session['tweet_count'], n, -1) if not results: return redirect(url_for('result')) else: return render_template('result.jsp', results=results, headers=headers) elif option == 5: headers = ['State Code', 'State Name', 'Tweets', 'Score'] results = happiest_state.get_state_happiness('resources/AFINN-111.txt', session['tweet_count']) if not results: return redirect(url_for('result')) else: return render_template('result.jsp', results=results, headers=headers)