""" graph.py create an accessible graph """ import json import sys from bs4 import BeautifulSoup as bs def original(graph): html = "" return html def flatten(graph): new = list() for n in graph: new.append(n) if "subitems" in n: for m in n["subitems"]: new.append(m) return new def sntn(graph, short_name): for n in flatten(graph): if n["short_name"] == short_name: return n["name"] return None def connections_to(graph): def _conns(node): html = f"
  • " + f"{node['name']}" if "cons" in node: html += "" html += "
  • " return html html = "" return html def get_reverse_connections(sn, graph): cons = list() for n in flatten(graph): if "cons" in n and sn in n["cons"]: cons.append(n["short_name"]) return cons def connections_from(graph): def _conns(node): html = f"
  • " + f"{node['name']}" html += "
  • " return html html = "" return html if __name__ == "__main__": if len(sys.argv) < 2: print("Must specify .json file") exit() f = open(sys.argv[1], "r") graph = json.loads(f.read()) html = "" html += "

    Graph

    " html += "

    The ideal solution to this would actually be to turn the graph into a 3D braille model so it can be printed. Due to conditions of remoteness and the time required to do such a task though, this is not possible right now.

    " html += "

    Please do not navigate to connections manually. Use the links.

    " html += "

    Nodes of Graph

    " html += original(graph) html += "

    Graph Connections (to)

    " html += connections_to(graph) html += "

    Graph Connections (form)

    " html += connections_from(graph) html += "" soup = bs(html, "html.parser") print(soup.prettify())