Skip to content

Commit 5ef2d1e

Browse files
committed
Add type hints
1 parent b5a9edc commit 5ef2d1e

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

rename_activities.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
import csv
44
import datetime as dt
55
import os
6-
import pathlib
76
import sys
7+
from pathlib import Path
88

99
from termcolor import cprint
1010

1111

12-
def load_csv(csv_file):
12+
def load_csv(csv_file: str) -> list[dict[str, str]]:
1313
data = []
1414

1515
with open(csv_file) as csv_file:
@@ -24,7 +24,7 @@ def load_csv(csv_file):
2424
return data
2525

2626

27-
def convert_date_string(input_string):
27+
def convert_date_string(input_string: str) -> str:
2828
# May 22, 2010, 7:39:29 PM
2929
# ->
3030
# 20100522-193929
@@ -36,19 +36,19 @@ def convert_date_string(input_string):
3636
return new_date
3737

3838

39-
def output_file(activity, ext=None):
39+
def output_file(activity: dict[str, str], ext: str | None = None) -> Path:
4040
# Return name like 20141207-152233-Ride.gpx
4141
new_date = convert_date_string(activity["Activity Date"])
4242

43-
path = pathlib.Path(activity["Filename"])
43+
path = Path(activity["Filename"])
4444
if not ext:
4545
ext = "".join(path.suffixes)
4646
outfile = f"{new_date}-{activity['Activity Type']}{ext}"
4747
outfile = path.parent / outfile
4848
return outfile
4949

5050

51-
if __name__ == "__main__":
51+
def main() -> None:
5252
parser = argparse.ArgumentParser(
5353
description="Rename files, eg. 1836025202.gpx to 20180912-064451-Ride.gpx",
5454
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
@@ -73,3 +73,7 @@ def output_file(activity, ext=None):
7373
os.rename(activity["Filename"], outfile)
7474
except FileNotFoundError:
7575
cprint(f"File not found: {infile}", "yellow")
76+
77+
78+
if __name__ == "__main__":
79+
main()

0 commit comments

Comments
 (0)