yiff_toolkit / scripts /tag_frequency.py
k4d3's picture
awoo
d83cc4e
raw
history blame
No virus
1.08 kB
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)