🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
58 lines
1.6 KiB
Python
58 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Configuration module for Kindle Clippings Parser
|
|
"""
|
|
|
|
import os
|
|
import json
|
|
from pathlib import Path
|
|
|
|
|
|
def load_config():
|
|
"""
|
|
Load configuration from config.json file or environment variables.
|
|
|
|
Returns:
|
|
dict: Configuration dictionary with WebDAV settings
|
|
"""
|
|
config = {}
|
|
|
|
# Try to load from config.json first
|
|
config_file = Path("config.json")
|
|
if config_file.exists():
|
|
try:
|
|
with open(config_file, 'r', encoding='utf-8') as f:
|
|
config = json.load(f)
|
|
except (json.JSONDecodeError, IOError) as e:
|
|
print(f"Warning: Could not load config.json: {e}")
|
|
config = {}
|
|
|
|
# Override with environment variables if they exist
|
|
webdav_config = {
|
|
'base_url': config.get('webdav', {}).get('base_url') or os.getenv('WEBDAV_BASE_URL'),
|
|
'username': config.get('webdav', {}).get('username') or os.getenv('WEBDAV_USERNAME'),
|
|
'password': config.get('webdav', {}).get('password') or os.getenv('WEBDAV_PASSWORD')
|
|
}
|
|
|
|
# Validate required settings
|
|
missing_settings = [key for key, value in webdav_config.items() if not value]
|
|
if missing_settings:
|
|
raise ValueError(
|
|
f"Missing required WebDAV configuration: {', '.join(missing_settings)}. "
|
|
"Please provide them in config.json or as environment variables."
|
|
)
|
|
|
|
return {
|
|
'webdav': webdav_config
|
|
}
|
|
|
|
|
|
def get_webdav_config():
|
|
"""
|
|
Get WebDAV configuration.
|
|
|
|
Returns:
|
|
dict: WebDAV configuration with base_url, username, password
|
|
"""
|
|
config = load_config()
|
|
return config['webdav'] |