-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsave-gpx.py
executable file
·38 lines (33 loc) · 1.07 KB
/
save-gpx.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
34
35
36
37
38
#!/usr/bin/python
# -*- encoding: utf-8 -*-
import optparse
import sys
from geocaching import Geo, tools
def main():
geo = Geo()
parser = optparse.OptionParser(usage="%prog GC-code [GC-code ...]",
description="Saves GPX data to GCCODE.gpx files")
opts, args = parser.parse_args()
if len(args) < 1:
parser.print_help()
sys.exit(1)
print "Logged in as %s" % geo.login_from_config()
for arg in args:
guid = arg
if arg.count('-') != 4:
guid = geo.guid_from_gc(arg)
gpx = geo.cache_gpx(guid)
if gpx is None:
print "Cache %s not found." % arg
continue
geocode = tools.geocode(gpx)
if geocode is None:
print "Can't parse cache %s, skipping", arg
continue
filename = "%s.gpx" % geocode
gpx.write(open(filename, "w"),
encoding="utf-8", xml_declaration=True,
pretty_print=True)
print ">>>>>>>>> Wrote %s" % filename
if __name__ == '__main__':
main()