Add linters config

This commit is contained in:
2022-01-01 20:48:39 +03:00
parent a7cfff3170
commit f062b41ce8
16 changed files with 179 additions and 60 deletions

View File

@@ -1,11 +1,12 @@
from typing import Optional
from io import BytesIO
from typing import Optional
from fastapi import UploadFile
from telegram_files_storage import AiogramFilesStorage, TelethonFilesStorage
from core.config import env_config
from app.models import UploadedFile, UploadBackends
from core.config import env_config
class FileUploader:
@@ -67,7 +68,9 @@ class FileUploader:
storage = self.get_telethon_storage()
self.upload_data = await storage.upload(bytes_io, caption=self.caption) # type: ignore
self.upload_data = await storage.upload(
bytes_io, caption=self.caption
) # type: ignore
self.upload_backend = UploadBackends.telethon
return True
@@ -82,12 +85,18 @@ class FileUploader:
async def prepare(cls):
if env_config.BOT_TOKENS:
cls.AIOGRAM_STORAGES: list[AiogramFilesStorage] = [
AiogramFilesStorage(env_config.TELEGRAM_CHAT_ID, token) for token in env_config.BOT_TOKENS
AiogramFilesStorage(env_config.TELEGRAM_CHAT_ID, token)
for token in env_config.BOT_TOKENS
]
if env_config.TELETHON_APP_CONFIG and env_config.TELETHON_SESSIONS:
cls.TELETHON_STORAGES: list[TelethonFilesStorage] = [
TelethonFilesStorage(env_config.TELEGRAM_CHAT_ID, env_config.TELETHON_APP_CONFIG.APP_ID, env_config.TELETHON_APP_CONFIG.API_HASH, session)
TelethonFilesStorage(
env_config.TELEGRAM_CHAT_ID,
env_config.TELETHON_APP_CONFIG.APP_ID,
env_config.TELETHON_APP_CONFIG.API_HASH,
session,
)
for session in env_config.TELETHON_SESSIONS
]
@@ -99,7 +108,9 @@ class FileUploader:
if not cls.AIOGRAM_STORAGES:
raise ValueError("Aiogram storage not exist!")
cls._aiogram_storage_index = (cls._aiogram_storage_index + 1) % len(cls.AIOGRAM_STORAGES)
cls._aiogram_storage_index = (cls._aiogram_storage_index + 1) % len(
cls.AIOGRAM_STORAGES
)
return cls.AIOGRAM_STORAGES[cls._aiogram_storage_index]
@@ -108,12 +119,16 @@ class FileUploader:
if not cls.TELETHON_STORAGES:
raise ValueError("Telethon storage not exists!")
cls._telethon_storage_index = (cls._telethon_storage_index + 1) % len(cls.TELETHON_STORAGES)
cls._telethon_storage_index = (cls._telethon_storage_index + 1) % len(
cls.TELETHON_STORAGES
)
return cls.TELETHON_STORAGES[cls._telethon_storage_index]
@classmethod
async def upload(cls, file: UploadFile, caption: Optional[str] = None) -> Optional[UploadedFile]:
async def upload(
cls, file: UploadFile, caption: Optional[str] = None
) -> Optional[UploadedFile]:
uploader = cls(file, caption)
upload_result = await uploader._upload()