diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2021-08-10 04:11:51 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2021-08-10 04:11:51 -0700 |
commit | 4f236749a2374914411005d18106a945815b6bea (patch) | |
tree | 4512673cb7d2a40bac19d8f729cc549bfb4f16bb /browse_slack | |
parent | dd625f6caaceeb5cb0f1f645cd090d7f8f87f763 (diff) | |
download | mu-4f236749a2374914411005d18106a945815b6bea.tar.gz |
.
Diffstat (limited to 'browse_slack')
-rw-r--r-- | browse_slack/convert_slack.py | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/browse_slack/convert_slack.py b/browse_slack/convert_slack.py index a2e0c4ef..db53cebf 100644 --- a/browse_slack/convert_slack.py +++ b/browse_slack/convert_slack.py @@ -38,33 +38,6 @@ user_id = {} # name -> index 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 filenames(dir): - for filename in sorted(listdir(dir)): - result = join(dir, filename) - if isfile(result): - yield result - def look_up_ppm_image(url): file_root = splitext(basename(urlparse(url).path))[0] filename = f"images/ppm/{file_root}.ppm" @@ -92,6 +65,33 @@ def load_channels(): for channel in json.load(f): channels[channel['id']] = channel['name'] +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 filenames(dir): + for filename in sorted(listdir(dir)): + result = join(dir, filename) + if isfile(result): + yield result + load_channels() load_users() for dir in channels.values(): |