about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-08-10 04:44:43 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-08-10 04:44:43 -0700
commit5456a1edcb9716bede78309fb76da3763ba54cd4 (patch)
treec7b718e98b48cf4eb08988fd0defffa20f353110
parent98b11ea64566199698991bf58e1037f4711e2e88 (diff)
downloadmu-5456a1edcb9716bede78309fb76da3763ba54cd4.tar.gz
.
-rw-r--r--browse_slack/convert_slack.py38
1 files changed, 16 insertions, 22 deletions
diff --git a/browse_slack/convert_slack.py b/browse_slack/convert_slack.py
index 460c4a31..a601c9d9 100644
--- a/browse_slack/convert_slack.py
+++ b/browse_slack/convert_slack.py
@@ -49,28 +49,22 @@ with open('users.json') as f:
 
 items = []
 
-def contents(filename):
-    with open(filename) as f:
-        for item in json.load(f):
-            try:
-                if 'thread_ts' in item:
-                    # comment
-                    yield {
-                      'name': f"/{item['thread_ts']}/{item['ts']}",
-                      'contents': item['text'],
-                      'by': user_id[item['user']],
-                    }
-                else:
-                    # top-level post
-                    yield {
-                      'name': f"/{item['ts']}",
-                      'contents': item['text'],
-                      'by': user_id[item['user']],
-                    }
-            except KeyError:
-                stderr.write(repr(item)+'\n')
+def by(item):
+    return user_id[item['user']]
+
+def id(item):
+    if 'thread_ts' in item:
+        # comment
+        return f"/{item['thread_ts']}/{item['ts']}"
+    else:
+        # top-level post
+        return                     f"/{item['ts']}"
 
 for channel in json.load(open('channels.json')):
     for filename in sorted(listdir(channel['name'])):
-        for item in contents(join(channel['name'], filename)):
-            print(f"({json.dumps(item['name'])} {json.dumps(channel['name'])} {item['by']} {json.dumps(item['contents'])})")
+        with open(join(channel['name'], filename)) as f:
+            for item in json.load(f):
+                try:
+                    print(f"({json.dumps(id(item))} {json.dumps(channel['name'])} {by(item)} {json.dumps(item['text'])})")
+                except KeyError:
+                    stderr.write(repr(item)+'\n')