I got gps log files with line of text
{"location": {"lat": 50.0918805, "lng": 14.4261817}, "accuracy": 29.1671027, "ts": 1598515548}
My goal is to print values of latitude and longtitude, I was able to do this:
folder_path = 'D:\path'
for filename in glob.glob(os.path.join(folder_path, '*.geo.json')):
with open(filename, 'r') as filecontent:
readme = filecontent.read()
lat = readme[21:28]
long = readme[40:47]
print(lat, long)
And I tought it was perfect for me, I got nice numbers like:
50.0918 14.4260
50.0920 4.42629
50.0918 14.4260
50.0917 14.4258
50.0920 14.4263
50.0917 14.4259
50.0918 14.4260
50.0919 4261233
But there is actualy numbers missing, the problem is in logs, the numbers generated for latitude/longtitude is not always same length and I print numbers from position of first character. I tried to print only numbers and split them by "," but there are more numbers I dont want there.
And here I am stucked, cant figure out how to print all numbers after "lat":
and "lng":
but not after "accuracy":
If you could help me it would make me happy, cheers.
You should use the json library to parse your .json
files:
import json
import glob
folder_path = 'D:\path'
for filename in glob.glob(os.path.join(folder_path, '*.geo.json')):
coords = json.load(open(filename, 'r'))
print(
coords['location']['lat'],
coords['location']['lng'],
coords['accuracy']
)
# 50.0918805 14.4261817 29.1671027