~ubuntu-branches/debian/wheezy/foxtrotgps/wheezy

« back to all changes in this revision

Viewing changes to contrib/osb2foxtrot

  • Committer: Package Import Robot
  • Author(s): Daniel Baumann
  • Date: 2012-02-14 06:13:28 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20120214061328-zo4mu0rvgz06q5nw
Tags: 1.1.0-1
* Using compression level 9 also for binary packages.
* Merging upstream version 1.1.0:
  - includes osb2tango and poi2osm (Closes: #647986).
* Removing curl.patch, included upstream.
* Updating to debhelper version 9.
* Updating years in copyright.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
from xml.etree.ElementTree import parse
 
4
import sys, re, hashlib
 
5
from pysqlite2 import dbapi2 as sqlite
 
6
 
 
7
if len(sys.argv) <3:
 
8
  print "usage:"
 
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"
 
12
  sys.exit(1)
 
13
 
 
14
def escapeQuote(str):
 
15
  """escapes single quotes by double single quote, sqlite style"""
 
16
  return str.replace('\'', '\'\'');
 
17
 
 
18
gpx = open(sys.argv[1])
 
19
xml = parse(gpx).getroot()
 
20
 
 
21
con = sqlite.connect(sys.argv[2]) 
 
22
cur = con.cursor()
 
23
 
 
24
for wpt in xml:
 
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():
 
29
      data[item[0]]=item[1]
 
30
    # transfer information from the sublevel tags into dictionary
 
31
    for sub in wpt:
 
32
      if sub.tag=="{http://www.topografix.com/GPX/1/1}desc":
 
33
        data['desc']=sub.text
 
34
    # build the query
 
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.
 
37
    cur.execute(query)
 
38
 
 
39
 
 
40
con.commit()
 
41