<commit_before>from slacker import Slacker

from optparse import OptionParser
from collections import defaultdict
import json

parser = OptionParser()
parser.add_option("-t", "--token", dest="token", help="your slack token")

(options, args) = parser.parse_args()

slack = Slacker(options.token)

response = slack.channels.list()

channel_members = dict()

for channel in response.body["channels"]:
    name = channel["name"]
    created = channel["created"]
    print("%s: %d" % (name, created))<commit_msg>extract age of newest message<commit_after>from slacker import Slacker

from optparse import OptionParser
from collections import defaultdict
import json

parser = OptionParser()
parser.add_option("-t", "--token", dest="token", help="your slack token")

(options, args) = parser.parse_args()

slack = Slacker(options.token)

response = slack.channels.list()

channel_members = dict()

def newest_message(messages):
    text_messages = [m for m in messages if m["type"] == "message" and "subtype" not in m]
    by_ts = sorted(text_messages, key=lambda m : m["ts"], reverse=True)
    if len(by_ts) > 0:
        return by_ts[0]
    else:
        return None

for channel in response.body["channels"]:
    name = channel["name"]
    id = channel["id"]
    history = slack.channels.history(id)
    created = channel["created"]
    newest = newest_message(history.body["messages"])
    if newest is not None:
        print("%s: %d -> %s: %s" % (name, created, newest["ts"], newest["text"]))
{'fraction_non_alphanumeric': 0.14142091152815014, 'fraction_numerical': 0.0013404825737265416, 'mean_word_length': 4.488970588235294, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1573120', 'n_tokens_mistral': 455, 'n_tokens_neox': 451, 'n_words': 134}