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/
|
/.idea/
|
||||||
/tests/
|
/tests/
|
||||||
|
|
||||||
poetry.lock
|
|
||||||
config.toml
|
config.toml
|
||||||
|
.env
|
||||||
|
|
||||||
**/__pycache__/
|
**/__pycache__/
|
||||||
.cache
|
.cache
|
||||||
|
|||||||
+2
-2
@@ -1,9 +1,9 @@
|
|||||||
from aiogram import Bot, Dispatcher
|
from aiogram import Bot, Dispatcher
|
||||||
from rich.console import Console
|
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()
|
dp = Dispatcher()
|
||||||
console = Console()
|
console = Console()
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import aiohttp
|
import aiohttp
|
||||||
from attrs import define
|
from attrs import define
|
||||||
|
|
||||||
from bot.utils.config import config
|
from bot.utils import env
|
||||||
|
|
||||||
|
|
||||||
@define
|
@define
|
||||||
@@ -26,7 +26,7 @@ class BotEngine:
|
|||||||
async def get_api(self, method: str, json: dict):
|
async def get_api(self, method: str, json: dict):
|
||||||
try:
|
try:
|
||||||
async with self.session.post(
|
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,
|
json=json,
|
||||||
) as r:
|
) as r:
|
||||||
return await r.json()
|
return await r.json()
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from attrs import define
|
from attrs import define
|
||||||
|
|
||||||
from bot.utils.config import config
|
from bot.utils import env
|
||||||
|
|
||||||
from .engine import TikTokEngine
|
from .engine import TikTokEngine
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ class TikTokDriver:
|
|||||||
async def get_detail(self, aweme_id: str):
|
async def get_detail(self, aweme_id: str):
|
||||||
new_url = (
|
new_url = (
|
||||||
await self.engine.post(
|
await self.engine.post(
|
||||||
config.tiktokapi.signer_microservice_url,
|
env.SIGNER_MICROSERVICE_URL,
|
||||||
data=f"https://www.tiktok.com/api/item/detail/"
|
data=f"https://www.tiktok.com/api/item/detail/"
|
||||||
f"?WebIdLastTime=0&aid=1988&app_language=ru-RU"
|
f"?WebIdLastTime=0&aid=1988&app_language=ru-RU"
|
||||||
f"&app_name=tiktok_web&browser_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
|
import tomllib
|
||||||
|
|
||||||
|
|
||||||
@@ -5,6 +7,8 @@ class Config(dict):
|
|||||||
def __init__(self, _config: dict = None):
|
def __init__(self, _config: dict = None):
|
||||||
try:
|
try:
|
||||||
if _config is None:
|
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")))
|
super().__init__(**tomllib.load(open("config.toml", "rb")))
|
||||||
else:
|
else:
|
||||||
super().__init__(**_config)
|
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]
|
||||||
log_cycle_errors = true
|
log_cycle_errors = true
|
||||||
log_tiktoks = true
|
log_tiktoks = true
|
||||||
|
|||||||
Reference in New Issue
Block a user