Skip to content

Commit

Permalink
Merge pull request #99 from DavidRomanovizc/develop
Browse files Browse the repository at this point in the history
Global update
  • Loading branch information
DavidRomanovizc authored Aug 14, 2023
2 parents ac852eb + ede72da commit 716fe21
Show file tree
Hide file tree
Showing 136 changed files with 4,787 additions and 2,968 deletions.
10 changes: 10 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[flake8]
exclude =
venv,
.env,
.gitignore,
README.md,
migrations,
.git,
max-line-length = 99
extend-ignore = F401, E402
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,4 @@ dmypy.json

# Django Settings with Secret key
/django_project/django_project/settings.py
/django_project/telegrambot/usersmanage/migrations/
photos/
43 changes: 43 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
exclude: migrations|templates|fixtures|__init__.py
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
files: /
- id: end-of-file-fixer
files: /
- id: check-ast
files: /
- repo: https://github.com/myint/autoflake # removes unused imports
rev: v2.0.1
hooks:
- id: autoflake
files: /
args:
[
-i,
--remove-all-unused-imports,
--ignore-init-module-imports,
--expand-star-imports,
--remove-duplicate-keys,
]
- repo: https://github.com/pycqa/isort # sorts imports
rev: 5.12.0
hooks:
- id: isort
args: [ --settings-file, black.toml]
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
files: /
language_version: python3
args: [--config, black.toml]
additional_dependencies:
- "click==8.0.4"
- repo: https://github.com/radix-ai/auto-smart-commit # prepends jira ticket number to each commit
rev: v1.0.2
hooks:
- id: auto-smart-commit
91 changes: 39 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,49 +72,25 @@ $ pip install -r requirements.txt
First you need to rename the file `.env.dist` to `.env`.\
After that, you need to fill it with data.

| Variable | Type | Importance |
|---------------|------|------------|
| BOT_TOKEN | str | True |
| ADMINS | list | True |
| SUPPORTS | list | True |
| IP | str | True |
| TIMEZONE | str | True |
| MODERATE_CHAT | str | True |
| DB_USER | str | True |
| DB_PASS | str | True |
| DB_HOST | str | True |
| DB_NAME | str | True |
| PORT | str | True |
| SECRET_KEY | str | True |
| API_KEY | str | True |
| QIWI_KEY | str | True |
| PHONE_NUMBER | str | True |
| SECRET_P2 | str | True |
| USE_REDIS | bool | False |

`BOT_TOKEN` - Bot token\
`ADMINS` - list of admins id\
`SUPPORTS` - list of admins id\
`IP` - ip for other services\
`TIMEZONE` - your time zone for working with the scheduler\
`MODERATE_CHAT` - telegram chat where the event will be moderated

`DB_USER` - username of the database owner\
`DB_PASS` - password from the database\
`DB_HOST` - IP address of the database\
`DB_NAME` - database name\
`PORT` - the database port. Usually the db running on port `5432`

`SECRET_KEY` - secret key for django

`API_KEY` - yandex api key for yandex map

`QIWI_KEY` - qiwi api key for receiving payments\
`PHONE_NUMBER` - your phone number (need for qiwi)\
`SECRET_2` - public p2 key which allows you to issue an invoice and open a transfer form

`USE_REDIS` - Optional parameter

| Variable | Type | Importance | Description |
|---------------|------|------------|-----------------------------------------------------------------------------|
| BOT_TOKEN | str | True | Bot token |
| ADMINS | list | True | list of admins id |
| SUPPORTS | list | True | list of supports id |
| IP | str | True | ip for other services |
| TIMEZONE | str | True | your time zone for working with the scheduler |
| MODERATE_CHAT | str | True | telegram chat where the event will be moderated |
| DB_USER | str | True | username of the database owner |
| DB_PASS | str | True | password from the database |
| DB_HOST | str | True | IP address of the database |
| DB_NAME | str | True | database name |
| PORT | str | True | the database port. Usually the db running on port `5432` |
| SECRET_KEY | str | True | secret key for django |
| API_KEY | str | True | yandex api key for yandex map |
| QIWI_KEY | str | True | qiwi api key for receiving payments |
| PHONE_NUMBER | str | True | your phone number (need for qiwi) |
| SECRET_P2 | str | True | public p2 key which allows you to issue an invoice and open a transfer form |
| USE_REDIS | bool | False | Optional parameter |

#### :green_book: Django

Expand Down Expand Up @@ -218,28 +194,36 @@ After you have downloaded the checkpoint you need, drag it to the NudeNet folder
We try to stick
to [PEP 8](https://peps.python.org/pep-0008/#:~:text=Use%20the%20function%20naming%20rules,invoke%20Python's%20name%20mangling%20rules)


Thank you for your interest in contributing to our Python project! Below are the steps to help you become a part of our developer community.
Thank you for your interest in contributing to our Python project! Below are the steps to help you become a part of our
developer community.

#### 1. Fork the Project
Go to the repository page on GitHub and click the "Fork" button in the upper right corner. This will create a copy of the project in your account.

Go to the repository page on GitHub and click the "Fork" button in the upper right corner. This will create a copy of
the project in your account.

#### 2. Clone the Repository

```sh
$ git clone https://github.com/DavidRomanovizc/DatingBot.git
```

#### 3. Project Setup

For instructions on deploying the project on a local computer, see above

#### 4. Create a Branch

Create a new branch for your changes:

```sh
$ git checkout -b branch-name
```

#### 5. Make Changes
Make the necessary changes to the project code. Follow the project's structure, coding style, and development guidelines.

Make the necessary changes to the project code. Follow the project's structure, coding style, and development
guidelines.

And run the flake8

Expand All @@ -248,30 +232,33 @@ $ flake8 --config=.flake8
```

#### 6. Commit and Push

```sh
$ git commit -m "Description of your changes"
$ git push origin your-branch-name
```

#### 7. Create a Pull Request
Go to your repository on GitHub and click the "New Pull Request" button. Specify the base branch of the project (usually `main` or `master`) and the branch with your changes.

Go to your repository on GitHub and click the "New Pull Request" button. Specify the base branch of the project (
usually `main` or `master`) and the branch with your changes.

#### 8. Discussion and Review

Discuss your Pull Request with the community members. Make necessary changes based on the feedback.

#### 9. Merge the Pull Request

After approval, your code will be merged into the main branch of the project.

#### 10. Celebration 🎉
Congratulations! You have successfully contributed to the Python project. Thank you for your help!


Congratulations! You have successfully contributed to the Python project. Thank you for your help!

For multi languages we use i18n. All the instructions we can find here - [Language guide](lang_instruction.md)

<br><br/>

<h3 align="center">Works on Open Source</h3>

![image](https://user-images.githubusercontent.com/72649244/173241368-c40bd408-8df8-450f-9ac7-530de1692e1c.png)

![image](https://user-images.githubusercontent.com/72649244/173241368-c40bd408-8df8-450f-9ac7-530de1692e1c.png)
21 changes: 12 additions & 9 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
# noinspection PyUnresolvedReferences
import logging
import os

import django
from django_project.telegrambot.telegrambot import settings
from aiogram import executor

from loader import dp, db, scheduler
# noinspection PyUnresolvedReferences
import filters
# noinspection PyUnresolvedReferences
from django_project.telegrambot.telegrambot import settings
# noinspection PyUnresolvedReferences
from loader import dp, db, scheduler
from utils.logger import setup_logger
from utils.notify_admins import AdminNotification

from utils.set_bot_commands import set_default_commands


async def on_startup(dispatcher) -> None:
# Устанавливаем дефолтные команды
await set_default_commands(dispatcher)
# Уведомляет о запуске

await AdminNotification.send(dispatcher)
logging.info(f'Создаем подключение...')
await db.create()
logging.info(f'Подключение успешно!')
logging.info(f'База загружена успешно!')


def setup_django():
Expand All @@ -33,7 +33,10 @@ def setup_django():

if __name__ == '__main__':
setup_django()
setup_logger("INFO", ["aiogram.bot.api"])
# noinspection PyUnresolvedReferences
import middlewares
# noinspection PyUnresolvedReferences
import handlers

scheduler.start()
Expand Down
10 changes: 10 additions & 0 deletions babel.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[python: data/**.py]
[python: django_project/**.py]
[python: filters/**.py]
[python: functions/**.py]
[python: handlers/**.py]
[python: keyboards/**.py]
[python: logs/**.py]
[python: middlewares/**.py]
[python: utils/**.py]
encoding = utf-8
23 changes: 23 additions & 0 deletions black.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[tool.black]
adopts = '--fast' #may yield briken ast, but much faster
exclude = '''
(
/(
\.git
| \.venv
| django_project/telegrambot/common/migrations
| django_project/telegrambot/usersmanage/migrations
)/
)
'''
line-length = 120
target_version = ['py38']

[tool.isort]
known_third_party = ['django', 'rest_framework_extensions', 'aiogram']
known_first_party = ["common", "usersmanage",]
line_length = 120
skip="migrations, templates,__init__.py,"
skip_gitignore = "True"
force_single_line = "True"
lines_after_imports = 2
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
45 changes: 35 additions & 10 deletions data/config.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import inspect
from dataclasses import dataclass
from functools import lru_cache
from pathlib import Path
from typing import List

from environs import Env
from yarl import URL

env = Env()
env.read_env()


# The frozen=True arg protects instances of the class from accidental modification
Expand Down Expand Up @@ -32,9 +37,9 @@ class TgBot:
class Miscellaneous:
secret_key: str
yandex_api_key: str
qiwi_key: str
phone_number: str
secret_p2p_key: str
client_id: str
redirect_url: URL
yoomoney_key: str


@dataclass(frozen=True)
Expand All @@ -44,11 +49,31 @@ class Config:
misc: Miscellaneous


def search_env() -> Path:
current_frame = inspect.currentframe()
frame = current_frame.f_back
caller_dir = Path(frame.f_code.co_filename).parent.resolve()
start = caller_dir / ".env"
return start


def change_env(section: str, value: str):
dumped_env = env.dump()
text = ""
start = search_env()

with open(start, "w", encoding="utf-8") as file:
for v in dumped_env:
if v:
e = dumped_env[v]
if v == section:
e = value
text += f"{v}={e}\n"
file.write(text)


@lru_cache
def load_config() -> Config:
env = Env()
env.read_env()

return Config(
tg_bot=TgBot(
token=env.str("BOT_TOKEN"),
Expand All @@ -58,7 +83,7 @@ def load_config() -> Config:
timezone=env.str("TIMEZONE"),
I18N_DOMAIN='dating',
moderate_chat=env.str("MODERATE_CHAT"),
use_redis=env.bool("USE_REDIS")
use_redis=env.bool("USE_REDIS"),
),
db=DataBaseConfig(
user=env.str('DB_USER'),
Expand All @@ -70,9 +95,9 @@ def load_config() -> Config:
misc=Miscellaneous(
secret_key=env.str("SECRET_KEY"),
yandex_api_key=env.str('API_KEY'),
qiwi_key=env.str("QIWI_KEY"),
phone_number=env.str("PHONE_NUMBER"),
secret_p2p_key=env.str("SECRET_P2"),
client_id=env.str("CLIENT_ID"),
redirect_url=env.str("REDIRECT_URI"),
yoomoney_key=env.str("YOOMONEY_KEY"),
)
)

Expand Down
3 changes: 0 additions & 3 deletions django_project/telegrambot/common/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
from django.contrib import admin

# Register your models here.
Loading

0 comments on commit 716fe21

Please sign in to comment.