Remove unused imports and fix trailing whitespace

This commit is contained in:
JoelShepard
2025-05-31 14:52:18 +02:00
parent 4d3b167c28
commit f78610e104

23
main.py
View File

@@ -13,8 +13,6 @@ from pathlib import Path
import argparse import argparse
import requests import requests
from requests.auth import HTTPBasicAuth from requests.auth import HTTPBasicAuth
import sys
import os
from xml.etree import ElementTree as ET from xml.etree import ElementTree as ET
from config import get_webdav_config from config import get_webdav_config
@@ -318,6 +316,11 @@ def clear_webdav_directory():
WEBDAV_USERNAME = webdav_config['username'] WEBDAV_USERNAME = webdav_config['username']
WEBDAV_PASSWORD = webdav_config['password'] WEBDAV_PASSWORD = webdav_config['password']
# Validate credentials
if not WEBDAV_USERNAME or not WEBDAV_PASSWORD:
print("Error: WebDAV username or password not configured")
return False
auth = HTTPBasicAuth(WEBDAV_USERNAME, WEBDAV_PASSWORD) auth = HTTPBasicAuth(WEBDAV_USERNAME, WEBDAV_PASSWORD)
print("Clearing WebDAV directory...") print("Clearing WebDAV directory...")
@@ -354,7 +357,7 @@ def clear_webdav_directory():
print(f"✗ Failed to delete: {filename}") print(f"✗ Failed to delete: {filename}")
failed_count += 1 failed_count += 1
print(f"\nCleanup Summary:") print("\nCleanup Summary:")
print(f"✓ Files deleted: {deleted_count}") print(f"✓ Files deleted: {deleted_count}")
print(f"✗ Failed deletions: {failed_count}") print(f"✗ Failed deletions: {failed_count}")
@@ -377,10 +380,16 @@ def upload_files_to_webdav(file_paths):
WEBDAV_USERNAME = webdav_config['username'] WEBDAV_USERNAME = webdav_config['username']
WEBDAV_PASSWORD = webdav_config['password'] WEBDAV_PASSWORD = webdav_config['password']
# Validate credentials
if not WEBDAV_USERNAME or not WEBDAV_PASSWORD:
print("Error: WebDAV username or password not configured")
return [], file_paths
successful_uploads = [] successful_uploads = []
failed_uploads = [] failed_uploads = []
for file_path in file_paths: for file_path in file_paths:
filename = None # Initialize filename variable
try: try:
# Get the filename from the local path # Get the filename from the local path
filename = Path(file_path).name filename = Path(file_path).name
@@ -421,10 +430,12 @@ def upload_files_to_webdav(file_paths):
failed_uploads.append(file_path) failed_uploads.append(file_path)
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:
print(f"✗ Network error uploading {filename}: {e}") display_filename = filename if filename else Path(file_path).name
print(f"✗ Network error uploading {display_filename}: {e}")
failed_uploads.append(file_path) failed_uploads.append(file_path)
except Exception as e: except Exception as e:
print(f"✗ Unexpected error uploading {filename}: {e}") display_filename = filename if filename else Path(file_path).name
print(f"✗ Unexpected error uploading {display_filename}: {e}")
failed_uploads.append(file_path) failed_uploads.append(file_path)
return successful_uploads, failed_uploads return successful_uploads, failed_uploads
@@ -491,7 +502,7 @@ def main():
successful, failed = upload_files_to_webdav(generated_files) successful, failed = upload_files_to_webdav(generated_files)
print(f"\nUpload Summary:") print("\nUpload Summary:")
print(f"✓ Successful uploads: {len(successful)}") print(f"✓ Successful uploads: {len(successful)}")
print(f"✗ Failed uploads: {len(failed)}") print(f"✗ Failed uploads: {len(failed)}")