# caps.py: 48 US capitals
import sys
import re
from graph import *
    
# construct graph
g = Graph()

r = re.compile(r"(\d+)\s+\(\"([A-Z][A-Z])\",\s+(\d+),\s+(\d+)" )
f = open("capsdata1.txt",'r')

for line in f:
    m = r.search(line)
    if m != None:
        i = int(m.group(1))
        state = m.group(2)
        x = int(m.group(3))
        y = int(m.group(4))
        entry = [ state, x, y]
        #sys.stdout.write(str(entry) + '\n')
        g.insertVertex(entry) 

r = re.compile(r"(\d*)\s*(\d*)\s*(\d*)" )
f = open("capsdata2.txt",'r')

for line in f:
    m = r.search(line)
    if m != None:
        i = int(m.group(1))
        j = int(m.group(2))
        d = int(m.group(3))
        #sys.stdout.write(str(i)+" "+str(j)+" "+str(d)+"\n")
        g.insertEdge(i, j, d)
        g.insertEdge(j, i, d)
        
# testing
sys.stdout.write(str(g.getEdgeData(2,6))+'\n')
g.putEdgeData(2,6,444)
sys.stdout.write(str(g.getEdgeData(2,6))+'\n')
g.putVertexData(4, ['Arizona', 3, 3])
sys.stdout.write(str(g.getVertexData(4))+'\n')

g.printGraph()

"""
441
444
['Arizona', 3, 3]
g = [
[['CA', 1, 4], [[4, 755], [1, 129], [2, 535]]], # 0
[['NV', 2, 4], [[0, 129], [4, 713], [5, 534], [6, 541], [2, 663]]], # 1
[['OR', 2, 5], [[0, 535], [1, 663], [6, 444], [3, 160]]], # 2
[['WA', 2, 6], [[2, 160], [6, 619]]], # 3
[['Arizona', 3, 3], [[0, 755], [1, 713], [7, 476], [5, 652]]], # 4
[['UT', 3, 4], [[1, 534], [4, 652], [8, 488], [9, 435], [6, 338]]], # 5
[['ID', 3, 5], [[1, 541], [2, 441], [3, 619], [5, 338], [9, 727], [10, 438]]], # 6
[['NM', 4, 3], [[4, 476], [11, 697], [12, 585], [8, 355]]], # 7
[['CO', 4, 4], [[5, 488], [7, 355], [12, 626], [13, 536], [14, 486], [9, 100]]], # 8
[['WY', 4, 5], [[5, 435], [6, 727], [8, 100], [14, 444], [15, 455], [10, 675]]], # 9
[['MT', 4, 6], [[6, 438], [9, 675], [15, 742], [16, 624]]], # 10
[['TX', 5, 2], [[7, 697], [17, 430], [18, 504], [12, 388]]], # 11
[['OK', 5, 3], [[7, 585], [8, 626], [11, 388], [18, 337], [19, 416], [13, 293]]], # 12
[['KS', 5, 4], [[8, 536], [12, 293], [19, 204], [14, 165]]], # 13
[['NE', 5, 5], [[8, 486], [9, 444], [13, 165], [19, 343], [20, 187], [15, 392]]], # 14
[['SD', 5, 6], [[9, 455], [10, 742], [14, 392], [20, 490], [21, 404], [16, 215]]], # 15
[['ND', 5, 7], [[10, 624], [15, 215], [21, 435]]], # 16
[['LA', 6, 2], [[11, 430], [22, 150], [18, 416]]], # 17
[['AR', 6, 3], [[11, 504], [12, 337], [17, 416], [22, 253], [26, 344], [19, 340]]], # 18
[['MO', 6, 4], [[12, 416], [13, 204], [14, 343], [18, 340], [26, 453], [27, 562], [23, 192], [20, 255]]], # 19
[['IA', 6, 5], [[14, 187], [15, 490], [19, 255], [23, 291], [24, 279], [21, 244]]], # 20
[['MN', 6, 6], [[15, 404], [16, 435], [20, 244], [24, 258]]], # 21
[['MS', 7, 2], [[17, 150], [18, 253], [25, 242], [26, 392]]], # 22
[['IL', 7, 5], [[19, 192], [20, 291], [27, 415], [28, 190], [24, 249]]], # 23
[['WI', 7, 6], [[20, 279], [21, 258], [23, 249], [29, 614]]], # 24
[['AL', 8, 2], [[22, 242], [30, 205], [31, 160], [26, 282]]], # 25
[['TN', 8, 3], [[18, 344], [19, 453], [22, 392], [25, 282], [31, 255], [36, 530], [32, 597], [27, 203]]], # 26
[['KY', 8, 4], [[19, 562], [23, 415], [26, 203], [32, 532], [33, 197], [34, 186], [28, 145]]], # 27
[['IN', 8, 5], [[23, 190], [27, 145], [34, 175], [29, 244]]], # 28
[['MI', 8, 6], [[24, 614], [28, 244], [34, 237]]], # 29
[['FL', 9, 1], [[25, 205], [31, 252]]], # 30
[['GA', 9, 2], [[25, 160], [26, 255], [30, 252], [35, 212], [36, 434]]], # 31
[['VA', 9, 3], [[26, 597], [27, 532], [36, 156], [37, 129], [33, 302]]], # 32
[['WV', 9, 4], [[27, 197], [32, 302], [37, 397], [38, 354], [34, 160]]], # 33
[['OH', 9, 5], [[27, 186], [28, 175], [29, 237], [33, 160], [38, 425]]], # 34
[['SC', 10, 1], [[31, 212], [36, 200]]], # 35
[['NC', 10, 2], [[26, 530], [31, 434], [32, 156], [35, 200]]], # 36
[['MD', 10, 4], [[32, 129], [33, 397], [39, 62], [38, 103]]], # 37
[['PA', 10, 5], [[33, 354], [34, 425], [37, 103], [39, 124], [40, 127], [41, 268]]], # 38
[['DE', 11, 4], [[37, 62], [38, 124], [40, 108]]], # 39
[['NJ', 11, 5], [[38, 127], [39, 108], [41, 193]]], # 40
[['NY', 11, 6], [[38, 268], [40, 193], [43, 111], [44, 165], [42, 153]]], # 41
[['VT', 11, 7], [[41, 153], [44, 236], [45, 106]]], # 42
[['CT', 12, 5], [[41, 111], [46, 72], [44, 101]]], # 43
[['MA', 12, 6], [[41, 165], [42, 236], [43, 101], [46, 45], [45, 68]]], # 44
[['NH', 12, 7], [[42, 106], [44, 68], [47, 139]]], # 45
[['RI', 13, 5], [[43, 72], [44, 45]]], # 46
[['ME', 13, 7], [[45, 139]]], # 47
]
"""