Skip to content
Snippets Groups Projects
Verified Commit ea58ad06 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Import additional waypoints from GPX.

parent 411e1e4d
No related branches found
No related tags found
No related merge requests found
...@@ -43,7 +43,7 @@ class GpxImporter(object): ...@@ -43,7 +43,7 @@ class GpxImporter(object):
session.add(waypoint) session.add(waypoint)
# Is this a geocache? # Is this a geocache?
if gpx_waypoint.getElementsByTagName('groundspeak:cache'): if waypoint.type.startswith('Geocache|') and gpx_waypoint.getElementsByTagName('groundspeak:cache'):
cache_node = gpx_waypoint.getElementsByTagName('groundspeak:cache')[0] cache_node = gpx_waypoint.getElementsByTagName('groundspeak:cache')[0]
# Find or create listing # Find or create listing
...@@ -107,6 +107,26 @@ class GpxImporter(object): ...@@ -107,6 +107,26 @@ class GpxImporter(object):
# Save log # Save log
session.add(log) session.add(log)
elif waypoint.type.startswith('Waypoint|'):
# This is a sub-waypoint
# Guess platform prefix
if gpx_waypoint.getElementsByTagName('url')[0].firstChild.data.startswith('http://www.geocaching.com'):
platform_prefix = 'GC'
parent_code = platform_prefix + waypoint.code[2:]
# Find or create parent listing
parent_waypoint = session.query(Waypoint).filter_by(code=parent_code).scalar()
if not parent_waypoint:
logger.info('Creating new master waypoint and listing for %s' % parent_code)
parent_waypoint = Waypoint(code=parent_code)
parent_listing = Listing(master_waypoint=parent_waypoint, waypoints=[parent_waypoint])
# Add waypoint
logger.info('Linking %s to %s' % (waypoint.code, parent_code))
parent_listing.waypoints.append(waypoint)
# Save listing
session.add(parent_listing)
session.commit() session.commit()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment