change config structure
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
BOT_TOKEN =
|
||||
SIGNER_MICROSERVICE_URL = http://signer:8080
|
||||
+1
-1
@@ -1,8 +1,8 @@
|
||||
/.idea/
|
||||
/tests/
|
||||
|
||||
poetry.lock
|
||||
config.toml
|
||||
.env
|
||||
|
||||
**/__pycache__/
|
||||
.cache
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
from aiogram import Bot, Dispatcher
|
||||
from rich.console import Console
|
||||
|
||||
from .utils.config import config
|
||||
from .utils import config, env
|
||||
|
||||
bot = Bot(token=config.telegram.bot_token)
|
||||
bot = Bot(token=env.BOT_TOKEN)
|
||||
dp = Dispatcher()
|
||||
console = Console()
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import aiohttp
|
||||
from attrs import define
|
||||
|
||||
from bot.utils.config import config
|
||||
from bot.utils import env
|
||||
|
||||
|
||||
@define
|
||||
@@ -26,7 +26,7 @@ class BotEngine:
|
||||
async def get_api(self, method: str, json: dict):
|
||||
try:
|
||||
async with self.session.post(
|
||||
f"https://api.telegram.org/bot{config.telegram.bot_token}/{method}",
|
||||
f"https://api.telegram.org/bot{env.BOT_TOKEN}/{method}",
|
||||
json=json,
|
||||
) as r:
|
||||
return await r.json()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from attrs import define
|
||||
|
||||
from bot.utils.config import config
|
||||
from bot.utils import env
|
||||
|
||||
from .engine import TikTokEngine
|
||||
|
||||
@@ -12,7 +12,7 @@ class TikTokDriver:
|
||||
async def get_detail(self, aweme_id: str):
|
||||
new_url = (
|
||||
await self.engine.post(
|
||||
config.tiktokapi.signer_microservice_url,
|
||||
env.SIGNER_MICROSERVICE_URL,
|
||||
data=f"https://www.tiktok.com/api/item/detail/"
|
||||
f"?WebIdLastTime=0&aid=1988&app_language=ru-RU"
|
||||
f"&app_name=tiktok_web&browser_language=ru-RU"
|
||||
|
||||
@@ -1 +1 @@
|
||||
pass
|
||||
from .config import config
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import os
|
||||
import shutil
|
||||
import tomllib
|
||||
|
||||
|
||||
@@ -5,6 +7,8 @@ class Config(dict):
|
||||
def __init__(self, _config: dict = None):
|
||||
try:
|
||||
if _config is None:
|
||||
if not os.path.isfile("config.toml"):
|
||||
shutil.copy("config.toml.example", "config.toml")
|
||||
super().__init__(**tomllib.load(open("config.toml", "rb")))
|
||||
else:
|
||||
super().__init__(**_config)
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
from dotenv import load_dotenv
|
||||
|
||||
try:
|
||||
load_dotenv()
|
||||
|
||||
BOT_TOKEN = os.environ["BOT_TOKEN"]
|
||||
SIGNER_MICROSERVICE_URL = os.environ["SIGNER_MICROSERVICE_URL"]
|
||||
|
||||
except KeyError as e:
|
||||
print("Can't parse environment", e)
|
||||
sys.exit(1)
|
||||
@@ -1,9 +1,3 @@
|
||||
[telegram]
|
||||
bot_token = ''
|
||||
|
||||
[tiktokapi]
|
||||
signer_microservice_url = "http://localhost:60103"
|
||||
|
||||
[log]
|
||||
log_cycle_errors = true
|
||||
log_tiktoks = true
|
||||
|
||||
Reference in New Issue
Block a user