3
3
import csv
4
4
import datetime as dt
5
5
import os
6
- import pathlib
7
6
import sys
7
+ from pathlib import Path
8
8
9
9
from termcolor import cprint
10
10
11
11
12
- def load_csv (csv_file ) :
12
+ def load_csv (csv_file : str ) -> list [ dict [ str , str ]] :
13
13
data = []
14
14
15
15
with open (csv_file ) as csv_file :
@@ -24,7 +24,7 @@ def load_csv(csv_file):
24
24
return data
25
25
26
26
27
- def convert_date_string (input_string ) :
27
+ def convert_date_string (input_string : str ) -> str :
28
28
# May 22, 2010, 7:39:29 PM
29
29
# ->
30
30
# 20100522-193929
@@ -36,19 +36,19 @@ def convert_date_string(input_string):
36
36
return new_date
37
37
38
38
39
- def output_file (activity , ext = None ):
39
+ def output_file (activity : dict [ str , str ], ext : str | None = None ) -> Path :
40
40
# Return name like 20141207-152233-Ride.gpx
41
41
new_date = convert_date_string (activity ["Activity Date" ])
42
42
43
- path = pathlib . Path (activity ["Filename" ])
43
+ path = Path (activity ["Filename" ])
44
44
if not ext :
45
45
ext = "" .join (path .suffixes )
46
46
outfile = f"{ new_date } -{ activity ['Activity Type' ]} { ext } "
47
47
outfile = path .parent / outfile
48
48
return outfile
49
49
50
50
51
- if __name__ == "__main__" :
51
+ def main () -> None :
52
52
parser = argparse .ArgumentParser (
53
53
description = "Rename files, eg. 1836025202.gpx to 20180912-064451-Ride.gpx" ,
54
54
formatter_class = argparse .ArgumentDefaultsHelpFormatter ,
@@ -73,3 +73,7 @@ def output_file(activity, ext=None):
73
73
os .rename (activity ["Filename" ], outfile )
74
74
except FileNotFoundError :
75
75
cprint (f"File not found: { infile } " , "yellow" )
76
+
77
+
78
+ if __name__ == "__main__" :
79
+ main ()
0 commit comments