diff --git a/main.py b/main.py index 2d50b05..268aece 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import html from functools import wraps from typing import TYPE_CHECKING @@ -8,7 +10,7 @@ from telegram.ext import (ApplicationBuilder, CallbackQueryHandler, CommandHandl InlineQueryHandler, MessageHandler, PicklePersistence, filters) import common -from tweet import TGTweet +from tweet import TelegramTweet if TYPE_CHECKING: from telegram import Chat, Message, Update diff --git a/tweet.py b/tweet.py index 35d8208..0e1f8a5 100644 --- a/tweet.py +++ b/tweet.py @@ -1,5 +1,9 @@ +from __future__ import annotations + import html -from typing import Generator +from functools import cached_property +from typing import TYPE_CHECKING +from uuid import uuid4 from httpx import AsyncClient from telegram import (InlineQueryResultMpeg4Gif, InlineQueryResultPhoto, InlineQueryResultVideo, InputMediaPhoto, @@ -7,6 +11,9 @@ from telegram import (InlineQueryResultMpeg4Gif, InlineQueryResultPhoto, InlineQ from common import get_logger, x_media_regex, x_tco_regex, x_url_regex +if TYPE_CHECKING: + from typing import Generator, TypedDict + logger = get_logger(__name__) @@ -18,15 +25,15 @@ message_raw_text = """{url} """ -def create_client() -> 'AsyncClient': +def create_client() -> AsyncClient: return AsyncClient(http2=True) -async def close_client(_client: 'AsyncClient') -> None: +async def close_client(_client: AsyncClient) -> None: await _client.aclose() -async def fetch_json(_client: 'AsyncClient', url: str) -> dict: +async def fetch_json(_client: AsyncClient, url: str) -> dict: logger.info(f"Fetching {url}") response = await _client.get(url) assert response.status_code == response.is_success, f"Failed to fetch {url}, status code {response.status_code}"