def convert_tweets_to_csv(): file_names = listdir("output") csv_file_names = listdir("output_csv") for file_name in file_names: if not Utils.is_text_file(file_name) or is_already_converted(file_name, csv_file_names): continue day_tweet = None with open("./output/" + file_name, "r", encoding="utf-8") as file: day_tweet = DayTweets.read_from_file(Party.get_from(file_name), file) csv_name = file_name[:-4] + ".csv" with open("./output_csv/" + csv_name, "w", encoding="utf-8") as csv_file: csv_writer = csv.writer(csv_file) for tweet in day_tweet.tweets: csv_writer.writerow([tweet.raw_tweet])
def generate_summary(self): total_tweets = 0 total_words = 0 token_list = [] file_names = listdir('output') days_tweets = [] for file_name in file_names: if not Utils.is_text_file(file_name): continue with open("./output/" + file_name, "r", encoding="utf-8") as file: days_tweets.append( DayTweets.read_from_file(Party.get_from(file_name), file)) for day_tweets in days_tweets: total_tweets += day_tweets.total_tweets total_words += day_tweets.total_words token_list += day_tweets.tokens print("Resumen") print("Total tweets: " + str(total_tweets)) print("Total words: " + str(total_words)) print("Total tokens: " + str(len(list(dict.fromkeys(token_list))))) print() for party in Party: party_tweets = 0 party_words = 0 party_token_list = [] for day_tweets in days_tweets: if day_tweets.party == party: party_tweets += day_tweets.total_tweets party_words += day_tweets.total_words party_token_list += day_tweets.tokens print(party.get_full_name()) print("Total tweets: " + str(party_tweets)) print("Total words: " + str(party_words)) print("Total tokens: " + str(len(list(dict.fromkeys(party_token_list))))) print()