Fix the structure to recursively contain spaces

This commit is contained in:
Rampoina 2022-04-17 22:28:37 +02:00
parent d0bda2688b
commit 74978a8ae4
3 changed files with 2893 additions and 2102 deletions

4952
list.html

File diff suppressed because it is too large Load Diff

View File

@ -9,25 +9,34 @@ def mxc2url(mxc):
mediaId = mxc.split('/')[3] mediaId = mxc.split('/')[3]
return "https://matrix.org/_matrix/media/v3/download/" + serverName + "/" + mediaId return "https://matrix.org/_matrix/media/v3/download/" + serverName + "/" + mediaId
def render(spaces, template): def render(spaces, loops, template):
appTemplate = Template(filename=template) appTemplate = Template(filename=template)
print(appTemplate.render(s=spaces)) print(appTemplate.render(s=spaces,loops=loops))
def make_hierarchy(room, loops, depth=0): def make_hierarchy(space, room, loops):
try: try:
print(' ' * depth + '- ' + room['name']) if 'children' in space:
if room['children_state'] and room['room_id'] not in loops: space['children'].append(room)
for child in room['children_state']: else:
make_hierarchy(ROOMS[child['state_key']], loops, depth+1) 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: except:
# missing or no name pass
print(' ' * depth + ' Skip ' + room['room_id'])
if __name__ == '__main__': if __name__ == '__main__':
with open('libregamingspaces.json') as f: with open('libregamingspaces.json') as f:
data = json.load(f) data = json.load(f)
# render(data, './spaces.html')
ROOMS = {room['room_id'] : room for room in data} ROOMS = {room['room_id'] : room for room in data}
make_hierarchy(ROOMS['!IdUUdKALNzBLKEjvbP:matrix.org'], ['!JTpfWshTKZpZiUASvP:hacklab.fi']) spaces={'name':"TOP"}
loops=['!JTpfWshTKZpZiUASvP:hacklab.fi']
make_hierarchy(spaces,ROOMS['!IdUUdKALNzBLKEjvbP:matrix.org'], loops)
#print(spaces)
render(spaces, loops, './spaces.html')

View File

@ -10,18 +10,19 @@
<link rel="stylesheet" href="main.css"> <link rel="stylesheet" href="main.css">
</head> </head>
<body> <body>
<%def name="render(space)"> <%def name="render(room)">
<table> <table>
<tbody> <tbody>
% for room in space:
<tr> <tr>
% if 'avatar_url' in room: % if 'avatar_url' in room:
<td><img class="avatar roomAvatar" src=${mxc2url(room['avatar_url'])}></td> <td><img class="avatar roomAvatar" src=${mxc2url(room['avatar_url'])}></td>
% endif % endif
% if 'room_type' in room and room['room_type'] == "m.space": % if 'children' in room:
<td><div> Subspace: ${room['name']} </div></td> <td><div>${room['name']} </div></td>
</tr> </tr>
<tr><td>${render(room['children_state'])}</td></tr> % for subroom in room['children']:
<tr><td>${render(subroom)}</td></tr>
% endfor
% else: % else:
% if 'room_id' in room: % if 'room_id' in room:
@ -35,7 +36,6 @@
% endif % endif
</tr> </tr>
% endif % endif
% endfor
</tbody> </tbody>
</table> </table>
</%def> </%def>