File size: 1,083 Bytes
d83cc4e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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 <json_file1> <json_file2> ...")
        sys.exit(1)

    json_files = sys.argv[1:]
    tag_counts = tally_tags(json_files)
    print_tag_table(tag_counts)