From 6bddcfb238c5acd50f8e5d9bf5eda35a0d50e31d Mon Sep 17 00:00:00 2001 From: Tristan Lee Date: Fri, 6 May 2022 02:56:38 -0500 Subject: [PATCH] modified formatting of print_occurrences function --- tiktok_downloader/hashtag_frequencies.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tiktok_downloader/hashtag_frequencies.py b/tiktok_downloader/hashtag_frequencies.py index 14d55ea..cf55a5b 100644 --- a/tiktok_downloader/hashtag_frequencies.py +++ b/tiktok_downloader/hashtag_frequencies.py @@ -79,7 +79,7 @@ def get_occurrences(filename: str, n: int = 1) -> Dict[str, Any]: return occs -def plot(n: int, occs: dict, img_folder: str): +def plot(occs: dict, img_folder: str): """Save plot of common hashtags as bar chart to file.""" y_pos = list(reversed(range(len(occs["top_n"][0]) - 1))) max_count = occs["top_n"][1][0] @@ -113,13 +113,13 @@ def print_occurrences(occs): row_number = 0 total_posts = occs["total"] print( - "{:<8} {:<15} {:<15} {:<15}".format( + "{:<8} {:<30} {:<15} {:<15}".format( "Rank", "Hashtag", "Occurrences", "Frequency" ) ) for key, value in zip(occs["top_n"][0], occs["top_n"][1]): ratio = value / total_posts - print("{:<8} {:<15} {:<15} {:<15}".format(row_number, key, value, ratio)) + print("{:<8} {:<30} {:<15} {:.4f}".format(row_number, key, value, ratio)) row_number += 1 @@ -145,6 +145,6 @@ if __name__ == "__main__": path = f"./{base}_sorted_hashtags.csv" occs = get_occurrences(input_file, args.n) if args.plot: - plot(args.n, occs, img_folder) + plot(occs, img_folder) else: print_occurrences(occs)