def get(self): global query_cron_1 query_cron_1 = ["obama", "romney", "zardari", "imran khan", "pakistan", "star wars", "lord of the rings", "appl", "xbox", "ps3"] for index in range(1,len(query_cron_1)+1): query = query_cron_1[index-1] ############# NOTE: CURRENTLY TWEETSTATS IS TURNED OFF. TO TURN IT BACK ON UNCOMMMENT THE LINE BELOW AND COMMENT THE LINE BELOW THAT! ############## # [list_tweets, total_results, time_search] = algorithm.getpasttweets(query) list_tweets = []; if list_tweets == -1 or list_tweets == -2 or list_tweets == -3 or list_tweets == -4 or list_tweets == []: pass else: list_tweets_5 = algorithm.tweetformat(list_tweets) features = algorithm.getfeatures(list_tweets, list_tweets_5) [features_final, list_labels, num_labels] = algorithm.classification(features) popularity_score = algorithm.popularityscore(num_labels, total_results, time_search) popularity_score = int(float(popularity_score)) phrase = "PastDataH" + str(index) + "(score = popularity_score)" data = eval(phrase) data.put()
def post(self): query = self.request.get("query_1") if query == "": self.render('TweetScoreMain.html', error='Please enter a valid query', query=query) else: [list_tweets, total_results, time_search] = algorithm.getpasttweets(query) if list_tweets == -1: self.redirect('/error') elif list_tweets == -2 or list_tweets == []: self.render('TweetScoreMain.html', error='Too many requests. We apologize but this is a free service and rate limited by Twitter API (which has exceeded). Please try again in 5 minutes.') elif list_tweets == -3: self.render('TweetScoreMain.html', error='Unknown Error occured please try again, we apologize for inconvenience') elif list_tweets == -4: self.render('TweetScoreMain.html', error='Not enough results for your search query. Please try another query.') else: list_tweets_5 = algorithm.tweetformat(list_tweets) features = algorithm.getfeatures(list_tweets, list_tweets_5) [features_final, list_labels, num_labels] = algorithm.classification(features) [list_tweets_positive, list_tweets_negative, list_tweets_neutral] = algorithm.selecttweets(list_tweets, list_labels, features_final, num_labels) popularity_score = algorithm.popularityscore(num_labels, total_results, time_search) popularity_score_float = float(popularity_score) plotdata = [['Objectivity Score', 'Positive', 'Negative', 'Neutral']] for i in range(0,len(list_labels)): obj_score = features_final[i][0] subj_score = features_final[i][1] if list_labels[i] == "1": plotdata.append([obj_score, subj_score, None, None]) elif list_labels[i] == "-1": plotdata.append([obj_score, None, subj_score, None]) elif list_labels[i] == "0": plotdata.append([obj_score, None, None, subj_score]) self.render('graph_tweetscore_1.html', pos=num_labels[0], neg=num_labels[1], neu=num_labels[2], plotdata=json.dumps(plotdata)) self.render('TweetScoreResult.html', query=query, score=popularity_score, score_float=popularity_score_float, tweets_pos=list_tweets_positive, tweets_neg=list_tweets_negative, tweets_neu=list_tweets_neutral)
def post(self): query_1 = self.request.get("query_2") query_2 = self.request.get("query_3") query_3 = self.request.get("query_4") cont = False # for blocking some computations if some error while fetching tweets if (query_1 == "" and query_2 == "") or (query_2 == "" and query_3 == "") or (query_1 == "" and query_3 == ""): self.render('TweetComparisonMain.html', error="Enter Atleast 2 valid queries for comparison", query_1=query_1, query_2=query_2, query_3=query_3) else: popularity_score_overall = [] popularity_score_overall_float = [] num_labels_overall = [] num_tweets_overall = [] total_results_overall = [] query_list = [query_1, query_2, query_3] if "" in query_list: query_list.remove("") for index_query in range(0,len(query_list)): query = query_list[index_query] [list_tweets, total_results, time_search] = algorithm.getpasttweets(query) if list_tweets == -1: cont = false self.redirect('/error') elif list_tweets == -2 or list_tweets == []: self.render('TweetComparisonMain.html', error='Too many requests. We apologize but this is a free service and rate limited by Twitter API (which has exceeded). Please try again in 5 minutes.') elif list_tweets == -3: self.render('TweetComparisonMain.html', error='Unknown Error occured please try again, we apologize for inconvenience') elif list_tweets == -4: self.render('TweetComparisonMain.html', error='Not enough results for your search query: <b>%s</b>. Please try another query' %query, query_1=query_1, query_2=query_2, query_3=query_3) else: list_tweets_5 = algorithm.tweetformat(list_tweets) features = algorithm.getfeatures(list_tweets, list_tweets_5) [features_final, list_labels, num_labels] = algorithm.classification(features) popularity_score = algorithm.popularityscore(num_labels, total_results, time_search) popularity_score_overall_float.append(float(popularity_score)) popularity_score_overall.append(popularity_score) num_labels_overall.append(num_labels) num_tweets_overall.append(len(list_tweets)) total_results_overall.append(total_results) cont = True # self.write("query: <b>%s</b>. Time: <b>%s</b> minutes<br>" %(query, time_search)) if cont == True: max_index = popularity_score_overall_float.index(max(popularity_score_overall_float)) max_query = query_list[max_index] self.render('graph_tweetcomparison_1.html', pos=num_labels_overall[0][0], neg=num_labels_overall[0][1], neu=num_labels_overall[0][2], query=query_list[0]) self.render('graph_tweetcomparison_2.html', pos=num_labels_overall[1][0], neg=num_labels_overall[1][1], neu=num_labels_overall[1][2], query=query_list[1]) if len(num_labels_overall) == 3: self.render('graph_tweetcomparison_3.html', pos=num_labels_overall[2][0], neg=num_labels_overall[2][1], neu=num_labels_overall[2][2], query=query_list[2]) self.render('TweetComparisonResult.html', max_query=max_query, query_1=query_list[0], query_2=query_list[1], query_3=query_list[2], score_1=popularity_score_overall[0], score_2=popularity_score_overall[1], score_3=popularity_score_overall[2], score_1_float=popularity_score_overall_float[0], score_2_float=popularity_score_overall_float[1], score_3_float=popularity_score_overall_float[2]) else: self.render('TweetComparisonResult.html', max_query=max_query, query_1=query_list[0], query_2=query_list[1], query_3="", score_1=popularity_score_overall[0], score_2=popularity_score_overall[1], score_3="", score_1_float=popularity_score_overall_float[0], score_2_float=popularity_score_overall_float[1], score_3_float="")