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
This commit is contained in:
parent
e451a10bf3
commit
a0ff199506
17
script.py
17
script.py
|
@ -8,8 +8,21 @@ def render(spaces, template):
|
||||||
appTemplate = Template(filename=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__':
|
if __name__ == '__main__':
|
||||||
with open('libregamingspaces.json') as f:
|
with open('libregamingspaces.json') as f:
|
||||||
spaces = json.load(f)
|
data = json.load(f)
|
||||||
|
|
||||||
render(spaces, './spaces.html')
|
# render(data, './spaces.html')
|
||||||
|
ROOMS = {room['room_id'] : room for room in data}
|
||||||
|
make_hierarchy(ROOMS['!IdUUdKALNzBLKEjvbP:matrix.org'], ['!JTpfWshTKZpZiUASvP:hacklab.fi'])
|
||||||
|
|
Loading…
Reference in New Issue