40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
import yaml
|
|
import os
|
|
from typing import List
|
|
|
|
class Config:
|
|
def __init__(self, config_file: str = "config.yaml"):
|
|
self.config_file = config_file
|
|
self.load_config()
|
|
|
|
def load_config(self):
|
|
"""Load configuration from YAML file."""
|
|
if os.path.exists(self.config_file):
|
|
with open(self.config_file, 'r') as f:
|
|
config = yaml.safe_load(f)
|
|
else:
|
|
# Default configuration
|
|
config = {
|
|
'vat_patterns': [
|
|
'BE0?\\d{9}',
|
|
'NL\\d{9}B\\d{2}',
|
|
'DE\\d{9}',
|
|
'FR[A-Z0-9]{2}\\d{9}',
|
|
'GB\\d{9,12}'
|
|
],
|
|
'gmail_query': 'has:attachment filename:pdf',
|
|
'max_messages': 100,
|
|
'save_folder': 'invoices',
|
|
'log_level': 'INFO'
|
|
}
|
|
|
|
self.vat_patterns = config.get('vat_patterns', [])
|
|
self.gmail_query = config.get('gmail_query', 'has:attachment filename:pdf')
|
|
self.max_messages = config.get('max_messages', 100)
|
|
self.save_folder = config.get('save_folder', 'invoices')
|
|
self.log_level = config.get('log_level', 'INFO')
|
|
|
|
def get_vat_patterns(self) -> List[str]:
|
|
"""Get VAT number patterns as compiled regex patterns."""
|
|
return self.vat_patterns
|