3
from xml.etree.ElementTree import parse
4
import sys, re, hashlib
5
from pysqlite2 import dbapi2 as sqlite
9
print "./osb2foxtrot gpxfile poidbfile"
10
print " gpxfile: a file in the OSB GPX file format, containing bug information"
11
print " poidbfile: usually poi.db, or any other wellformed foxtrotgps poi sqlite database file"
15
"""escapes single quotes by double single quote, sqlite style"""
16
return str.replace('\'', '\'\'');
18
gpx = open(sys.argv[1])
19
xml = parse(gpx).getroot()
21
con = sqlite.connect(sys.argv[2])
25
if wpt.tag=="{http://www.topografix.com/GPX/1/1}wpt":
26
data = {} # dictionary holding all relevant data to be written into database
27
# transfer lat, lon into dictionary directly
28
for item in wpt.items():
30
# transfer information from the sublevel tags into dictionary
32
if sub.tag=="{http://www.topografix.com/GPX/1/1}desc":
35
idmd5 = hashlib.md5(data['lon']+data['lat']).hexdigest()[0:18] #not the format foxtrotgps uses
36
query = "insert into poi (idmd5, lon, lat, keywords, visibility, cat, subcat, price_range, extended_open, desc) values ('"+idmd5+"', '"+data['lon']+"', '"+data['lat']+"', 'OpenStreetBug', 0.0, 14.0, 2.0, 3.0, 0.0, '"+escapeQuote(data['desc'])+"')" #foxtrotgps crashes if some of these remain NULL.