libregamingspaces/script.py

34 lines
1021 B
Python
Executable File

#!/usr/bin/env python3
# SPDX-License-Identifier: CC0-1.0
from mako.template import Template
import json
def render(spaces, loops, template):
appTemplate = Template(filename=template)
print(appTemplate.render(s=spaces,loops=loops))
def make_hierarchy(space, room, loops):
try:
if 'children' in space:
space['children'].append(room)
else:
space['children'] = [room]
if 'children_state' in room:
for child in room['children_state']:
if ROOMS[child['state_key']]['room_id'] not in loops:
make_hierarchy(room,ROOMS[child['state_key']], loops)
except:
pass
if __name__ == '__main__':
with open('libregamingspaces.json') as f:
data = json.load(f)
ROOMS = {room['room_id'] : room for room in data}
spaces={'name':"TOP"}
loops=['!JTpfWshTKZpZiUASvP:hacklab.fi']
make_hierarchy(spaces,ROOMS['!IdUUdKALNzBLKEjvbP:matrix.org'], loops)
render(spaces, loops, './spaces.html')