Skip to content

Commit

Permalink
Merge pull request #24 from Tishka17/fix/reformat
Browse files Browse the repository at this point in the history
Fix/reformat
  • Loading branch information
Tishka17 committed Oct 1, 2023
2 parents 3754124 + 93e3d0d commit 1216429
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/sulguk/post_manager/chat_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from aiogram import Bot
from aiogram.exceptions import TelegramBadRequest

from .exceptions import ChatNotFound
from .exceptions import ChatNotFoundError

logger = getLogger(__name__)

Expand All @@ -15,5 +15,5 @@ async def get_chat(bot: Bot, chat_id: Union[str, int]):
except TelegramBadRequest as e:
if "chat not found" in e.message:
logger.error("Chat %s not found", chat_id)
raise ChatNotFound
raise ChatNotFoundError from e
raise
4 changes: 2 additions & 2 deletions src/sulguk/post_manager/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ class ManagerError(Exception):
pass


class LinkedMessageNotFound(ManagerError):
class LinkedMessageNotFoundError(ManagerError):
pass


class ChatNotFound(ManagerError):
class ChatNotFoundError(ManagerError):
pass
6 changes: 3 additions & 3 deletions src/sulguk/post_manager/file.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

from sulguk import transform_html, RenderResult
from sulguk import RenderResult, transform_html
from .exceptions import ManagerError

logger = logging.getLogger(__name__)
Expand All @@ -10,6 +10,6 @@ def load_file(filename) -> RenderResult:
try:
with open(filename) as f:
return transform_html(f.read())
except FileNotFoundError:
except FileNotFoundError as e:
logger.error("File `%s` not found", filename)
raise ManagerError
raise ManagerError from e
12 changes: 6 additions & 6 deletions src/sulguk/post_manager/links.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from dataclasses import dataclass
from typing import Optional, Union
from urllib.parse import urlparse, parse_qs
from urllib.parse import parse_qs, urlparse

from aiogram.types import Message, Chat
from aiogram.types import Chat, Message


@dataclass
Expand Down Expand Up @@ -40,16 +40,16 @@ def parse_link(link: str) -> Link:
params = parse_qs(parsed.query)
try:
post_id = int(path[1])
except ValueError:
raise LinkParseError(f"Invalid post id: {path[1]}")
except ValueError as e:
raise LinkParseError(f"Invalid post id: {path[1]}") from e
comment_id_raw = params.get("comment")
if not comment_id_raw:
comment_id = None
elif len(comment_id_raw) == 1:
try:
comment_id = int(comment_id_raw[0])
except ValueError:
raise LinkParseError(f"Invalid comment id: {path[1]}")
except ValueError as e:
raise LinkParseError(f"Invalid comment id: {path[1]}") from e
else:
raise LinkParseError(f"Cannot parse comment id: {parsed.query}")
return Link(
Expand Down
6 changes: 3 additions & 3 deletions src/sulguk/post_manager/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ def init_parser():
subparsers = root.add_subparsers(dest="command")
sender = subparsers.add_parser("send")
sender.add_argument(
"destination", type=parse_link
"destination", type=parse_link,
)
sender.add_argument(
"file", nargs='+'
"file", nargs='+',
)
sender.add_argument(
"-m", "--mode", choices=["poll", "getChat"],
default="poll",
)
editor = subparsers.add_parser("edit")
editor.add_argument(
"destination", type=parse_link
"destination", type=parse_link,
)
editor.add_argument(
"file",
Expand Down
6 changes: 3 additions & 3 deletions src/sulguk/post_manager/sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from typing import Optional

from aiogram import Bot, Dispatcher, F
from aiogram.types import Message, Chat
from aiogram.types import Chat, Message

from .chat_info import get_chat
from .exceptions import LinkedMessageNotFound
from .exceptions import LinkedMessageNotFoundError
from .file import load_file
from .links import make_link, unparse_link
from .params import SendArgs
Expand Down Expand Up @@ -80,7 +80,7 @@ async def send(bot: Bot, args: SendArgs):
linked_message = await get_linked_message[args.mode](bot, chat, message)
if not linked_message:
logger.error("Cannot load linked message to leave a comment")
raise LinkedMessageNotFound("No linked message found")
raise LinkedMessageNotFoundError("No linked message found")
for file in args.file[1:]:
data = load_file(file)
comment = await bot.send_message(
Expand Down

0 comments on commit 1216429

Please sign in to comment.