-
Notifications
You must be signed in to change notification settings - Fork 2
/
gpxshift
executable file
·52 lines (42 loc) · 1.25 KB
/
gpxshift
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
import argparse
import logging
import sys
import traceback
import gpxlib
def main():
parser = argparse.ArgumentParser(
description="A tool to shift timestamps in a GPX file"
)
parser.add_argument(
"-v",
"--verbose",
help="Increase output verbosity (thus rendering output XML unusable)",
action="store_true",
)
parser.add_argument(
"-l",
"--last",
help="Set the last timestamp; only useful with an absolute timestamp",
action="store_true",
)
parser.add_argument("-o", "--output", help="Write output to OUTPUT")
parser.add_argument("value")
parser.add_argument("file", nargs="?")
args, pass_args = parser.parse_known_args()
args = parser.parse_args()
logging.basicConfig(level=1, format="%(asctime)s -- %(message)s")
gpx_in, points = gpxlib.read(args.file)
gpx_out, segment = gpxlib.create(gpx_in)
try:
segment.points = gpxlib.gpxshift(points, args.value, args.last)
except Exception:
sys.exit(traceback.format_exc())
s = gpx_out.to_xml()
if args.output:
with open(args.output, "w") as f:
f.write(s)
else:
print(s)
if __name__ == "__main__":
main()