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'
|
||||
ARBITRUM_API_KEY = 'P61RFT45N63PJYT5MDY1CEHG1US1C5KZZ4'
|
||||
ARBITRUM_ADRESS = '683dc0af0d3797523104b57a7889b97a5871fbbb'
|
||||
ACCOUNT_ID_YK = '438627'
|
||||
SECRET_KEY_YK = 'test_c4W1yT9yzc8WT-d1YvJKGX59yOfXBMpeNtWegH2uJqo'
|
||||
DB_HOST = "localhost"
|
||||
DB_USER = "root"
|
||||
DB_PASSWORD = "vy!f..rVJ7t9tmG"
|
||||
DB_HOST = "db"
|
||||
DB_USER = ""
|
||||
DB_PASSWORD = ""
|
||||
DB_DATABASE = "subscriptions"
|
||||
66
.idea/workspace.xml
generated
66
.idea/workspace.xml
generated
@@ -4,24 +4,7 @@
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="9e9f83d0-9771-4593-86bc-13be9ebfba22" name="Changes" comment="">
|
||||
<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>
|
||||
<list default="true" id="9e9f83d0-9771-4593-86bc-13be9ebfba22" name="Changes" comment="docker" />
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
@@ -46,24 +29,24 @@
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent">{
|
||||
"keyToString": {
|
||||
"Python.admin.executor": "Run",
|
||||
"Python.bot.executor": "Run",
|
||||
"Python.database_queries.executor": "Run",
|
||||
"Python.main.executor": "Run",
|
||||
"Python.payment_binance_pay.executor": "Run",
|
||||
"Python.payments.executor": "Run",
|
||||
"Python.payments_tron.executor": "Run",
|
||||
"Python.test.executor": "Run",
|
||||
"Python.test3.executor": "Run",
|
||||
"Python.utils.executor": "Run",
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"git-widget-placeholder": "main",
|
||||
"last_opened_file_path": "C:/Users/PC/Desktop/subscriptions"
|
||||
<component name="PropertiesComponent"><![CDATA[{
|
||||
"keyToString": {
|
||||
"Python.admin.executor": "Run",
|
||||
"Python.bot.executor": "Run",
|
||||
"Python.database_queries.executor": "Run",
|
||||
"Python.main.executor": "Debug",
|
||||
"Python.payment_binance_pay.executor": "Run",
|
||||
"Python.payments.executor": "Run",
|
||||
"Python.payments_tron.executor": "Run",
|
||||
"Python.test.executor": "Run",
|
||||
"Python.test3.executor": "Run",
|
||||
"Python.utils.executor": "Run",
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"git-widget-placeholder": "main",
|
||||
"last_opened_file_path": "C:/Users/PC/Desktop/subscriptions"
|
||||
}
|
||||
}</component>
|
||||
}]]></component>
|
||||
<component name="RecentsManager">
|
||||
<key name="CopyFile.RECENT_KEYS">
|
||||
<recent name="C:\Users\PC\Desktop\subscriptions" />
|
||||
@@ -114,6 +97,19 @@
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1722862614099</updated>
|
||||
</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 />
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="docker" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="docker" />
|
||||
</component>
|
||||
</project>
|
||||
9
README
9
README
@@ -1,11 +1,16 @@
|
||||
Установите необходимые зависимости:
|
||||
2. Установите необходимые зависимости:
|
||||
|
||||
pip install -r requirements.txt
|
||||
|
||||
Настройте переменные окружения:
|
||||
3. Настройте переменные окружения:
|
||||
Создайте файл .env и добавьте необходимые переменные, такие как API-ключи и идентификаторы.
|
||||
|
||||
## Использование
|
||||
**Соберите и запустите контейнеры:**
|
||||
|
||||
docker-compose up --build
|
||||
Это создаст и запустит все сервисы, указанные в docker-compose.yml.
|
||||
|
||||
|
||||
Запустите приложение:
|
||||
python main.py
|
||||
|
||||
1
bot.py
1
bot.py
@@ -1,4 +1,3 @@
|
||||
|
||||
import os
|
||||
from datetime import datetime, timedelta
|
||||
import datetime
|
||||
|
||||
@@ -94,14 +94,6 @@ def get_user_data(cursor: Any, telegram_id: int) -> tuple:
|
||||
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:
|
||||
""" Запись количества месяцев в subscription_option """
|
||||
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:
|
||||
bot:
|
||||
build: .
|
||||
container_name: aiogram_bot
|
||||
ports:
|
||||
- "8080:8080"
|
||||
environment:
|
||||
- API_TOKEN=${API_TOKEN}
|
||||
restart: unless-stopped
|
||||
services:
|
||||
db:
|
||||
image: mysql:8.0
|
||||
restart: always
|
||||
environment:
|
||||
MYSQL_DATABASE: ${DB_DATABASE}
|
||||
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
|
||||
|
||||
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
|
||||
import asyncio
|
||||
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 dotenv import load_dotenv
|
||||
|
||||
@@ -21,6 +22,10 @@ async def main() -> None:
|
||||
""" Запуск бота """
|
||||
dp.include_router(bot.router)
|
||||
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 планировщиком
|
||||
scheduler.add_job(get_usd_rub_course, 'cron', hour='12,18,0')
|
||||
# Планируем выполнение функции 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)
|
||||
except Exception as 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