7 from urllib2 import unquote
13 def check_db_for_training(db,sport,timestamp):
15 conn = sqlite3.connect(db)
18 cur.execute ("select count(*) from tracks where sport=? and start_time=?" , (sport,timestamp))
19 return cur.fetchall()[0][0]
21 def write_parsed_to_db(db,gpx,filename):
23 conn = sqlite3.connect(db)
26 cur.execute ("delete from tracks where filename=?" , (filename.decode('UTF-8'),))
44 cur.execute("insert into authors(name,description) values(?,?)", (author,''))
45 print "created author %s" % (author)
47 print "failed to create author %s" % (author)
55 printable = pygeocode.GeoName(start.lat,start.lon).printable
56 start_time = track.start_time()
57 full_duration = track.full_duration().total_seconds()
58 distance = track.distance()
59 filtered_distance = track.filtered_distance(max_speed=50)
60 ascent = track.elevation_gain()
61 descent = track.elevation_loss()
62 ((minlat,minlon),(maxlat,maxlon)) = track.bound_box()
64 gpx.author,name,filename.decode('UTF-8'),
65 track.sport,start_time,full_duration,
66 distance,filtered_distance,ascent,descent,
69 minlat,minlon,maxlat,maxlon
73 author,name,filename,sport,
75 distance,distance_filtered,
77 lat,lon,printable_location,minlat,minlon,maxlat,maxlon)
79 ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
83 print "created track %s" % (filename)
89 def write_tree_to_db(db,tree,filename):
94 write_parsed_to_db(db,gpx,filename)