-
Notifications
You must be signed in to change notification settings - Fork 2
/
gpxtac
executable file
·44 lines (34 loc) · 1.11 KB
/
gpxtac
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
#!/usr/bin/env python
import argparse
import logging
import sys
import traceback
import gpxlib
def main():
# https://stackoverflow.com/questions/10027242/python-argparse-to-handle-arbitrary-numeric-options-like-head1
parser = argparse.ArgumentParser(description="Outputs GPX points in reverse order")
parser.add_argument("file", nargs="?")
parser.add_argument(
"-t",
"--time",
help="Don't invert timestamps, only GPS points",
action="store_true",
)
parser.add_argument("-o", "--output", help="Write output to OUTPUT")
args, pass_args = parser.parse_known_args()
logging.basicConfig(level=1, format="%(asctime)s -- %(message)s")
# read input, create GPX output
gpx_in, points = gpxlib.read(args.file)
gpx_out, segment = gpxlib.create(gpx_in)
try:
segment.points = gpxlib.gpxtac(points, args.time)
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()