Added dump script.

This commit is contained in:
retoor 2025-03-18 00:46:32 +01:00
parent 825ece4e78
commit 3c6a0944d6
2 changed files with 20 additions and 0 deletions

View File

@ -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

17
src/snek/dump.py Normal file
View File

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