Skip to content

Commit

Permalink
convert to template
Browse files Browse the repository at this point in the history
  • Loading branch information
taimast committed Jan 19, 2024
1 parent 615d540 commit 1b8da89
Show file tree
Hide file tree
Showing 103 changed files with 99 additions and 188 deletions.
File renamed without changes.
28 changes: 15 additions & 13 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,25 @@ on:
- master

jobs:
python-ckecks:
build-and-deploy:

runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
- name: Deploy to Server
uses: appleboy/[email protected]
with:
python-version: 3.11

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8
host: ${{ secrets.SERVER_IP }}
username: ${{ secrets.SERVER_USERNAME }}
# key: ${{ secrets.SSH_PRIVATE_KEY }}
password: ${{ secrets.SERVER_PASSWORD }}
script: |
cd /home/src
git pull
docker compose stop
docker compose up --build -d
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 ./project --count --select=E9,F63,F7,F82 --show-source --statistics
# todo L1 TODO 21.05.2023 15:31 taima: Add python syntax check to CI
19 changes: 0 additions & 19 deletions .github/workflows/qodana_code_quality.yml

This file was deleted.

5 changes: 0 additions & 5 deletions .pre-commit-config.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion project/Dockerfile → Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ FROM ghcr.io/withlogicco/poetry:1.7.0-python-3.12
WORKDIR /app
COPY pyproject.toml ./
RUN poetry install --no-root --without dev
COPY crying crying
COPY src src
COPY README.md README.md
ENV PYTHONPATH=/app
21 changes: 16 additions & 5 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,21 @@ To initialize the project, run the script `init_project.py `, example: `python3
## Localization

[Fluent] is used for localization(https://projectfluent.org/fluent/guide /).
By default, the folder with localizations is located at the path `crying/locales'.
By default, the folder with localizations is located at the path `src/locales'.

## _utilities_
- `project/crying/utils/ftl_parser_cli.py ` - Live generation of stubs for localization.
- `project/crying/utils/ftl_translator.py ` - Automatic localization translation into all languages via Google Translate and ftl generation.
- `project/crying/apps/bot/callback_data/paginator.py ` - Paginator of pages for InlineKeyboardMarkup.
- `project/crying/db/models/user/mixins.py ` - Mixins for user models. At the moment, for Referrals and Connecting users to each other through a bot. (Example of connection in `helpers/connect')
- `src/utils/ftl_parser_cli.py ` - Live generation of stubs for localization.
- `src/utils/ftl_translator.py ` - Automatic localization translation into all languages via Google Translate and ftl generation.
- `src/apps/bot/callback_data/paginator.py ` - Paginator of pages for InlineKeyboardMarkup.
- `src/db/models/user/mixins.py ` - Mixins for user models. At the moment, for Referrals and Connecting users to each other through a bot. (Example of connection in `helpers/connect')


### Установка

1. Заполнить `config.yml`
2. Запустить `docker compose up -d`

### При изменении данных

1. Запустить `docker compose down` (остановить контейнер)
2. Запустить `docker compose up -d --build` (пересобрать контейнер и запустить его)
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion project/alembic/env.py → alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from sqlalchemy import engine_from_config
from sqlalchemy import pool
from project.crying.db import models
from src.db import models
from alembic import context

# this is the Alembic Config object, which provides
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion project/config.yml → config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ db:
#db:
# user: postgres
# password: postgres
# database: crying
# database: src
# host: localhost
# port: 5432

Expand Down
4 changes: 2 additions & 2 deletions project/docker-compose.yml → docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
bot:
build: ./
restart: always
command: python crying/main.py -m prod
command: bash -c "alembic upgrade head && python src/main.py -m prod"
volumes:
- ./config.yml:/app/config.yml
- ./logs:/app/logs
Expand All @@ -18,7 +18,7 @@ services:
# environment:
# POSTGRES_PASSWORD: postgres
# POSTGRES_USER: postgres
# POSTGRES_DB: crying
# POSTGRES_DB: src
# # ports:
# # - "5433:5432"
# volumes:
Expand Down
10 changes: 5 additions & 5 deletions init_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def create_setting_files(project_path: Path, project_name: str):
if original_path.exists():
shutil.copy(original_path, project_path / file)
file_path = project_path / file
data = file_path.read_text(encoding="utf-8").replace("crying", project_name)
data = file_path.read_text(encoding="utf-8").replace("src", project_name)
file_path.write_text(data, encoding="utf-8")


Expand All @@ -67,9 +67,9 @@ def set_project_name_in_files(workdir: Path, project_name: str, ignore_merchant:
else:
if (elem.suffix != ".pyc") and ("dev" not in elem.name) and ("probe" not in elem.name):
data = elem.read_text(encoding="utf-8")
data = data.replace("project/crying", project_name) \
.replace('project.crying', project_name) \
.replace('crying', project_name)
data = data.replace("src", project_name) \
.replace('src', project_name) \
.replace('src', project_name)
print(f"✅ {elem}")

if ignore_merchant:
Expand Down Expand Up @@ -167,7 +167,7 @@ def main():
create_setting_files(project_path, project_name)
print("Файлы настроек созданы")

shutil.copytree(str(TEMPLATE_DIR / "crying"), str(workdir), dirs_exist_ok=True)
shutil.copytree(str(TEMPLATE_DIR / "src"), str(workdir), dirs_exist_ok=True)
# dir_util.copy_tree(str(TEMPLATE_DIR / "scripts"), str(project_path / "scripts"))
shutil.copytree(str(TEMPLATE_DIR / ".github"), str(project_path / ".github"), dirs_exist_ok=True)

Expand Down
33 changes: 0 additions & 33 deletions project/.github/workflows/deploy.yml

This file was deleted.

15 changes: 0 additions & 15 deletions project/.gitignore

This file was deleted.

9 changes: 0 additions & 9 deletions project/README.md

This file was deleted.

Empty file removed project/crying/db/__init__.py
Empty file.
29 changes: 0 additions & 29 deletions qodana.yaml

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
from aiogram.filters import BaseFilter
from aiogram.types import Message, CallbackQuery

from project.crying.apps.bot.keyboards.common import common_kbs
from project.crying.utils.subscribe import is_subscribe
from src.apps.bot.keyboards.common import common_kbs
from src.utils.subscribe import is_subscribe

if TYPE_CHECKING:
from project.crying.locales.stubs.ru.stub import TranslatorRunner
from src.locales.stubs.ru.stub import TranslatorRunner


class IsSubscribeFilter(BaseFilter):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from aiogram.filters import Command, StateFilter
from aiogram.fsm.context import FSMContext

from project.crying.config import Settings
from src.config import Settings
from ...callback_data.admin import AdminCallback
from ...callback_data.actions import Action
from ...commands.bot_commands import AdminCommands
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
from aiogram.fsm.context import FSMContext
from sqlalchemy.ext.asyncio import AsyncSession

from project.crying.apps.bot.commands.bot_commands import BaseCommands
from project.crying.apps.bot.keyboards.common import common_kbs
from project.crying.db.models import User
from src.apps.bot.commands.bot_commands import BaseCommands
from src.apps.bot.keyboards.common import common_kbs
from src.db.models import User

if TYPE_CHECKING:
from project.crying.locales.stubs.ru.stub import TranslatorRunner
from src.locales.stubs.ru.stub import TranslatorRunner

on = Router(name=__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from aiogram.filters import ChatMemberUpdatedFilter, ADMINISTRATOR
from loguru import logger

from project.crying.config import Settings
from src.config import Settings

on = Router(name=__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from aiogram.exceptions import TelegramBadRequest
from aiogram.fsm.context import FSMContext

from project.crying.apps.bot.callback_data.paginator import PaginatorCallback
from src.apps.bot.callback_data.paginator import PaginatorCallback

if TYPE_CHECKING:
from .....locales.stubs.ru.stub import TranslatorRunner
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from aiogram.types import InlineKeyboardMarkup
from aiogram.utils.keyboard import InlineKeyboardBuilder

from project.crying.apps.bot.callback_data.admin import AdminCallback
from project.crying.apps.bot.callback_data.actions import Action
from src.apps.bot.callback_data.admin import AdminCallback
from src.apps.bot.callback_data.actions import Action


# todo 5/31/2022 2:33 PM taima: разделить основно функционал
Expand Down Expand Up @@ -31,7 +31,7 @@ def admins(admins: list[int]) -> InlineKeyboardMarkup:
builder.button(text=str(admin), callback_data=AdminCallback(action=Action.DELETE, id=admin))
builder.button(text="Добавить админа", callback_data=AdminCallback(action=Action.CREATE))
builder.adjust(1)
builder.button(text= Назад", callback_data="admin")
builder.button(text="«", callback_data="admin")
return builder.as_markup()


Expand All @@ -43,5 +43,5 @@ def admin_button() -> InlineKeyboardMarkup:

def back() -> InlineKeyboardMarkup:
builder = InlineKeyboardBuilder()
builder.button(text= Назад", callback_data="admin")
builder.button(text="«", callback_data="admin")
return builder.as_markup()
File renamed without changes.
15 changes: 15 additions & 0 deletions src/apps/bot/keyboards/common/common_kbs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from aiogram.types import ReplyKeyboardMarkup, InlineKeyboardMarkup
from aiogram.utils.keyboard import ReplyKeyboardBuilder, InlineKeyboardBuilder


def start() -> ReplyKeyboardMarkup:
builder = ReplyKeyboardBuilder()
builder.button(text="Start", callback_data="start")
return builder.as_markup(resize_keyboard=True)


def inline_start() -> InlineKeyboardMarkup:
builder = InlineKeyboardBuilder()
builder.button(text="Start", callback_data="start")

return builder.as_markup(resize_keyboard=True)
Loading

0 comments on commit 1b8da89

Please sign in to comment.