awoo
Browse filesSigned-off-by: Balazs Horvath <[email protected]>
- scripts/tag_frequency.py +35 -0
scripts/tag_frequency.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import sys
|
3 |
+
from collections import Counter
|
4 |
+
from rich.table import Table
|
5 |
+
from rich import print
|
6 |
+
|
7 |
+
def tally_tags(json_files):
|
8 |
+
tag_counts = Counter()
|
9 |
+
for file in json_files:
|
10 |
+
with open(file, 'r', encoding='utf-8') as f: # specify the encoding here
|
11 |
+
data = json.load(f)
|
12 |
+
tag_freq = data.get('ss_tag_frequency', {})
|
13 |
+
for tags in tag_freq.values():
|
14 |
+
tag_counts.update(tags)
|
15 |
+
return tag_counts
|
16 |
+
|
17 |
+
def print_tag_table(tag_counts):
|
18 |
+
table = Table(show_header=True, header_style="bold magenta")
|
19 |
+
table.add_column("Tag", style="dim", width=30)
|
20 |
+
table.add_column("Count", justify="right")
|
21 |
+
|
22 |
+
sorted_tags = sorted(tag_counts.items(), key=lambda x: x[1], reverse=True)
|
23 |
+
for tag, count in sorted_tags:
|
24 |
+
table.add_row(tag, str(count))
|
25 |
+
|
26 |
+
print(table)
|
27 |
+
|
28 |
+
if __name__ == '__main__':
|
29 |
+
if len(sys.argv) < 2:
|
30 |
+
print("Usage: python script.py <json_file1> <json_file2> ...")
|
31 |
+
sys.exit(1)
|
32 |
+
|
33 |
+
json_files = sys.argv[1:]
|
34 |
+
tag_counts = tally_tags(json_files)
|
35 |
+
print_tag_table(tag_counts)
|