Skip to content

Commit

Permalink
Merge pull request #7 from w1tnessbtwwwww/future
Browse files Browse the repository at this point in the history
Future
  • Loading branch information
w1tnessbtwwwww authored Dec 19, 2024
2 parents 6ee85c0 + f81608b commit aefb311
Show file tree
Hide file tree
Showing 22 changed files with 102 additions and 350 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Deployment

on:
push:
branches:
- develop
- master
pull_request:
branches:
- master


jobs:
Deploy:
runs-on: self-hosted
steps:
- name: Downloading repository
uses: actions/checkout@v4

- name: Copy .env file
run: |
echo "${{ secrets.QUOTE_ENV }}" > .env
- name: Run docker-compose.yml
run: |
make deploy
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@

.DS_Store

temp_quotes/



*.log
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
dev:
poetry run python main.py

deploy:
docker-compose -f docker/docker-compose.yml --project-directory . up --build -d

deploydebug:
docker-compose -f docker/docker-compose.yml --project-directory . up --build
Binary file removed app/cfg/__pycache__/settings.cpython-312.pyc
Binary file not shown.
2 changes: 2 additions & 0 deletions app/cfg/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
class Settings(BaseSettings):
TELEGRAM_TOKEN: str

class Config:
env_file = '.env'

settings = Settings()
Binary file removed app/quote_module/__pycache__/quote.cpython-312.pyc
Binary file not shown.
Binary file not shown.
3 changes: 2 additions & 1 deletion app/quote_module/models/quote_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@


class QuoteModel:
def __init__(self, quote: str, author: str):
def __init__(self, quote: str, author: str, avatar:str):
self.quote = quote
self.author = author
self.avatar = avatar

@property
def wrapped_quote(self, chunk_size=50):
Expand Down
9 changes: 4 additions & 5 deletions app/quote_module/quote.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from app.quote_module.models.quote_model import QuoteModel
from app.utils.result.result import Result, err, success
from app.utils.logger.logger import logger
from PIL import Image, ImageDraw, ImageFont
import textwrap

Expand Down Expand Up @@ -36,7 +35,7 @@ def create_avatar_circle(size, border_color='black', border_width=2):
def paste_avatar(image, avatar, position):
image.paste(avatar, position, avatar)

def generate_image(quote_text: str, author_name: str) -> Result[None]:
def generate_image(quote_text: str, author_name: str, avatar:str) -> Result[None]:
title_font = ImageFont.truetype("app/quote_module/media/Roboto-Medium.ttf", 24)
quote_font = ImageFont.truetype("app/quote_module/media/Roboto-Medium.ttf", 20)
author_font = ImageFont.truetype("app/quote_module/media/Roboto-Medium.ttf", 16)
Expand Down Expand Up @@ -73,17 +72,17 @@ def generate_image(quote_text: str, author_name: str) -> Result[None]:

author_position = (padding + avatar_size + padding, height - author_height - padding)
add_text(image, author_text, author_font, author_position)

avatar = create_avatar_circle(avatar_size)
avatar_position = (50, height - avatar_size - 50)
# paste_avatar(image, f"{author_name}_avatar.png", avatar_position)
paste_avatar(image, f"{author_name}_avatar.png", avatar_position)


image.save(f'temp_quotes/{author_name.replace("@", "")}.png')
image.close()
def generate_quote(quote: QuoteModel) -> Result[None]:
try:
generate_image(quote.wrapped_quote, quote.author)
generate_image(quote.wrapped_quote, quote.author, quote.avatar)
return success(None)
except Exception as e:
print(e)
Expand Down
Binary file modified app/utils/__pycache__/get_user_avatar.cpython-312.pyc
Binary file not shown.
Binary file not shown.
Binary file modified app/utils/logger/__pycache__/logger.cpython-312.pyc
Binary file not shown.
8 changes: 0 additions & 8 deletions app/utils/logger/logger.py

This file was deleted.

Binary file not shown.
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.12.7-slim-bullsey
FROM python:3.12.7-slim-bullseye

RUN apt-get update && apt-get install -y \
gcc \
Expand Down
4 changes: 2 additions & 2 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@


services:
quoteGen:
container_name: quoteGen
quote_gen:
container_name: quote_gen
build:
context: .
dockerfile: docker/Dockerfile
Expand Down
150 changes: 0 additions & 150 deletions logs/2024-12-16.log

This file was deleted.

177 changes: 0 additions & 177 deletions logs/2024-12-17.log

This file was deleted.

22 changes: 18 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import asyncio
import os
import telebot
import requests
from telebot.types import Message
from telebot.types import UserProfilePhotos

import logging

from app.quote_module.models.quote_model import QuoteModel
from app.utils.get_user_avatar import get_user_avatar
Expand All @@ -19,12 +19,26 @@

@bot.message_handler(func=lambda message: True)
def handle_all_messages(message: telebot.types.Message):

logging.info(f"Received message: {message}")

if message.forward_from or message.forward_from_chat:
user_id = message.forward_from.id
try:
photos = bot.get_user_profile_photos(user_id)
if photos.total_count > 0:
file_id = photos.photos[0][-1].file_id
file_info = bot.get_file(file_id)
file_path = file_info.file_path
file_url = f"https://api.telegram.org/file/bot{settings.TELEGRAM_TOKEN}/{file_path}"
response = requests.get(file_url)
if response.status_code == 200:
with open(f"{message.forward_from.full_name}_avatar.png", "wb") as file:
file.write(response.content)
else:
bot.send_message(message.chat.id, "Не удалось скачать аватар")
except Exception as e:
bot.reply_to(message, f"Ошибка!")
# avatar = get_user_avatar(message.forward_from.username, message.forward_from.id, bot)
image = generate_quote(QuoteModel(message.any_text, message.forward_from.username))
image = generate_quote(QuoteModel(message.any_text, message.forward_from.username, f"{message.forward_from.full_name}"))
if image.success:
with open(f"temp_quotes/{message.forward_from.username}.png", "rb") as photo:
bot.send_photo(message.chat.id, photo)
Expand Down
36 changes: 35 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ telebot = "^0.0.5"
pydantic = "^2.10.3"
pillow = "^11.0.0"
pytelegrambotapi = "^4.25.0"
pydantic-settings = "^2.7.0"


[build-system]
Expand Down
Empty file added temp_quotes/hold.bat
Empty file.

0 comments on commit aefb311

Please sign in to comment.