mirror of
https://github.com/marcogll/telegram_expenses_controller.git
synced 2026-01-13 21:35:15 +00:00
feat: Implement core application structure, AI extraction, persistence, and Telegram bot modules with updated configuration and dependencies.
This commit is contained in:
0
app/audit/__init__.py
Normal file
0
app/audit/__init__.py
Normal file
28
app/audit/logs.py
Normal file
28
app/audit/logs.py
Normal file
@@ -0,0 +1,28 @@
|
||||
"""
|
||||
Logging configuration and handlers.
|
||||
"""
|
||||
import logging
|
||||
import sys
|
||||
from app.config import config
|
||||
|
||||
def setup_logging():
|
||||
"""
|
||||
Sets up a centralized logging configuration for the application.
|
||||
"""
|
||||
log_level = config.LOG_LEVEL.upper()
|
||||
|
||||
# Remove any existing handlers
|
||||
for handler in logging.root.handlers[:]:
|
||||
logging.root.removeHandler(handler)
|
||||
|
||||
logging.basicConfig(
|
||||
level=log_level,
|
||||
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
||||
stream=sys.stdout
|
||||
)
|
||||
logging.getLogger("sqlalchemy.engine").setLevel(logging.WARNING)
|
||||
logging.getLogger("uvicorn.access").setLevel(logging.WARNING)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.info(f"Logging configured with level {log_level}")
|
||||
|
||||
38
app/audit/raw_storage.py
Normal file
38
app/audit/raw_storage.py
Normal file
@@ -0,0 +1,38 @@
|
||||
"""
|
||||
Handles storage of raw, original input files for audit purposes.
|
||||
"""
|
||||
import logging
|
||||
import os
|
||||
from uuid import uuid4
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# A simple file-based storage. In production, you'd use S3 or a similar service.
|
||||
RAW_STORAGE_PATH = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "raw_storage")
|
||||
os.makedirs(RAW_STORAGE_PATH, exist_ok=True)
|
||||
|
||||
|
||||
def save_raw_input(data: bytes, input_type: str) -> str:
|
||||
"""
|
||||
Saves the original input data to a file.
|
||||
|
||||
Args:
|
||||
data: The raw bytes of the input.
|
||||
input_type: The type of input (e.g., 'image', 'audio').
|
||||
|
||||
Returns:
|
||||
The path to the saved file.
|
||||
"""
|
||||
try:
|
||||
file_extension = input_type # e.g., 'jpg', 'mp3'
|
||||
file_name = f"{uuid4()}.{file_extension}"
|
||||
file_path = os.path.join(RAW_STORAGE_PATH, file_name)
|
||||
|
||||
with open(file_path, "wb") as f:
|
||||
f.write(data)
|
||||
|
||||
logger.info(f"Saved raw input to {file_path}")
|
||||
return file_path
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to save raw input: {e}")
|
||||
return ""
|
||||
Reference in New Issue
Block a user