Created
March 21, 2016 13:47
-
-
Save ilkinulas/8e1d7fc69d1cd15ce671 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import re | |
import datetime | |
REGEX = "([0-9]{8} [0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3})(.*)"; | |
shiftSeconds = int(sys.argv[2]) | |
startTime = sys.argv[3] | |
startShifting = False | |
with open(sys.argv[1]) as fp: | |
for line in fp: | |
m = re.search(REGEX, line) | |
if m is not None: | |
timestring = m.group(1) | |
if timestring == startTime: | |
startShifting = True | |
if startShifting: | |
rest = m.group(2) | |
t = datetime.datetime.strptime(timestring, "%Y%m%d %H:%M:%S.%f") | |
t = t - datetime.timedelta(seconds = shiftSeconds) | |
shiftedTime = t.strftime("%Y%m%d %H:%M:%S.%f")[:-3] | |
print shiftedTime + rest | |
else: | |
print m.group(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment