-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0fe6d7b
commit 406d8b2
Showing
7 changed files
with
87 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.vscode | ||
autom4te.cache | ||
.github | ||
.env | ||
.env | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,10 @@ | ||
FROM python:3.9 | ||
|
||
# Установка зависимостей | ||
RUN pip install python-telegram-bot==12.8 | ||
|
||
# Копирование исходного кода в контейнер | ||
COPY . /app | ||
|
||
# Копирование файла .env в контейнер | ||
COPY .env /app/.env | ||
|
||
# Установка рабочей директории | ||
WORKDIR /app | ||
|
||
# Команда для запуска приложения с использованием переменных окружения из .env | ||
CMD ["sh", "-c", "export $(xargs < .env) && python main.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,27 @@ | ||
# Телеграм-бот для анализа PINFL | ||
# Telegram Bot for PINFL Analysis | ||
|
||
Этот проект представляет собой телеграм-бота, который анализирует введенный пользователем ПИНФЛ (Персональный идентификационный номер физического лица) и сообщает о его валидности, а также о дате рождения, коде региона и других параметрах. | ||
[![linting: pylint](https://img.shields.io/badge/linting-pylint-yellowgreen)](https://github.com/pylint-dev/pylint) | ||
|
||
## Зачем этот проект нужен? | ||
This project is a Telegram bot that analyzes the PINFL (Personal Identification Number for Individual Taxpayer) entered by the user and reports its validity, as well as its birth date, region code, and other parameters. | ||
|
||
ПИНФЛ (PINFL) - это уникальный идентификационный номер, используемый в ряде стран для идентификации граждан. Этот проект предназначен для обработки и анализа PINFL, чтобы убедиться в его корректности и предоставить информацию о дате рождения и других данных, содержащихся в этом номере. | ||
## Why is this project needed? | ||
|
||
## Как использовать? | ||
PINFL (PINFL) is a unique identification number used in several countries to identify citizens. This project is intended for processing and analyzing PINFL to ensure its correctness and provide information about the birth date and other data contained in this number. | ||
|
||
1. Перейдите в деррикторию проекта | ||
## How to use? | ||
|
||
2. Скопируйте ``` .env.example ``` в ``` .env ``` | ||
1. Navigate to the project directory. | ||
|
||
3. Обновите все значения в ``` .env ``` | ||
2. Copy ``` .env.example ``` to ``` .env ```. | ||
|
||
3. Update all values in ``` .env ```. | ||
|
||
4. ``` docker build -t pinfl_bot . ``` | ||
|
||
5. ``` docker run -d pinfl_bot ``` | ||
|
||
## Дополнительные функции | ||
## Additional features | ||
|
||
1. Бот предварительно проверяет введенный текст на наличие только цифр и длину не менее 14 символов. Если введенный текст не соответствует этим критериям, бот отправит сообщение с соответствующим предупреждением. | ||
1. The bot pre-checks the entered text for the presence of only digits and a length of at least 14 characters. If the entered text does not meet these criteria, the bot will send a message with the corresponding warning. | ||
|
||
2. Если введенный PINFL короче 14 символов, недостающие символы будут заполнены нулями перед анализом. | ||
2. If the entered PINFL is shorter than 14 characters, the missing characters will be filled with zeros before analysis. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,43 @@ | ||
"""Random PINFL generation module.""" | ||
|
||
import random | ||
import datetime | ||
|
||
|
||
class PinflUtilitiesGenerator: | ||
def generate_pinfl(self, gender, birth_date): | ||
century = str(self.gender_date_index(gender, birth_date)) | ||
"""Random PINFL generation.""" | ||
|
||
def generate(self, gender, birth_date): | ||
"""PINFL generation function.""" | ||
|
||
century = str(self._gender_date_index(gender, birth_date)) | ||
|
||
month = str(birth_date.month).zfill(2) | ||
day = str(birth_date.day).zfill(2) | ||
decade = str(birth_date.year % 100) | ||
|
||
area_code = str(random.randint(1, 999)).zfill(3) | ||
serial_number = str(random.randint(1, 999)).zfill(3) | ||
pinfl_digits = [ | ||
|
||
digits = [ | ||
str(digit) | ||
for digit in century + day + month + decade + area_code + serial_number | ||
] | ||
check_digit = self._calculate_check_digit(pinfl_digits) | ||
return "".join(pinfl_digits) + str(check_digit) | ||
|
||
def gender_date_index(self, gender, birth_date): | ||
check_digit = self._calculate_check_digit(digits) | ||
return "".join(digits) + str(check_digit) | ||
|
||
def generate_pinfl(self, gender, birth_date): | ||
"""Generate PINFL.""" | ||
|
||
return self.generate(gender, birth_date) | ||
|
||
def _gender_date_index(self, gender, birth_date): | ||
gender_shift_number = 1 if gender == "female" else 0 | ||
return (birth_date.year // 100) - 17 + gender_shift_number | ||
|
||
def _calculate_check_digit(self, pinfl_digits): | ||
def _calculate_check_digit(self, digits): | ||
weight_func = [7, 3, 1, 7, 3, 1, 7, 3, 1, 7, 3, 1, 7] | ||
sum_digits = sum( | ||
int(digit) * weight for digit, weight in zip(pinfl_digits, weight_func) | ||
int(digit) * weight for digit, weight in zip(digits, weight_func) | ||
) | ||
return sum_digits % 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters