diff --git a/Makefile b/Makefile index e3febf7..70b06a0 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,9 @@ PORT = 8081 python: $(PYTHON) +dump: + $(PYTHON) -m snek.dump + run: $(GUNICORN) -w $(GUNICORN_WORKERS) -k aiohttp.worker.GunicornWebWorker snek.gunicorn:app --bind 0.0.0.0:$(PORT) --reload diff --git a/src/snek/dump.py b/src/snek/dump.py new file mode 100644 index 0000000..6401637 --- /dev/null +++ b/src/snek/dump.py @@ -0,0 +1,17 @@ +import json + +from snek.app import app + + +def dump_public_channels(): + result = {'channels':{}} + + for channel in app.db['channel'].find(is_private=False,is_listed=True): + result['channels'][channel['label']] = dict(channel) + result['channels'][channel['label']]['messages'] = list(dict(record) for record in app.db['channel_message'].find(channel_uid=channel['uid'])) + + print(json.dumps(result, sort_keys=True, indent=4,default=str),end='',flush=True) + + +if __name__ == '__main__': + dump_public_channels()