From 3c6a0944d68ca16250ec9364d7f006b0e7eea6e8 Mon Sep 17 00:00:00 2001
From: retoor <retoor@molodetz.nl>
Date: Tue, 18 Mar 2025 00:46:32 +0100
Subject: [PATCH] Added dump script.

---
 Makefile         |  3 +++
 src/snek/dump.py | 17 +++++++++++++++++
 2 files changed, 20 insertions(+)
 create mode 100644 src/snek/dump.py

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()