forked from quisquous/cactbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimeline_adjust.py
executable file
·33 lines (25 loc) · 1.01 KB
/
timeline_adjust.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/python
from __future__ import print_function
import argparse
import re
time_re = re.compile(r"^\s*#?\s*([0-9]+(?:\.[0-9]+)?)\s+\"")
first_num_re = re.compile(r"([0-9]+(?:\.[0-9]+)?)")
def adjust_lines(lines, adjust):
for line in lines:
match = re.match(time_re, line)
if match:
time = float(match.group(1)) + adjust
print(re.sub(first_num_re, "%.1f" % time, line, 1), end='')
else:
print(line, end='')
def main():
parser = argparse.ArgumentParser(
description="A utility to uniformly adjust times in an act timeline file")
parser.add_argument('--file', required=True, type=argparse.FileType('r', encoding="utf8"),
help="The timeline file to adjust times in")
parser.add_argument('--adjust', required=True, type=float,
help="The amount of time to adjust each entry by")
args = parser.parse_args()
adjust_lines(args.file, args.adjust)
if __name__ == "__main__":
main()