Skip to content

Instantly share code, notes, and snippets.

@puhitaku
Created March 14, 2023 15:46
Show Gist options
  • Save puhitaku/8ef8fb64bcc87c51dee32e70c985d7d9 to your computer and use it in GitHub Desktop.
Save puhitaku/8ef8fb64bcc87c51dee32e70c985d7d9 to your computer and use it in GitHub Desktop.
Slack Archive Emoji Counter
"""
Slack Archive Emoji Counter
Copyright (c) 2023 Takumi Sueda (puhitaku@gmail.com)
SPDX-License-Identifier: MIT
Put this script by the channel directories and run it.
"""
import json
import sys
from pathlib import Path
emoji_counts = dict()
def count(fn):
with open(fn, 'r', encoding='utf-8') as f:
j = json.load(f)
for message in j:
if 'reactions' in message:
for reaction in message['reactions']:
emoji = reaction['name']
count = reaction['count']
emoji_counts[emoji] = emoji_counts.get(emoji, 0) + count
for fn in Path('.').glob('**/*.json'):
print(fn, file=sys.stderr)
count(fn)
for emoji, count in sorted(emoji_counts.items(), key=lambda x: x[1], reverse=True):
print(emoji, count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment