'''
Extract nodes that were active after given date'
'''

validTime = 1335744000
fdIn = open('host_2012_06_02.xml', 'r')
fdOut = open('host_2012_06_02_active_2012_04_30.xml', 'w')
count = 0
lines = []
track = True
for line in fdIn:
    if '</host>' in line:
        if len(lines) > 0: #Reset
            for i in lines: fdOut.write(i)
            fdOut.write(line)
            count += 1
            if count % 500 == 0: print count
            lines = []
        track = True
    elif '<rpc_time>' in line:
        if int(line.split('>')[1].split('<')[0]) < validTime:
            lines = []
            track = False
        else: lines.append(line)
    elif track == True:
        lines.append(line)
fdIn.close()
fdOut.close()
print count
