diff --git a/.gitignore b/.gitignore
index 5b1240f..1223251 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,6 +5,7 @@ __pycache__/
*.so
.Python
venv/
+venv-google/
env/
ENV/
env.bak/
diff --git a/services/email_auditor/auto_sync_pipeline.sh b/services/email_auditor/auto_sync_pipeline.sh
new file mode 100755
index 0000000..6365bec
--- /dev/null
+++ b/services/email_auditor/auto_sync_pipeline.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+# -----------------------------------------------------------------------------
+# DOMOVOY AI PIPELINE: MAIL -> PDF -> DRIVE -> TELEGRAM
+# -----------------------------------------------------------------------------
+
+BASE_DIR="/home/matrixhasyou/domovoy_bot"
+BOT_PYTHON="python3" # Используем системный питон (там imap-tools)
+GOOGLE_PYTHON="$BASE_DIR/venv-google/bin/python"
+LOG_FILE="$BASE_DIR/services/email_auditor/pipeline.log"
+
+echo "[$(date)] >>> СТАРТ ПАЙПЛАЙНА" >> $LOG_FILE
+
+# 1. Запуск экспорта почты (mutt -> PDF)
+echo "[$(date)] >>> Экспорт почты..." >> $LOG_FILE
+cd $BASE_DIR
+$BOT_PYTHON services/email_auditor/export_emails_v2.py >> $LOG_FILE 2>&1
+
+# 2. Даем права на всякий случай
+chmod +x /home/matrixhasyou/domovoy_drive_sync.py
+
+# 3. Загрузка в Google Drive
+echo "[$(date)] >>> Загрузка на Google Drive..." >> $LOG_FILE
+$GOOGLE_PYTHON /home/matrixhasyou/domovoy_drive_sync.py >> $LOG_FILE 2>&1
+
+if [ $? -eq 0 ]; then
+ echo "[$(date)] >>> УСПЕХ: Пайплайн завершен." >> $LOG_FILE
+else
+ echo "[$(date)] >>> ОШИБКА в пайплайне." >> $LOG_FILE
+fi
diff --git a/web/app.py b/web/app.py
index 9abe161..ed1a79a 100644
--- a/web/app.py
+++ b/web/app.py
@@ -115,8 +115,43 @@ async def upload_to_tg(content, filename, content_type):
file_id = msg["photo"][-1]["file_id"] if file_type == "photo" else msg["document"]["file_id"]
return file_id, file_type
+@app.post("/api/emails/sync_ai")
+async def api_sync_emails_to_ai(username: str = Depends(get_current_admin)):
+ sync_script = "/home/matrixhasyou/domovoy_drive_sync.py"
+ python_path = "/home/matrixhasyou/domovoy_bot/venv-google/bin/python"
+
+ try:
+ # Запуск синхронизации
+ process = subprocess.run(
+ [python_path, sync_script],
+ capture_output=True, text=True, timeout=300
+ )
+
+ if process.returncode == 0:
+ # Уведомляем админа в ТГ
+ msg = "🤖 AI Синхронизация Успешна!\n\n📄 Архив почты обновлен на Google Drive.\n👉 Не забудь нажать 'Sync' в NotebookLM!"
+
+ # Отправка через API Telegram (упрощенно)
+ async with aiohttp.ClientSession() as session:
+ url = f"https://api.telegram.org/bot{config.BOT_TOKEN}/sendMessage"
+ params = {
+ "chat_id": config.ADMIN_USER_ID,
+ "text": msg,
+ "parse_mode": "HTML"
+ }
+ # Используем прокси если нужно
+ proxy = f"http://{config.PROXY_HOST}:{config.PROXY_PORT}" if config.USE_PROXY else None
+ await session.get(url, params=params, proxy=proxy)
+
+ return {"success": True, "message": "Синхронизация завершена, уведомление отправлено."}
+ else:
+ return {"success": False, "error": process.stderr or process.stdout}
+
+ except Exception as e:
+ return JSONResponse(status_code=500, content={"success": False, "error": str(e)})
+
# ============================================================================
-# ГЛАВНАЯ (DASHBOARD)
+# ГЛАВНАЯ ПАНЕЛЬ (DASHBOARD)
# ============================================================================
@app.get("/", response_class=HTMLResponse)
@@ -546,23 +581,6 @@ async def api_run_email_audit(username: str = Depends(get_current_admin)):
except Exception as e:
return JSONResponse(status_code=500, content={"message": str(e)})
-@app.post("/api/emails/sync_ai")
-async def api_sync_email_ai(username: str = Depends(get_current_admin)):
- script_path = BASE_DIR / "services" / "email_auditor" / "sync_helper.py"
- venv_python = BASE_DIR / "venv" / "bin" / "python3"
- if not script_path.exists(): return JSONResponse(status_code=404, content={"message": "Sync script not found"})
- try:
- env = os.environ.copy()
- env["PYTHONPATH"] = str(BASE_DIR)
- # Запускаем скрипт синхронизации
- result = subprocess.run([str(venv_python), str(script_path)], capture_output=True, text=True, env=env)
- if result.returncode == 0:
- return JSONResponse(content={"message": result.stdout.strip()})
- else:
- return JSONResponse(status_code=500, content={"message": f"Ошибка: {result.stderr}"})
- except Exception as e:
- return JSONResponse(status_code=500, content={"message": str(e)})
-
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)