add: formating
This commit is contained in:
parent
6f54ae20c7
commit
ea47212342
|
@ -1,5 +1,4 @@
|
||||||
gpx/
|
gpx/
|
||||||
old/
|
|
||||||
new/
|
*.gpx
|
||||||
keep/
|
|
||||||
.python-version
|
.python-version
|
52
huawei.py
52
huawei.py
|
@ -4,33 +4,26 @@ import gpxpy.gpx
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from geopy.distance import geodesic
|
from geopy.distance import geodesic
|
||||||
|
|
||||||
start_time = {
|
start_time = ['2022-02-22 17:42', '2022-02-24 19:44']
|
||||||
'20190625骑行.gpx': '2019-06-25 16:48',
|
|
||||||
'20190627骑行.gpx': '2019-06-27 19:42',
|
|
||||||
'20190705骑行.gpx': '2019-07-05 18:26',
|
|
||||||
'20190706骑行.gpx': '2019-07-06 19:37',
|
|
||||||
'20190709骑行.gpx': '2019-07-09 18:25',
|
|
||||||
'20190912跑步.gpx': '2019-09-12 18:03',
|
|
||||||
'20190915跑步.gpx': '2019-09-15 21:02',
|
|
||||||
'20190916跑步.gpx': '2019-09-16 21:38',
|
|
||||||
'20190920跑步.gpx': '2019-09-20 21:36',
|
|
||||||
'20190928跑步.gpx': '2019-09-28 22:41',
|
|
||||||
'20190930跑步.gpx': '2019-09-30 21:27',
|
|
||||||
'20191001跑步.gpx': '2019-10-01 17:12',
|
|
||||||
'20191006跑步.gpx': '2019-10-06 18:10',
|
|
||||||
'20191010跑步.gpx': '2019-10-10 22:06',
|
|
||||||
'20191011跑步.gpx': '2019-10-11 21:52',
|
|
||||||
'20191020跑步.gpx': '2019-10-20 18:08',
|
|
||||||
'20191030跑步.gpx': '2019-10-30 10:47',
|
|
||||||
'20191103跑步.gpx': '2019-11-03 17:16',
|
|
||||||
'20191107跑步.gpx': '2019-11-07 21:33',
|
|
||||||
'20191108跑步.gpx': '2019-11-08 22:14',
|
|
||||||
'20200321跑步.gpx': '2020-03-21 19:27',
|
|
||||||
'20200828骑行.gpx': '2020-08-28 22:19'
|
|
||||||
}
|
|
||||||
|
|
||||||
|
old = '<gpx creator="Health" xsi:schemaLocation="http://www.topografix.com/GPX/1/0 \
|
||||||
|
http://www.topografix.com/GPX/1/0/gpx.xsd" version="1.0" \
|
||||||
|
xmlns="http://www.topografix.com/GPX/1/0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
|
||||||
|
new = '<gpx xmlns="http://www.topografix.com/GPX/1/1" \
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" \
|
||||||
|
xsi:schemaLocation="http://www.topografix.com/GPX/1/1 \
|
||||||
|
http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" \
|
||||||
|
creator="gpx.py -- https://github.com/tkrajina/gpxpy">\n'
|
||||||
|
|
||||||
def process(file):
|
def file_format(file):
|
||||||
|
f = open('./old/'+file, 'r', encoding='utf-8')
|
||||||
|
s = f.readline()
|
||||||
|
s = s.replace(old, new)
|
||||||
|
s = '<?xml version="1.0" encoding="UTF-8"?>\n' + s
|
||||||
|
with open('./old/'+file, 'w', encoding='utf-8') as f:
|
||||||
|
f.write(s)
|
||||||
|
|
||||||
|
def process(file, index):
|
||||||
gpx_file = open('./old/'+file, 'r', encoding='utf-8')
|
gpx_file = open('./old/'+file, 'r', encoding='utf-8')
|
||||||
gpx = gpxpy.parse(gpx_file)
|
gpx = gpxpy.parse(gpx_file)
|
||||||
|
|
||||||
|
@ -53,7 +46,7 @@ def process(file):
|
||||||
gpx_track.segments.append(gpx_segment)
|
gpx_track.segments.append(gpx_segment)
|
||||||
|
|
||||||
p = None
|
p = None
|
||||||
time0 = datetime.strptime(start_time[file], '%Y-%m-%d %H:%M') - timedelta(hours=8)
|
time0 = datetime.strptime(start_time[index], '%Y-%m-%d %H:%M') - timedelta(hours=8)
|
||||||
for track in gpx.tracks:
|
for track in gpx.tracks:
|
||||||
for segment in track.segments:
|
for segment in track.segments:
|
||||||
for point in segment.points:
|
for point in segment.points:
|
||||||
|
@ -72,7 +65,8 @@ def process(file):
|
||||||
with open('./new/'+file, 'w', encoding='utf-8') as f:
|
with open('./new/'+file, 'w', encoding='utf-8') as f:
|
||||||
f.write(ngpx.to_xml())
|
f.write(ngpx.to_xml())
|
||||||
|
|
||||||
|
|
||||||
files = os.listdir('./old')
|
files = os.listdir('./old')
|
||||||
for file in files:
|
for k in range(len(files)):
|
||||||
process(file)
|
file_format(files[k])
|
||||||
|
process(files[k], k)
|
||||||
|
os.remove('./old/' + files[k])
|
||||||
|
|
Reference in New Issue