Addde fallback for 0.0 values - no insert
This commit is contained in:
parent
2eeada3129
commit
e44761db8f
|
|
@ -30,15 +30,19 @@ def hello():
|
|||
def getGpsDistance():
|
||||
own_id = request.args.get('id')
|
||||
req_id = request.args.get('req_id')
|
||||
lat = dm(request.args.get('lat'))
|
||||
long = dm(request.args.get('long'))
|
||||
lat = dm(request.args.get('lat')) if request.args.get('lat') != '0' else 0.0
|
||||
long = dm(request.args.get('long')) if request.args.get('long') != '0' else 0.0
|
||||
|
||||
try:
|
||||
gpsDateTime = datetime.strptime(request.args.get('gpsDateTime')[:11], '%d%m%y%H%M%S')
|
||||
print(gpsDateTime)
|
||||
except ValueError:
|
||||
print("No gpsDateTime")
|
||||
gpsDateTime = datetime.now()
|
||||
print(request.args)
|
||||
|
||||
|
||||
if (lat != 0.0 and long != 0.0):
|
||||
with sqlite3.connect('location.db', check_same_thread=False) as conn:
|
||||
cur = conn.cursor()
|
||||
cur.execute(f'INSERT INTO location_data(sender_id, lat, long, gpsDateTime) VALUES({own_id}, {lat}, {long}, "{gpsDateTime}");')
|
||||
|
|
@ -61,9 +65,6 @@ def getGpsDistance():
|
|||
|
||||
fwd_azimuth, back_azimuth, distance = geodesic.inv(long, lat, req_long, req_lat)
|
||||
|
||||
|
||||
|
||||
|
||||
distance = distance * ureg.meter
|
||||
prettyDistance = f"{distance:.1f~#P}"
|
||||
print(f'fwd: {fwd_azimuth}, bwd: {back_azimuth}, dist: {prettyDistance}')
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user