Skip to content

Commit

Permalink
Merge pull request #11 from avibn/dev
Browse files Browse the repository at this point in the history
Version 2 improvements
  • Loading branch information
avibn authored Dec 17, 2024
2 parents f320532 + 11f0732 commit 7ee88b6
Show file tree
Hide file tree
Showing 17 changed files with 622 additions and 167 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ celerybeat.pid
.venv
env/
venv/
venv*/
ENV/
env.bak/
venv.bak/
Expand Down Expand Up @@ -164,4 +165,5 @@ cython_debug/
# Custom
testing/
bot-api/
downloads/
downloads/
*.session
28 changes: 23 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
# Use an official Python runtime as a parent image
FROM python:3.11.9-bookworm

# Install necessary packages
RUN apt-get update && apt-get install -y --no-install-recommends curl ca-certificates

# Add and run the UV installer script
ADD https://astral.sh/uv/0.5.9/install.sh /uv-installer.sh
RUN sh /uv-installer.sh && rm /uv-installer.sh

# Set environment variables
ENV PATH="/root/.local/bin/:$PATH"

# Set working directory in the container to /app
WORKDIR /app

# Add current directory contents into the container at /app
ADD . /app
# Enable bytecode compilation
ENV UV_COMPILE_BYTECODE=1

# Install the project's dependencies using the lockfile and settings
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --frozen --no-install-project --no-dev

# Install packages from requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
# Add the rest of the application code
ADD . /app
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-dev

# Start the bot
CMD ["python", "run.py"]
CMD ["uv", "run", "python", "run.py"]
19 changes: 17 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
[tool.black]
line-length = 88
[project]
name = "telegram-downloader"
version = "0.1.0"
description = "Telegram Bot to download video files sent to it"
readme = "README.md"
requires-python = ">=3.11"
dependencies = [
"pydantic-settings>=2.7.0",
"pydantic>=2.10.3",
"python-dotenv>=1.0.1",
"python-telegram-bot>=21.9",
]

[tool.uv]
dev-dependencies = [
"ruff>=0.8.3",
]
22 changes: 0 additions & 22 deletions requirements.txt

This file was deleted.

11 changes: 10 additions & 1 deletion run.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
from src.bot import main
import logging

# Enable logging
logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO
)
logging.getLogger("httpx").setLevel(logging.WARNING)


if __name__ == "__main__":
from src.bot import main

main()
27 changes: 4 additions & 23 deletions src/bot.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,11 @@
# Environment variables
from dotenv import load_dotenv

load_dotenv(override=True)

import logging
import os

from telegram import Update
from telegram.ext import Application, CommandHandler, ContextTypes

from .cogs import downloader_commands, error_handler, general_commands
from .utils import env

# Environment variables
BOT_TOKEN = os.getenv("BOT_TOKEN")
LOCAL_BOT_API_URL = os.getenv("LOCAL_BOT_API_URL")
BOT_API_DIR = os.getenv("BOT_API_DIR")
DOWNLOAD_TO_DIR = os.getenv("DOWNLOAD_TO_DIR")

if not all([BOT_TOKEN, LOCAL_BOT_API_URL, BOT_API_DIR, DOWNLOAD_TO_DIR]):
raise ValueError("Please set all environment variables in .env file")

# Enable logging
logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO
)
logging.getLogger("httpx").setLevel(logging.WARNING)
logger = logging.getLogger(__name__)


Expand All @@ -37,11 +18,11 @@ def main() -> None:
# Create the Application and pass it your bot's token.
application = (
Application.builder()
.token(BOT_TOKEN)
.token(env.BOT_TOKEN)
.concurrent_updates(True)
.local_mode(True)
.base_url(f"{LOCAL_BOT_API_URL}/bot")
.base_file_url(f"{LOCAL_BOT_API_URL}/file/bot")
.base_url(f"{env.LOCAL_BOT_API_URL}/bot")
.base_file_url(f"{env.LOCAL_BOT_API_URL}/file/bot")
.build()
)

Expand Down
Loading

0 comments on commit 7ee88b6

Please sign in to comment.