import json import sys from collections import Counter from rich.table import Table from rich import print def tally_tags(json_files): tag_counts = Counter() for file in json_files: with open(file, 'r', encoding='utf-8') as f: # specify the encoding here data = json.load(f) tag_freq = data.get('ss_tag_frequency', {}) for tags in tag_freq.values(): tag_counts.update(tags) return tag_counts def print_tag_table(tag_counts): table = Table(show_header=True, header_style="bold magenta") table.add_column("Tag", style="dim", width=30) table.add_column("Count", justify="right") sorted_tags = sorted(tag_counts.items(), key=lambda x: x[1], reverse=True) for tag, count in sorted_tags: table.add_row(tag, str(count)) print(table) if __name__ == '__main__': if len(sys.argv) < 2: print("Usage: python script.py ...") sys.exit(1) json_files = sys.argv[1:] tag_counts = tally_tags(json_files) print_tag_table(tag_counts)