Added dump script.
This commit is contained in:
parent
825ece4e78
commit
3c6a0944d6
3
Makefile
3
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
|
||||
|
||||
|
17
src/snek/dump.py
Normal file
17
src/snek/dump.py
Normal 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()
|
Loading…
Reference in New Issue
Block a user