[Amazfit] fzelle:
My strava export was working, but yesterday it didn't export the 90 minute run.

I'm just looking at the script and the process ( as I don't have root I need the backup variant but with gpx export).

Why is there even the where clause?

I changed the gpx name to year+month+day+'_'+hour+minute+second+"_"+type_id+'.gpx'

Anything else?

Edit:

Here my changes.

I removed the type from the where, and added cadence.

Then I "pretty printed" the resulting xml.

And lastly I only write a new file when that one isn't there

#!/usr/bin/python3
import sqlite3 as lite
import sys
import datetime
import os
import os.path
import time as t #dddddddddddddddd

def db_to_gpx(db,dest):
con = lite.connect(db)

with con:

cur = con.cursor()
cur.execute('SELECT track_id, start_time, type from sport_summary')
running_sessions = cur.fetchall()
for running_session in running_sessions:
track_id=running_session[0]
tiempo_init=running_session[1]
type_id=running_session[2]
cur.execute('SELECT location_data.latitude, location_data.longitude, location_data.altitude, location_data.timestamp from location_data, sport_summary where location_data.track_id=' + str(track_id) + ' and sport_summary.type=2 ')
datos = cur.fetchall()
year=datetime.datetime.fromtimestamp(running_session[1]/1000).strftime('%Y')
month=datetime.datetime.fromtimestamp(running_session[1]/1000).strftime('%m')
day=datetime.datetime.fromtimestamp(running_session[1]/1000).strftime('%d')
hour=datetime.datetime.fromtimestamp(running_session[1]/1000).strftime('%H')
minute=datetime.datetime.fromtimestamp(running_session[1]/1000).strftime('%M')
second=datetime.datetime.fromtimestamp(running_session[1]/1000).strftime('%S')

fileName = dest+'/'+year+month+day+'_'+hour+minute+second+'_'+str(type_id)+'.gpx'

if not os.path.exists(fileName) :
try:
os.remove(fileName)
except OSError:
pass
with open(fileName, 'a') as out:
# Write Header
print('File '+year+'-'+month+'-'+day+'_'+hour+'-'+minute+'-'+second+'_'+str(type_id)+'.gpx syncing...')
out.write('<?xml version="1.0" encoding="UTF-8"?>' + '\n')
out.write('<gpx version="1.1" creator="Amazfit_export by dvd_ath and fzelle" xsi:schemaLocation="http://www.topografix.com/GPX/1/1' + '\n')
out.write('	http://www.topografix.com/GPX/1/1/gpx.xsd' + '\n')
out.write('	http://www.garmin.com/xmlschemas/GpxExtensions/v3' + '\n')
out.write('	http://www.garmin.com/xmlschemas/GpxExtensionsv3.xsd' + '\n')
out.write('	http://www.garmin.com/xmlschemas/TrackPointExtension/v1' + '\n')
out.write('	http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd" xmlns="http://www.topografix.com/GPX/1/1" xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1" xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' + '\n')
out.write('	<metadata>' + '\n')
out.write('	<link href="https://github.com/botmakerdvd/amazfit_exporter">'+ '\n')
out.write('	<text>Amazfit exporter</text>'+ '\n')
out.write('	</link>'+ '\n')
out.write('	<time>'+year+'-'+month+'-'+day+'T'+hour+':'+minute+':'+second+'.000Z</time>'+ '\n')
out.write('	</metadata>'+ '\n')
out.write('	<trk>'+ '\n')
out.write('	<trkseg>'+ '\n')
for dato in datos:
latitud=str(dato[0])
longitud=str(dato[1])
altitud=str(round(dato[2],1))
time=((dato[3]+tiempo_init)/1000)
year=datetime.datetime.fromtimestamp(time).strftime('%Y')
month=datetime.datetime.fromtimestamp(time).strftime('%m')
day=datetime.datetime.fromtimestamp(time).strftime('%d')
hour=datetime.datetime.fromtimestamp(time).strftime('%H')
minute=datetime.datetime.fromtimestamp(time).strftime('%M')
second=datetime.datetime.fromtimestamp(time).strftime('%S')
cur.execute('SELECT rate,step_freq from heart_rate where time=' + str(round(time)*1000))
rate=cur.fetchone()
out.write('	<trkpt lon="'+longitud+'" lat="'+latitud+'">'+ '\n')
out.write('	<ele>'+altitud+'</ele>'+ '\n')
out.write('	<time>'+year+'-'+month+'-'+day+'T'+hour+':'+minute+':'+second+'.000Z</time>'+ '\n')
if rate is not None:
out.write('	<extensions>'+ '\n')
out.write('	<gpxtpx:TrackPointExtension>'+ '\n')
out.write('	<gpxtpx:hr>'+str(int(rate[0]))+'</gpxtpx:hr>'+ '\n')
out.write('	<gpxtpx:cad>'+str(int(rate[1]*30)+1)+'</gpxtpx:cad>'+ '\n')
out.write('	</gpxtpx:TrackPointExtension>'+ '\n')
out.write('	</extensions>'+ '\n')
out.write('	</trkpt>'+ '\n')
out.write('	</trkseg>'+ '\n')
out.write('	</trk>'+ '\n')
out.write('</gpx>'+ '\n')
out.close()