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():
|
def getGpsDistance():
|
||||||
own_id = request.args.get('id')
|
own_id = request.args.get('id')
|
||||||
req_id = request.args.get('req_id')
|
req_id = request.args.get('req_id')
|
||||||
lat = dm(request.args.get('lat'))
|
lat = dm(request.args.get('lat')) if request.args.get('lat') != '0' else 0.0
|
||||||
long = dm(request.args.get('long'))
|
long = dm(request.args.get('long')) if request.args.get('long') != '0' else 0.0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
gpsDateTime = datetime.strptime(request.args.get('gpsDateTime')[:11], '%d%m%y%H%M%S')
|
gpsDateTime = datetime.strptime(request.args.get('gpsDateTime')[:11], '%d%m%y%H%M%S')
|
||||||
|
print(gpsDateTime)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
print("No gpsDateTime")
|
print("No gpsDateTime")
|
||||||
gpsDateTime = datetime.now()
|
gpsDateTime = datetime.now()
|
||||||
print(request.args)
|
print(request.args)
|
||||||
|
|
||||||
|
|
||||||
|
if (lat != 0.0 and long != 0.0):
|
||||||
with sqlite3.connect('location.db', check_same_thread=False) as conn:
|
with sqlite3.connect('location.db', check_same_thread=False) as conn:
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
cur.execute(f'INSERT INTO location_data(sender_id, lat, long, gpsDateTime) VALUES({own_id}, {lat}, {long}, "{gpsDateTime}");')
|
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)
|
fwd_azimuth, back_azimuth, distance = geodesic.inv(long, lat, req_long, req_lat)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
distance = distance * ureg.meter
|
distance = distance * ureg.meter
|
||||||
prettyDistance = f"{distance:.1f~#P}"
|
prettyDistance = f"{distance:.1f~#P}"
|
||||||
print(f'fwd: {fwd_azimuth}, bwd: {back_azimuth}, dist: {prettyDistance}')
|
print(f'fwd: {fwd_azimuth}, bwd: {back_azimuth}, dist: {prettyDistance}')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user