Compare commits

...

3 Commits

Author SHA1 Message Date
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
2 changed files with 1316 additions and 530 deletions

File diff suppressed because it is too large Load Diff

30
script.py Normal file → Executable file
View File

@ -1,10 +1,28 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: CC0-1.0
from mako.template import Template
import json
import itertools
import argparse
appTemplate = Template(filename='./spaces.html')
f = open('libregamingspaces.json')
spaces=json.load(f)
def render(spaces, template):
appTemplate = Template(filename=template)
print(appTemplate.render(s=spaces))
print(appTemplate.render(s=spaces))
def make_hierarchy(room, loops, depth=0):
try:
print(' ' * depth + '- ' + room['name'])
if room['children_state'] and room['room_id'] not in loops:
for child in room['children_state']:
make_hierarchy(ROOMS[child['state_key']], loops, depth+1)
except:
# missing or no name
print(' ' * depth + ' Skip ' + room['room_id'])
if __name__ == '__main__':
with open('libregamingspaces.json') as f:
data = json.load(f)
# render(data, './spaces.html')
ROOMS = {room['room_id'] : room for room in data}
make_hierarchy(ROOMS['!IdUUdKALNzBLKEjvbP:matrix.org'], ['!JTpfWshTKZpZiUASvP:hacklab.fi'])