Skip to content

Commit

Permalink
fix log and progress bar (#664)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyNikiforov authored Jul 16, 2023
1 parent e6482c6 commit 64a913f
Show file tree
Hide file tree
Showing 11 changed files with 246 additions and 231 deletions.
7 changes: 3 additions & 4 deletions src/icloudpd/authentication.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Handles username/password authentication and two-step authentication"""

import logging
import sys
import click
import pyicloud_ipd
Expand All @@ -23,7 +22,7 @@ def authenticate_(
client_id=None,
):
"""Authenticate with iCloud username and password"""
logger.tqdm_write("Authenticating...", logging.DEBUG)
logger.debug("Authenticating...")
while True:
try:
# If password not provided on command line variable will be set to None
Expand All @@ -42,9 +41,9 @@ def authenticate_(
if icloud.requires_2sa:
if raise_error_on_2sa:
raise TwoStepAuthRequiredError(
"Two-step/two-factor authentication is required!"
"Two-step/two-factor authentication is required"
)
logger.info("Two-step/two-factor authentication is required!")
logger.info("Two-step/two-factor authentication is required")
request_2sa(icloud, logger)
return icloud
return authenticate_
Expand Down
15 changes: 7 additions & 8 deletions src/icloudpd/autodelete.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@
Delete any files found in "Recently Deleted"
"""
import os
import logging
from tzlocal import get_localzone
from icloudpd.paths import local_download_path


def delete_file(logger, path) -> bool:
""" Actual deletion of files """
os.remove(path)
logger.tqdm_write(f"Deleted {path}", logging.INFO)
logger.info("Deleted %s", path)
return True

def delete_file_dry_run(logger, path) -> bool:
""" Dry run deletion of files """
logger.tqdm_write(f"[DRY RUN] Would delete {path}", logging.INFO)
logger.info("[DRY RUN] Would delete %s", path)
return True

def autodelete_photos(logger, dry_run, icloud, folder_structure, directory):
Expand All @@ -24,17 +23,17 @@ def autodelete_photos(logger, dry_run, icloud, folder_structure, directory):
from the download directory.
(I.e. If you delete a photo on your phone, it's also deleted on your computer.)
"""
logger.tqdm_write("Deleting any files found in 'Recently Deleted'...", logging.INFO)
logger.info("Deleting any files found in 'Recently Deleted'...")

recently_deleted = icloud.photos.albums["Recently Deleted"]

for media in recently_deleted:
try:
created_date = media.created.astimezone(get_localzone())
except (ValueError, OSError):
logger.tqdm_write(
f"Could not convert media created date to local timezone {media.created}",
logging.ERROR)
logger.error(
"Could not convert media created date to local timezone %s",
media.created)
created_date = media.created

date_path = folder_structure.format(created_date)
Expand All @@ -45,6 +44,6 @@ def autodelete_photos(logger, dry_run, icloud, folder_structure, directory):
local_download_path(
media, size, download_dir))
if os.path.exists(path):
logger.tqdm_write(f"Deleting {path}...", logging.DEBUG)
logger.debug("Deleting %s...", path)
delete_local = delete_file_dry_run if dry_run else delete_file
delete_local(logger, path)
Loading

0 comments on commit 64a913f

Please sign in to comment.