Compare commits
3 Commits
ab2fd3a833
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| d902e47068 | |||
| 5ef27f4cc8 | |||
| 12fcb9bfe1 |
8
.env
8
.env
@@ -1,10 +1,10 @@
|
|||||||
API_TOKEN = "6594413238:AAFahDg955k1GE9a4JE9T9yHyQoJZV5TFEk"
|
API_TOKEN = ""
|
||||||
TO_ADRESS = 'TRFBWmb5NkvKuQpYyPaYzZAX46VCUJtiq1'
|
TO_ADRESS = 'TRFBWmb5NkvKuQpYyPaYzZAX46VCUJtiq1'
|
||||||
ARBITRUM_API_KEY = 'P61RFT45N63PJYT5MDY1CEHG1US1C5KZZ4'
|
ARBITRUM_API_KEY = 'P61RFT45N63PJYT5MDY1CEHG1US1C5KZZ4'
|
||||||
ARBITRUM_ADRESS = '683dc0af0d3797523104b57a7889b97a5871fbbb'
|
ARBITRUM_ADRESS = '683dc0af0d3797523104b57a7889b97a5871fbbb'
|
||||||
ACCOUNT_ID_YK = '438627'
|
ACCOUNT_ID_YK = '438627'
|
||||||
SECRET_KEY_YK = 'test_c4W1yT9yzc8WT-d1YvJKGX59yOfXBMpeNtWegH2uJqo'
|
SECRET_KEY_YK = 'test_c4W1yT9yzc8WT-d1YvJKGX59yOfXBMpeNtWegH2uJqo'
|
||||||
DB_HOST = "localhost"
|
DB_HOST = "db"
|
||||||
DB_USER = "root"
|
DB_USER = ""
|
||||||
DB_PASSWORD = "vy!f..rVJ7t9tmG"
|
DB_PASSWORD = ""
|
||||||
DB_DATABASE = "subscriptions"
|
DB_DATABASE = "subscriptions"
|
||||||
66
.idea/workspace.xml
generated
66
.idea/workspace.xml
generated
@@ -4,24 +4,7 @@
|
|||||||
<option name="autoReloadType" value="SELECTIVE" />
|
<option name="autoReloadType" value="SELECTIVE" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="9e9f83d0-9771-4593-86bc-13be9ebfba22" name="Changes" comment="">
|
<list default="true" id="9e9f83d0-9771-4593-86bc-13be9ebfba22" name="Changes" comment="docker" />
|
||||||
<change afterPath="$PROJECT_DIR$/.env" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/Project_Default.xml" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/profiles_settings.xml" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/.idea/subscriptions.iml" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/admin.py" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/bot.py" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/database_queries.py" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/requirements.txt" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/states.py" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/test.py" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/utils.py" afterDir="false" />
|
|
||||||
</list>
|
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||||
@@ -46,24 +29,24 @@
|
|||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
<option name="showLibraryContents" value="true" />
|
<option name="showLibraryContents" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PropertiesComponent">{
|
<component name="PropertiesComponent"><![CDATA[{
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
"Python.admin.executor": "Run",
|
"Python.admin.executor": "Run",
|
||||||
"Python.bot.executor": "Run",
|
"Python.bot.executor": "Run",
|
||||||
"Python.database_queries.executor": "Run",
|
"Python.database_queries.executor": "Run",
|
||||||
"Python.main.executor": "Run",
|
"Python.main.executor": "Debug",
|
||||||
"Python.payment_binance_pay.executor": "Run",
|
"Python.payment_binance_pay.executor": "Run",
|
||||||
"Python.payments.executor": "Run",
|
"Python.payments.executor": "Run",
|
||||||
"Python.payments_tron.executor": "Run",
|
"Python.payments_tron.executor": "Run",
|
||||||
"Python.test.executor": "Run",
|
"Python.test.executor": "Run",
|
||||||
"Python.test3.executor": "Run",
|
"Python.test3.executor": "Run",
|
||||||
"Python.utils.executor": "Run",
|
"Python.utils.executor": "Run",
|
||||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"git-widget-placeholder": "main",
|
"git-widget-placeholder": "main",
|
||||||
"last_opened_file_path": "C:/Users/PC/Desktop/subscriptions"
|
"last_opened_file_path": "C:/Users/PC/Desktop/subscriptions"
|
||||||
}
|
}
|
||||||
}</component>
|
}]]></component>
|
||||||
<component name="RecentsManager">
|
<component name="RecentsManager">
|
||||||
<key name="CopyFile.RECENT_KEYS">
|
<key name="CopyFile.RECENT_KEYS">
|
||||||
<recent name="C:\Users\PC\Desktop\subscriptions" />
|
<recent name="C:\Users\PC\Desktop\subscriptions" />
|
||||||
@@ -114,6 +97,19 @@
|
|||||||
<option name="presentableId" value="Default" />
|
<option name="presentableId" value="Default" />
|
||||||
<updated>1722862614099</updated>
|
<updated>1722862614099</updated>
|
||||||
</task>
|
</task>
|
||||||
|
<task id="LOCAL-00001" summary="docker">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1723821929851</created>
|
||||||
|
<option name="number" value="00001" />
|
||||||
|
<option name="presentableId" value="LOCAL-00001" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1723821929851</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="2" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="VcsManagerConfiguration">
|
||||||
|
<MESSAGE value="docker" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value="docker" />
|
||||||
|
</component>
|
||||||
</project>
|
</project>
|
||||||
9
README
9
README
@@ -1,11 +1,16 @@
|
|||||||
Установите необходимые зависимости:
|
2. Установите необходимые зависимости:
|
||||||
|
|
||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
|
|
||||||
Настройте переменные окружения:
|
3. Настройте переменные окружения:
|
||||||
Создайте файл .env и добавьте необходимые переменные, такие как API-ключи и идентификаторы.
|
Создайте файл .env и добавьте необходимые переменные, такие как API-ключи и идентификаторы.
|
||||||
|
|
||||||
## Использование
|
## Использование
|
||||||
|
**Соберите и запустите контейнеры:**
|
||||||
|
|
||||||
|
docker-compose up --build
|
||||||
|
Это создаст и запустит все сервисы, указанные в docker-compose.yml.
|
||||||
|
|
||||||
|
|
||||||
Запустите приложение:
|
Запустите приложение:
|
||||||
python main.py
|
python main.py
|
||||||
|
|||||||
1
bot.py
1
bot.py
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import datetime
|
import datetime
|
||||||
|
|||||||
@@ -94,14 +94,6 @@ def get_user_data(cursor: Any, telegram_id: int) -> tuple:
|
|||||||
return cursor.fetchone()
|
return cursor.fetchone()
|
||||||
|
|
||||||
|
|
||||||
# def subscription_entry(cursor: Any, telegram_id: int, price_usd: int) -> None:
|
|
||||||
# """ Запись подписки в столбец subscription_option """
|
|
||||||
# new = f"{price_usd} мес"
|
|
||||||
# cursor.execute(
|
|
||||||
# "UPDATE users SET subscription_option = %s WHERE telegram_id = %s "
|
|
||||||
# "AND (sub_datetime_end IS NULL OR sub_datetime_end = '0')",
|
|
||||||
# (new, telegram_id)
|
|
||||||
# )
|
|
||||||
def subscription_entry(cursor: Any, telegram_id: int, price_usd: int) -> None:
|
def subscription_entry(cursor: Any, telegram_id: int, price_usd: int) -> None:
|
||||||
""" Запись количества месяцев в subscription_option """
|
""" Запись количества месяцев в subscription_option """
|
||||||
cursor.execute("UPDATE users SET subscription_option = subscription_option + %s WHERE telegram_id = %s",
|
cursor.execute("UPDATE users SET subscription_option = subscription_option + %s WHERE telegram_id = %s",
|
||||||
|
|||||||
@@ -1,12 +1,20 @@
|
|||||||
version: "3.9"
|
version: "3.9"
|
||||||
|
|
||||||
services:
|
services:
|
||||||
bot:
|
db:
|
||||||
build: .
|
image: mysql:8.0
|
||||||
container_name: aiogram_bot
|
restart: always
|
||||||
ports:
|
environment:
|
||||||
- "8080:8080"
|
MYSQL_DATABASE: ${DB_DATABASE}
|
||||||
environment:
|
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
|
||||||
- API_TOKEN=${API_TOKEN}
|
|
||||||
restart: unless-stopped
|
bot:
|
||||||
|
build: .
|
||||||
|
restart: always
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
ports:
|
||||||
|
- "5000:5000"
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
db_data:
|
||||||
|
|||||||
7
main.py
7
main.py
@@ -3,7 +3,8 @@ import os
|
|||||||
from aiogram import Bot, Dispatcher
|
from aiogram import Bot, Dispatcher
|
||||||
import asyncio
|
import asyncio
|
||||||
import bot
|
import bot
|
||||||
from utils import get_usd_rub_course, checking_and_deleting_users
|
from utils import get_usd_rub_course, checking_and_deleting_users, check_table_exists_users, check_table_exists_usd_rub, \
|
||||||
|
check_table_exists_successful_hash
|
||||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
@@ -21,6 +22,10 @@ async def main() -> None:
|
|||||||
""" Запуск бота """
|
""" Запуск бота """
|
||||||
dp.include_router(bot.router)
|
dp.include_router(bot.router)
|
||||||
scheduler = AsyncIOScheduler()
|
scheduler = AsyncIOScheduler()
|
||||||
|
check_table_exists_users()
|
||||||
|
check_table_exists_usd_rub()
|
||||||
|
check_table_exists_successful_hash()
|
||||||
|
await get_usd_rub_course()
|
||||||
# Планируем выполнение функции в 12:00, 18:00 и 00:00 планировщиком
|
# Планируем выполнение функции в 12:00, 18:00 и 00:00 планировщиком
|
||||||
scheduler.add_job(get_usd_rub_course, 'cron', hour='12,18,0')
|
scheduler.add_job(get_usd_rub_course, 'cron', hour='12,18,0')
|
||||||
# Планируем выполнение функции checking_and_deleting_users ежедневно в 00:12
|
# Планируем выполнение функции checking_and_deleting_users ежедневно в 00:12
|
||||||
|
|||||||
79
utils.py
79
utils.py
@@ -123,3 +123,82 @@ async def checking_and_deleting_users() -> None:
|
|||||||
reset_user_data(id_user)
|
reset_user_data(id_user)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Ошибка: {e}")
|
print(f"Ошибка: {e}")
|
||||||
|
|
||||||
|
|
||||||
|
def check_table_exists_users():
|
||||||
|
""" Проверяет, существует ли таблица users в базе данных. Если таблицы нет, создает ее """
|
||||||
|
conn = create_connection()
|
||||||
|
cursor = conn.cursor()
|
||||||
|
# Запрос для проверки существования таблицы
|
||||||
|
cursor.execute(f"""
|
||||||
|
SELECT 1
|
||||||
|
FROM information_schema.tables
|
||||||
|
WHERE table_schema = '{os.getenv('DB_DATABASE')}'
|
||||||
|
AND table_name = 'users';
|
||||||
|
""")
|
||||||
|
exists = cursor.fetchone() is not None
|
||||||
|
# Если таблица не существует, создаем ее
|
||||||
|
if not exists:
|
||||||
|
cursor.execute(f"""
|
||||||
|
CREATE TABLE users (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
telegram_id BIGINT NOT NULL,
|
||||||
|
telegram_username VARCHAR(255) NOT NULL,
|
||||||
|
zennolab_id VARCHAR(255) DEFAULT NULL,
|
||||||
|
sub_datetime_end BIGINT UNSIGNED DEFAULT NULL,
|
||||||
|
threads_count INT DEFAULT NULL,
|
||||||
|
telegram_thread_id BIGINT DEFAULT NULL,
|
||||||
|
question_time INT DEFAULT NULL,
|
||||||
|
count_streams INT DEFAULT NULL,
|
||||||
|
subscription_option VARCHAR(255) DEFAULT NULL,
|
||||||
|
subscription_end_date DATE DEFAULT NULL);""")
|
||||||
|
conn.commit()
|
||||||
|
cursor.close()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
def check_table_exists_usd_rub():
|
||||||
|
""" Проверяет, существует ли таблица USD_RUB в базе данных. Если таблицы нет, создает ее """
|
||||||
|
conn = create_connection()
|
||||||
|
cursor = conn.cursor()
|
||||||
|
# Запрос для проверки существования таблицы
|
||||||
|
cursor.execute(f"""
|
||||||
|
SELECT 1
|
||||||
|
FROM information_schema.tables
|
||||||
|
WHERE table_schema = '{os.getenv('DB_DATABASE')}'
|
||||||
|
AND table_name = 'USD_RUB';
|
||||||
|
""")
|
||||||
|
exists = cursor.fetchone() is not None
|
||||||
|
# Если таблица не существует, создаем ее
|
||||||
|
if not exists:
|
||||||
|
cursor.execute(f"""
|
||||||
|
CREATE TABLE USD_RUB (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
well FLOAT DEFAULT 0);""")
|
||||||
|
conn.commit()
|
||||||
|
cursor.close()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
def check_table_exists_successful_hash():
|
||||||
|
""" Проверяет, существует ли таблица successful_hash в базе данных. Если таблицы нет, создает ее """
|
||||||
|
conn = create_connection()
|
||||||
|
cursor = conn.cursor()
|
||||||
|
# Запрос для проверки существования таблицы
|
||||||
|
cursor.execute(f"""
|
||||||
|
SELECT 1
|
||||||
|
FROM information_schema.tables
|
||||||
|
WHERE table_schema = '{os.getenv('DB_DATABASE')}'
|
||||||
|
AND table_name = 'successful_hash';
|
||||||
|
""")
|
||||||
|
exists = cursor.fetchone() is not None
|
||||||
|
# Если таблица не существует, создаем ее
|
||||||
|
if not exists:
|
||||||
|
cursor.execute(f"""
|
||||||
|
CREATE TABLE successful_hash (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
hash_users VARCHAR(255) NOT NULL,
|
||||||
|
telegram_id BIGINT NOT NULL);""")
|
||||||
|
conn.commit()
|
||||||
|
cursor.close()
|
||||||
|
conn.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user