parent
5279b99e39
commit
b4ae19aefb
|
|
@ -0,0 +1,20 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Zmienne środowiskowe
|
||||
DB_NAME="telegram_bot"
|
||||
DB_USER="telegram_user"
|
||||
DB_PASSWORD="telegram_pass"
|
||||
DB_PORT="5432"
|
||||
VOLUME_NAME="telegram_bot_pgdata"
|
||||
|
||||
export DATABASE_URL="postgresql://${DB_USER}:${DB_PASSWORD}@localhost:${DB_PORT}/${DB_NAME}"
|
||||
|
||||
docker run \
|
||||
--name "${CONTAINER_NAME}" \
|
||||
-e POSTGRES_DB="${DB_NAME}" \
|
||||
-e POSTGRES_USER="${DB_USER}" \
|
||||
-e POSTGRES_PASSWORD="${DB_PASSWORD}" \
|
||||
-p "${DB_PORT}:5432" \
|
||||
--restart unless-stopped \
|
||||
-d \
|
||||
postgres:14-alpine
|
||||
6
main.py
6
main.py
|
|
@ -2,9 +2,9 @@ import asyncio
|
|||
import logging
|
||||
from telegram import Update
|
||||
from telegram.ext import ApplicationBuilder, MessageHandler, filters, CommandHandler
|
||||
from .src.config import TELEGRAM_BOT_TOKEN, logger # Import logger z config
|
||||
from .src.handlers import handle_message, error_handler
|
||||
from .src.db import init_db, close_db
|
||||
from src.config import TELEGRAM_BOT_TOKEN, logger # Import logger z config
|
||||
from src.handlers import handle_message, error_handler
|
||||
from src.db import init_db, close_db
|
||||
|
||||
async def post_init(application):
|
||||
"""Funkcja wykonywana po inicjalizacji aplikacji bota."""
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import re
|
|||
from telegram import Update
|
||||
from telegram.ext import ContextTypes
|
||||
from telegram.constants import ParseMode
|
||||
from .youtube_utils import extract_youtube_urls, extract_video_id, get_transcript, get_video_title
|
||||
from .youtube_utils import extract_youtube_urls, extract_video_id, get_transcript
|
||||
from .openai_utils import summarize_text
|
||||
from .db import save_video_summary, check_if_url_exists
|
||||
from .config import TRANSCRIPT_LANGUAGES
|
||||
|
|
@ -52,27 +52,17 @@ async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|||
|
||||
await context.bot.send_chat_action(chat_id=chat_id, action='typing')
|
||||
|
||||
# 1. Pobierz tytuł
|
||||
title = await get_video_title(url)
|
||||
# Pobierz transkrypcję i tytuł
|
||||
try:
|
||||
transcript, title = await get_transcript(video_id, TRANSCRIPT_LANGUAGES)
|
||||
if not title:
|
||||
logger.warning(f"Nie udało się pobrać tytułu dla ID filmu: {video_id}")
|
||||
title = f"Film YouTube {video_id}" # Użyj zastępczego tytułu
|
||||
except Exception as e:
|
||||
logger.warning(f"Nie udało się pobrać transkrypcji dla ID filmu: {video_id}: {str(e)}")
|
||||
await context.bot.send_message(
|
||||
chat_id=chat_id,
|
||||
text=f"Nie udało się pobrać tytułu dla filmu: {url}",
|
||||
disable_web_page_preview=True
|
||||
)
|
||||
processed_urls_in_message.add(url)
|
||||
continue # Potrzebujemy tytułu
|
||||
|
||||
await context.bot.send_chat_action(chat_id=chat_id, action='typing')
|
||||
|
||||
# 2. Pobierz transkrypcję
|
||||
transcript = await get_transcript(video_id, TRANSCRIPT_LANGUAGES)
|
||||
if not transcript:
|
||||
logger.warning(f"Nie udało się pobrać transkrypcji dla ID filmu: {video_id}")
|
||||
await context.bot.send_message(
|
||||
chat_id=chat_id,
|
||||
text=f"Nie udało się pobrać transkrypcji dla filmu: {title} ({url})",
|
||||
text=f"Nie udało się pobrać transkrypcji dla filmu: {url}",
|
||||
disable_web_page_preview=True
|
||||
)
|
||||
processed_urls_in_message.add(url)
|
||||
|
|
@ -80,7 +70,7 @@ async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|||
|
||||
await context.bot.send_chat_action(chat_id=chat_id, action='typing')
|
||||
|
||||
# 3. Wygeneruj streszczenie
|
||||
# Wygeneruj streszczenie
|
||||
summary = await summarize_text(transcript)
|
||||
if not summary:
|
||||
logger.error(f"Nie udało się wygenerować streszczenia dla ID filmu: {video_id}")
|
||||
|
|
@ -92,7 +82,7 @@ async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|||
processed_urls_in_message.add(url)
|
||||
continue
|
||||
|
||||
# 4. Zapisz do bazy danych
|
||||
# Zapisz do bazy danych
|
||||
saved = await save_video_summary(url, title, transcript, summary)
|
||||
if saved:
|
||||
logger.info(f"Pomyślnie przetworzono i zapisano film: {title} ({url})")
|
||||
|
|
|
|||
Loading…
Reference in New Issue