uploader-bot/app/core/_config.py

83 lines
2.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
from datetime import datetime
from dotenv import load_dotenv
load_dotenv(dotenv_path='.env')
PROJECT_HOST = os.getenv('PROJECT_HOST', 'http://127.0.0.1:8080')
SANIC_PORT = int(os.getenv('SANIC_PORT', '8080'))
# Use relative path for local development, absolute for container
default_uploads = 'data' if not os.path.exists('/app') else '/app/data'
UPLOADS_DIR = os.getenv('UPLOADS_DIR', default_uploads)
# Safe directory creation
def safe_mkdir(path: str) -> bool:
"""Safely create directory with error handling"""
try:
if not os.path.exists(path):
os.makedirs(path, exist_ok=True)
return True
except (OSError, PermissionError) as e:
print(f"Warning: Could not create directory {path}: {e}")
return False
# Try to create uploads directory
safe_mkdir(UPLOADS_DIR)
TELEGRAM_API_KEY = os.environ.get('TELEGRAM_API_KEY', '1234567890:ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789')
CLIENT_TELEGRAM_API_KEY = os.environ.get('CLIENT_TELEGRAM_API_KEY', '1234567890:ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789')
import httpx
# Безопасное получение username с обработкой ошибок
def get_bot_username(api_key: str, fallback: str = "unknown_bot") -> str:
try:
response = httpx.get(f"https://api.telegram.org/bot{api_key}/getMe", timeout=5.0)
data = response.json()
if response.status_code == 200 and 'result' in data:
return data['result']['username']
else:
print(f"Warning: Failed to get bot username, using fallback. Status: {response.status_code}")
return fallback
except Exception as e:
print(f"Warning: Exception getting bot username: {e}, using fallback")
return fallback
TELEGRAM_BOT_USERNAME = get_bot_username(TELEGRAM_API_KEY, "my_network_bot")
CLIENT_TELEGRAM_BOT_USERNAME = get_bot_username(CLIENT_TELEGRAM_API_KEY, "my_client_bot")
MYSQL_URI = os.environ.get('MYSQL_URI', 'mysql://user:pass@localhost:3306')
MYSQL_DATABASE = os.environ.get('MYSQL_DATABASE', 'my_network')
LOG_LEVEL = os.getenv('LOG_LEVEL', 'DEBUG')
LOG_DIR = os.getenv('LOG_DIR', 'logs')
# Safe log directory creation
safe_mkdir(LOG_DIR)
_now_str = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
LOG_FILEPATH = f"{LOG_DIR}/{_now_str}.log"
WEB_APP_URLS = {
'uploadContent': f"https://web2-client.vercel.app/uploadContent"
}
ALLOWED_CONTENT_TYPES = [
'image/jpeg', 'image/png', 'image/gif', 'image/webp',
'video/mp4', 'video/webm', 'video/ogg',
'audio/mpeg', 'audio/ogg', 'audio/wav',
'text/plain'
]
TESTNET = bool(int(os.getenv('TESTNET', '0')))
TONCENTER_HOST = os.getenv('TONCENTER_HOST', 'https://toncenter.com/api/v2/')
TONCENTER_API_KEY = os.getenv('TONCENTER_API_KEY')
TONCENTER_V3_HOST = os.getenv('TONCENTER_V3_HOST', 'https://toncenter.com/api/v3/')
MY_PLATFORM_CONTRACT = 'EQDmWp6hbJlYUrXZKb9N88sOrTit630ZuRijfYdXEHLtheMY'
MY_FUND_ADDRESS = 'UQDarChHFMOI2On9IdHJNeEKttqepgo0AY4bG1trw8OAAwMY'