Skip to content

Commit

Permalink
delete deprecated code (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
bralbral authored Aug 23, 2024
1 parent 2d42894 commit 26f09de
Show file tree
Hide file tree
Showing 20 changed files with 328 additions and 627 deletions.
1 change: 0 additions & 1 deletion src/bot/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
def superuser_commands() -> list[BotCommand]:
commands = [
BotCommand(command="add_user", description="Add user to bot."),
# BotCommand(command="users", description="Start Users Administration Dialog."),
BotCommand(command="add_channels", description="Add channels from file."),
BotCommand(command="scheduler_start", description="Start scheduler"),
BotCommand(command="scheduler_pause", description="Stop scheduler"),
Expand Down
22 changes: 0 additions & 22 deletions src/bot/dialogs/channel/on_click.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,6 @@ async def on_turn_off(callback: CallbackQuery, button: Button, manager: DialogMa
await manager.switch_to(ChannelsSG.turn_off)


async def on_turn_delete_errors(
callback: CallbackQuery, button: Button, manager: DialogManager
):
index = manager.dialog_data["current_page"]
channel: ChannelRetrieveDTO = manager.dialog_data["channels"][index]

if channel.id:
dal: DataAccessLayer = manager.start_data["dal"]

result = await dal.clear_channel_errors(channel_id=channel.id)

if result:
await callback.answer("Success.")
else:
await callback.answer("Cannot delete error rows.")
else:
await callback.answer("Cannot delete error rows.")

await manager.switch_to(state=ChannelsSG.scrolling)


async def on_turn_on(callback: CallbackQuery, button: Button, manager: DialogManager):
await manager.switch_to(ChannelsSG.turn_on)

Expand Down Expand Up @@ -114,7 +93,6 @@ async def on_perform_update(
"on_finish",
"on_perform_delete",
"on_perform_update",
"on_turn_delete_errors",
"on_turn_off",
"on_turn_on",
]
8 changes: 0 additions & 8 deletions src/bot/dialogs/channel/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from .on_click import on_finish
from .on_click import on_perform_delete
from .on_click import on_perform_update
from .on_click import on_turn_delete_errors
from .on_click import on_turn_off
from .on_click import on_turn_on
from .widgets import Viewer
Expand Down Expand Up @@ -69,13 +68,6 @@ def scroll_window():
Button(Const("✏️ Turn on"), id="off", on_click=on_turn_on),
Button(Const("✏️ Turn off"), id="on", on_click=on_turn_off),
),
Row(
Button(
Const("🧽 Delete errors"),
id="errors",
on_click=on_turn_delete_errors,
)
),
when=F["role"] == UserRole.SUPERUSER,
),
Row(
Expand Down
2 changes: 1 addition & 1 deletion src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
SQLITE_DATABASE_FILE_PATH: str = os.environ.get(
"SQLITE_DATABASE_FILE_PATH", os.path.join(ROOT_DIR, "youtube-notifier-bot.db")
)
VERSION: str = "2024-08-01.23"
VERSION: str = "2024-08-23.20"

__all__ = [
"CONFIG_FILE_PATH",
Expand Down
44 changes: 3 additions & 41 deletions src/db/dal.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@

from ..constants import SQLITE_DATABASE_FILE_PATH
from ..dto import ChannelCreateDTO
from ..dto import ChannelErrorCreateDTO
from ..dto import ChannelErrorRetrieveDTO
from ..dto import ChannelRetrieveDTO
from ..dto import MessageLogCreateDTO
from ..dto import MessageLogRetrieveDTO
from ..dto import UserCreateDTO
from ..dto import UserRetrieveDTO
from .dao import ChannelDAO
from .dao import ChannelErrorDAO
from .dao import MessageLogDAO
from .dao import UserRepo
from .exceptions import DatabaseDoesNotExist
from .models import ChannelErrorORM
from .models import ChannelORM
from .models import MessageLogORM
from .models import UserORM
Expand Down Expand Up @@ -67,11 +63,6 @@ def __init_repo(self) -> None:
schema=ChannelRetrieveDTO,
model_orm=ChannelORM,
)
self.__channel_error_repo = ChannelErrorDAO(
session=self.__session,
schema=ChannelErrorRetrieveDTO,
model_orm=ChannelErrorORM,
)
self.__message_log_repo = MessageLogDAO(
session=self.__session,
schema=MessageLogRetrieveDTO,
Expand Down Expand Up @@ -136,9 +127,9 @@ async def get_last_published_message_id(self) -> Optional[int]:
"""
:return:
"""
message_log_dto: Optional[
MessageLogRetrieveDTO
] = await self.__message_log_repo.get_by_attr()
message_log_dto: Optional[MessageLogRetrieveDTO] = (
await self.__message_log_repo.get_by_attr()
)
if message_log_dto:
return message_log_dto.message_id

Expand All @@ -164,17 +155,6 @@ async def create_channel(
"""
return await self.__channel_repo.create(channel_schema=channel_schema)

async def create_channel_error(
self, channel_error_schema: ChannelErrorCreateDTO
) -> int:
"""
:param channel_error_schema:
:return:
"""
return await self.__channel_error_repo.create(
channel_error_schema=channel_error_schema
)

async def get_channels(self, **kwargs) -> list[ChannelRetrieveDTO]:
"""
:param kwargs:
Expand All @@ -201,23 +181,5 @@ async def update_channel_by_id(self, _id: int, data: dict) -> Optional[int]:
"""
return await self.__channel_repo.update_by_pk(pk=_id, data=data)

async def auto_turn_off_channels(self, errors_limit: int) -> None:
"""
:return:
"""
channel_ids = await self.__channel_error_repo.get_channel_ids_with_errors_upper_then_limit(
limit=errors_limit
)

for channel_id in channel_ids:
await self.update_channel_by_id(_id=channel_id, data={"enabled": False})

return

async def clear_channel_errors(self, channel_id: int) -> list[int]:
return await self.__channel_error_repo.delete_by_attr(
**{"channel_id": channel_id}
)


__all__ = ["DataAccessLayer"]
3 changes: 1 addition & 2 deletions src/db/dao/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from .channel_errors import ChannelErrorDAO
from .channels import ChannelDAO
from .message_log import MessageLogDAO
from .users import UserRepo

__all__ = ["ChannelDAO", "ChannelErrorDAO", "MessageLogDAO", "UserRepo"]
__all__ = ["ChannelDAO", "MessageLogDAO", "UserRepo"]
39 changes: 0 additions & 39 deletions src/db/dao/channel_errors.py

This file was deleted.

7 changes: 0 additions & 7 deletions src/db/migrations/versions/da6a2af82a8b_init.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
"""init
Revision ID: da6a2af82a8b
Revises:
Create Date: 2023-12-19 17:55:42.111237
"""
from typing import Sequence
from typing import Union

Expand Down
43 changes: 43 additions & 0 deletions src/db/migrations/versions/f78d1309ec45_init.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from typing import Sequence
from typing import Union

import sqlalchemy as sa
from alembic import op


# revision identifiers, used by Alembic.
revision: str = "f78d1309ec45"
down_revision: Union[str, None] = "da6a2af82a8b"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index("ix_channel_errors_error", table_name="channel_errors")
op.drop_table("channel_errors")
op.drop_index("ix_users_is_admin", table_name="users")
op.drop_column("users", "is_admin")
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column("users", sa.Column("is_admin", sa.BOOLEAN(), nullable=True))
op.create_index("ix_users_is_admin", "users", ["is_admin"], unique=False)
op.create_table(
"channel_errors",
sa.Column("id", sa.INTEGER(), nullable=False),
sa.Column("error", sa.VARCHAR(length=512), nullable=False),
sa.Column("created_at", sa.TIMESTAMP(), nullable=False),
sa.Column("updated_at", sa.TIMESTAMP(), nullable=False),
sa.Column("channel_id", sa.INTEGER(), nullable=False),
sa.ForeignKeyConstraint(
["channel_id"], ["channels.id"], onupdate="CASCADE", ondelete="CASCADE"
),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(
"ix_channel_errors_error", "channel_errors", ["error"], unique=False
)
# ### end Alembic commands ###
2 changes: 0 additions & 2 deletions src/db/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
from .channel import ChannelORM
from .channel import ChannelORMRelatedModel
from .channel_errors import ChannelErrorORM
from .message_log import MessageLogORM
from .mixins.base import ModelORM
from .user import UserORM
from .user import UserORMRelatedModel

__all__ = [
"ChannelErrorORM",
"ChannelORM",
"ChannelORMRelatedModel",
"MessageLogORM",
Expand Down
38 changes: 0 additions & 38 deletions src/db/models/channel_errors.py

This file was deleted.

Loading

0 comments on commit 26f09de

Please sign in to comment.