Compare commits

...

6 Commits

Author SHA1 Message Date
Rampoina 74978a8ae4 Fix the structure to recursively contain spaces 2022-04-17 22:28:37 +02:00
Rampoina d0bda2688b Merge changes from master 2022-04-17 18:07:14 +02:00
Phil Morrell a0ff199506
transform the API json into a usable datastructure
* index by room_id and recursively build the Space hierarchy
* not proper tail recursion, and uses a global variable for now
* FlightGear Republic is both child and parent of FlightGear and JSBSim
* as proof of concept, print out the room name at correct depth
2022-04-17 14:27:35 +01:00
Phil Morrell e451a10bf3
refactor python to support multiple actions
* executable, license header
* prefer `with open` style to auto-close file handles
* keep hardcoding within __main__
2022-04-17 14:14:22 +01:00
Phil Morrell 585fde2898
update spaces json from matrix-client.matrix.org 2022-04-17 13:55:52 +01:00
Phil Morrell f103ce8649
update spaces json from API
* paginated, append `&from=$FROM` and repeat until "null"

    SPACE='!IdUUdKALNzBLKEjvbP:matrix.org'
    URL="https://freedombox.emorrp1.name/_matrix/client/unstable/org.matrix.msc2946/rooms/$SPACE/hierarchy?access_token=$TOKEN"
    FROM=$(curl "$URL" | tee -a hierarchy.json | jq -r .next_batch); echo $FROM
    jq -s 'map(.rooms) | add' hierarchy.json > libregamingspaces.json
2022-02-12 15:09:53 +00:00
4 changed files with 7377 additions and 3091 deletions

File diff suppressed because it is too large Load Diff

4952
list.html

File diff suppressed because it is too large Load Diff

39
script.py Normal file → Executable file
View File

@ -1,19 +1,42 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: CC0-1.0
from mako.template import Template
import json
import itertools
import argparse
def mxc2url(mxc):
serverName = mxc.split('/')[2]
mediaId = mxc.split('/')[3]
return "https://matrix.org/_matrix/media/v3/download/" + serverName + "/" + mediaId
appTemplate = Template(filename='./spaces.html')
f = open('libregamingspaces.json')
spaces=json.load(f)
print(appTemplate.render(s=spaces))
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)
#print(spaces)
render(spaces, loops, './spaces.html')

View File

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