Skip to content

Commit

Permalink
Display download progress
Browse files Browse the repository at this point in the history
  • Loading branch information
GRWalter committed Jul 25, 2024
1 parent 4e2fce1 commit 9c3f40e
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/LocationHistory.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,15 @@ def GetDates(Dates: List[DT.date], AuthCookie: str, authuser: int, rapt: str) ->
raise Exception('You must specify at least one date.')

SortedDates = sorted(Dates)
total_dates = len(SortedDates)
current_date = 1
DisplayProgress(SortedDates[0], current_date, total_dates)

LocationHistory = GetDate(SortedDates[0], AuthCookie, authuser, rapt)

for Date in SortedDates[1:]:
current_date += 1
DisplayProgress(Date, current_date, total_dates)
try:
LocationHistory = Merge(LocationHistory, GetDate(Date, AuthCookie, authuser, rapt))
except:
Expand All @@ -99,10 +104,15 @@ def GetDateRange(StartDate: DT.date, EndDate: DT.date, AuthCookie: str, authuser
if EndDate < StartDate:
raise Exception('Start date cannot be later than end date.')

total_dates = (EndDate - StartDate).days
current_date = 1
DisplayProgress(StartDate, current_date, total_dates)
LocationHistory = GetDate(StartDate, AuthCookie, authuser, rapt)

for Delta in range((EndDate - StartDate).days):
for Delta in range(total_dates):
Date = StartDate + DT.timedelta(Delta + 1)
current_date += 1
DisplayProgress(Date, current_date, total_dates)
try:
LocationHistory = Merge(LocationHistory, GetDate(Date, AuthCookie, authuser, rapt))
except:
Expand Down Expand Up @@ -175,3 +185,8 @@ def RemoveErroneousAltitude(KmlTree: ET.ElementTree) -> None:
if Coordinates is not None and Coordinates.text is not None and re.search(RegEx, Coordinates.text):
# All altitudes are 0. Remove them.
Coordinates.text = re.sub(CoordinatesRegEx, '\\1', Coordinates.text)


def DisplayProgress(date: DT.date, current_download: int, total_downloads: int):
"""Display Current Progress"""
print(f'Downloading {date} | {current_download}/{total_downloads} | {current_download/total_downloads*100:.2f}%\r', end='', flush=True)

0 comments on commit 9c3f40e

Please sign in to comment.