FEAT: Full AI Automation (Mail -> PDF -> Drive -> WebUI) [fixed venv bloat]

This commit is contained in:
Admin 2026-04-20 19:52:54 +04:00
parent f4ac98c6f4
commit f7c06fd471
3 changed files with 66 additions and 18 deletions

1
.gitignore vendored
View file

@ -5,6 +5,7 @@ __pycache__/
*.so *.so
.Python .Python
venv/ venv/
venv-google/
env/ env/
ENV/ ENV/
env.bak/ env.bak/

View file

@ -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

View file

@ -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"] file_id = msg["photo"][-1]["file_id"] if file_type == "photo" else msg["document"]["file_id"]
return file_id, file_type 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 = "🤖 <b>AI Синхронизация Успешна!</b>\n\n📄 Архив почты обновлен на Google Drive.\n👉 Не забудь нажать <b>'Sync'</b> в 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) @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: except Exception as e:
return JSONResponse(status_code=500, content={"message": str(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__": if __name__ == "__main__":
import uvicorn import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000) uvicorn.run(app, host="0.0.0.0", port=8000)