#!/usr/bin/env python

def read_file(filename):
    with open(filename, 'r') as f:
        for line in f:
            yield line.strip()
            
def main():
    graph = dict()

    for line in read_file("connections.txt"):
        tokens = line.split(" ")
        tokens[0] = int(tokens[0])
        tokens[1] = int(tokens[1])

        # add vertex 1
        if tokens[0] not in graph:
            graph[tokens[0]] = set()
        graph[tokens[0]].add(tokens[2])
        # add vertex 2
        if tokens[1] not in graph:
            graph[tokens[1]] = set()
        graph[tokens[1]].add(tokens[2])

    for (k, v) in graph.items():  
        # svg base data
        color_circle_up="yellow"
        color_circle_down="yellow"
        color_rectangle="white"
        color_number="black"
        
        if 'bus' in v:
            color_circle_down="green"
        if 'underground' in v:
            color_rectangle="red"
            color_number="white"

        with open(f"../data/{k}.svg", "w") as f:
            f.write("<svg height=\"64\" width=\"64\" xmlns=\"http://www.w3.org/2000/svg\">\n")
            f.write(f"<circle cx=\"32\" cy=\"32\" r=\"30\" fill=\"{ color_circle_up }\" stroke=\"black\" stroke-width=\"2\"/>\n")
            f.write(f"<path d=\"M2,32 a1,1 0 0,0 60,0 Z\" fill=\"{ color_circle_down }\" stroke=\"black\" stroke-width=\"2\"/>\n")
            f.write(f"<rect x=\"15\" y=\"20\" width=\"35\" height=\"20\" stroke=\"black\" fill=\"{ color_rectangle }\" stroke-width=\"2\" />\n")
            f.write(f"<text x=\"50%\" y=\"50%\" fill=\"{ color_number }\" dominant-baseline=\"middle\" text-anchor=\"middle\">{ k }</text>\n")
            f.write('</svg>')
if __name__ == "__main__":
    main()


'''
<svg height="64" width="64">
  <circle cx="32" cy="32" r="30" fill="yellow" stroke="black" stroke-width="2"/>
  <path d="M2,32 a1,1 0 0,0 60,0 Z" fill="green" stroke="black" stroke-width="2"/>
   <rect x="15" y="20" width="35" height="20" stroke="black" fill="red" stroke-width="2" />
  <text x="50%" y="50%" fill="white" dominant-baseline="middle" text-anchor="middle">9</text>
</svg>
'''