From 9a747878a08bb1b9f921bea5ff9ab9ac0aec737c Mon Sep 17 00:00:00 2001 From: Mike Lang Date: Sun, 13 Nov 2022 05:38:20 +1100 Subject: [PATCH] chat archiver: Add cli tool for downloading emotes --- chat_archiver/chat_archiver/ensure_emotes.py | 18 ++++++++++++++++++ chat_archiver/chat_archiver/main.py | 4 ++++ 2 files changed, 22 insertions(+) create mode 100644 chat_archiver/chat_archiver/ensure_emotes.py diff --git a/chat_archiver/chat_archiver/ensure_emotes.py b/chat_archiver/chat_archiver/ensure_emotes.py new file mode 100644 index 0000000..4e968eb --- /dev/null +++ b/chat_archiver/chat_archiver/ensure_emotes.py @@ -0,0 +1,18 @@ + +import gevent.monkey +gevent.monkey.patch_all() + +import argh +import logging +import json + +from chat_archiver.main import ensure_emotes, wait_for_ensure_emotes + +def main(base_dir, *ids, log='INFO'): + """Ensure all listed emote ids are downloaded""" + logging.basicConfig(level=log) + ensure_emotes(base_dir, ids) + wait_for_ensure_emotes() + +if __name__ == '__main__': + argh.dispatch_command(main) diff --git a/chat_archiver/chat_archiver/main.py b/chat_archiver/chat_archiver/main.py index 6f4dfab..8df8b67 100644 --- a/chat_archiver/chat_archiver/main.py +++ b/chat_archiver/chat_archiver/main.py @@ -322,6 +322,10 @@ def ensure_emotes(base_dir, emote_ids): logging.debug("Skipping checking emote with key {} - already running".format(key)) +def wait_for_ensure_emotes(): + gevent.wait(_EMOTES_RUNNING.values()) + + def write_batch(path, batch_time, messages, size_histogram=None): """Batches are named PATH/YYYY-MM-DDTHH/MM:SS-HASH.json""" output = (format_batch(messages) + '\n').encode('utf-8')