import time def convert(string = '00:00:00'): """Converts a HH:MM:SS time format to seconds.""" return int(string[:2]) * 3600 + int(string[3:5]) * 60 + int(string[6:]) def increment(ls, i, j): """Increments a second, minute or hour.""" return str(int(ls[i:j]) + 1).zfill(2) name = 'timeRecorder.py' t = '00:00:20/00:01:10' while True: f = file(name, 'r') for line in f: if line.split() != [] and line.split()[0] == 't': exec line ts = t.split('/') total = convert(ts[1]) break f.close() if convert(ts[0]) > total: break # While current time is less than total. time.sleep(1) retain = '' f = file(name, 'r') for line in f: if line.split() != [] and line.split()[0] == 't': ls = line.split()[2][1:-1].split('/')[0] # Get the current time. ls = ls[:-2] + increment(ls, -2, len(ls)) # Increment the second. if ls[-2:] == '60': # If 60 seconds, increment the minute, decrement seconds. ls = ls[:3] + increment(ls, 3, 5) + ':00' if ls[3:5] == '60': # If 60 minutes, increment the hour, decrement minutes. ls = increment(ls, 0, 2) + ':00' + ls[5:] line = line[:5] + ls + line[13:] print line, retain += line f.close() f = file(name, 'w') f.write(retain) f.close()