From ea4721234268f15789ccb57be1efc0db642eed63 Mon Sep 17 00:00:00 2001 From: YiHui Liu Date: Thu, 10 Mar 2022 17:31:45 +0800 Subject: [PATCH] add: formating --- .gitignore | 5 ++--- huawei.py | 52 +++++++++++++++++++++++----------------------------- 2 files changed, 25 insertions(+), 32 deletions(-) diff --git a/.gitignore b/.gitignore index d387767..6f9aead 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ gpx/ -old/ -new/ -keep/ + +*.gpx .python-version \ No newline at end of file diff --git a/huawei.py b/huawei.py index 2d6156f..8633317 100644 --- a/huawei.py +++ b/huawei.py @@ -4,33 +4,26 @@ import gpxpy.gpx from datetime import datetime, timedelta from geopy.distance import geodesic -start_time = { - '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' -} +start_time = ['2022-02-22 17:42', '2022-02-24 19:44'] +old = '' +new = '\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 = '\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 = gpxpy.parse(gpx_file) @@ -53,7 +46,7 @@ def process(file): gpx_track.segments.append(gpx_segment) 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 segment in track.segments: for point in segment.points: @@ -72,7 +65,8 @@ def process(file): with open('./new/'+file, 'w', encoding='utf-8') as f: f.write(ngpx.to_xml()) - files = os.listdir('./old') -for file in files: - process(file) +for k in range(len(files)): + file_format(files[k]) + process(files[k], k) + os.remove('./old/' + files[k])