From 5d522cd6a93133599f2c870430d4911f11cdf3aa Mon Sep 17 00:00:00 2001
From: Philipp Kessling
Date: Fri, 3 Feb 2023 17:20:31 +0100
Subject: [PATCH 1/2] [fix] python3.8 compatibility
---
pyproject.toml | 2 +-
tegracli/dispatch.py | 21 ++++++++++-----------
tegracli/main.py | 4 ++--
tests/test_dispatchers.py | 6 +++---
4 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/pyproject.toml b/pyproject.toml
index d0140a7..6b46131 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -14,7 +14,7 @@ classifiers = [
]
[tool.poetry.dependencies]
-python = "^3.9"
+python = "^3.8"
Telethon = "^1.24.0"
ujson = "^5.4.0"
click = "^8.1.3"
diff --git a/tegracli/dispatch.py b/tegracli/dispatch.py
index 114b92b..d0a2564 100644
--- a/tegracli/dispatch.py
+++ b/tegracli/dispatch.py
@@ -1,11 +1,10 @@
-"""dispatch functions that dispatch requests to Telethon and MTProto
-"""
+"""Dispatch functions that request data from Telethon and MTProto."""
import datetime
import time
from functools import partial
from io import TextIOWrapper
from pathlib import Path
-from typing import Dict, Optional
+from typing import Dict, List, Optional
import telethon
import ujson
@@ -20,19 +19,19 @@
async def dispatch_iter_messages(
client: TelegramClient, params: Dict, callback: MessageHandler
) -> None:
- """dispatch a a TG-method with callback
+ """Dispatch a a TG-method with callback.
Parameters:
client : TelegramClient
params : Dict
- callback : Callable
+ callback : MessageHandler
"""
async for message in client.iter_messages(wait_time=10, **params):
await callback(message)
async def dispatch_get(users, client: TelegramClient, params: Dict):
- """get the message history of a specified set of users."""
+ """Get the message history of a specified set of users."""
for user in users:
done = False
@@ -62,8 +61,8 @@ async def dispatch_get(users, client: TelegramClient, params: Dict):
done = True
-async def dispatch_search(queries: list[str], client: TelegramClient):
- """dispatch a global search"""
+async def dispatch_search(queries: List[str], client: TelegramClient):
+ """Dispatch a global search."""
local_account = await client.get_me()
log.info(f"Using telegram accout of {local_account.username}")
for query in queries:
@@ -83,7 +82,7 @@ async def dispatch_search(queries: list[str], client: TelegramClient):
async def handle_message(
message: telethon.types.Message, file: TextIOWrapper, injects: Optional[Dict]
):
- """Accept incoming messages and log them to disk
+ """Accept incoming messages and log them to disk.
Parameters
----------
@@ -109,7 +108,7 @@ async def handle_message(
async def get_input_entity(
client: TelegramClient, member_id: int
) -> Optional[telethon.types.TypeInputPeer]:
- """wraps the client.get_input_entity function
+ """Wraps the client.get_input_entity function.
Parameters
----------
@@ -127,7 +126,7 @@ async def get_input_entity(
async def get_profile(
client: TelegramClient, member: str, group_name: str
) -> Optional[Dict[str, str]]:
- """Returns a Dict from the requested entity
+ """Returns a Dict from the requested entity.
Parameters
----------
diff --git a/tegracli/main.py b/tegracli/main.py
index 7556fc0..6f93c7c 100644
--- a/tegracli/main.py
+++ b/tegracli/main.py
@@ -108,7 +108,7 @@ def get( # pylint: disable=too-many-arguments
from_user: str,
reverse: bool,
reply_to: int,
- channels: list[str],
+ channels: List[str],
) -> None:
"""Get messages for the specified channels by either ID or username."""
client = get_client(ctx.obj["credentials"])
@@ -337,7 +337,7 @@ def _guarded_group_load(cwd: Path, _name: str) -> Group:
@cli.command()
@click.argument("queries", nargs=-1)
@click.pass_context
-def search(ctx: click.Context, queries: list[str]):
+def search(ctx: click.Context, queries: List[str]):
"""Searches Telegram content that is available to your account."""
client = get_client(ctx.obj["credentials"])
diff --git a/tests/test_dispatchers.py b/tests/test_dispatchers.py
index d6d291f..3f6452a 100644
--- a/tests/test_dispatchers.py
+++ b/tests/test_dispatchers.py
@@ -10,7 +10,7 @@
# pylint: disable=wrong-import-position
from pathlib import Path
-from typing import Dict
+from typing import Dict, List
import pytest
import yaml
@@ -36,7 +36,7 @@ def client():
@pytest.mark.api
@pytest.mark.enable_socket
-def test_search(queries: list[str], client: TelegramClient):
+def test_search(queries: List[str], client: TelegramClient):
"""Should run a search on the specified queries
Asserts
@@ -59,7 +59,7 @@ def test_search(queries: list[str], client: TelegramClient):
[{"limit": 1}, {"limit": 2, "reverse": True}, {"offset_id": 5, "limit": 1}],
)
@pytest.mark.parametrize("queries", [["channelnotfound123"], ["channel", "1446651076"]])
-def test_get(queries: list[str], client: TelegramClient, params: Dict):
+def test_get(queries: List[str], client: TelegramClient, params: Dict):
"""Should get message for existing channels
Asserts
From bd09f762a47fd788c25718a0246b4522759a480a Mon Sep 17 00:00:00 2001
From: Philipp Kessling
Date: Fri, 3 Feb 2023 17:23:25 +0100
Subject: [PATCH 2/2] [fix] add python3.8 GH-action
---
.github/workflows/main.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 281748f..0d622f8 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
- python-version: ["3.9", "3.10"] # "3.7", "3.8", "
+ python-version: ["3.8", "3.9", "3.10"] # "3.7", "3.8", "
steps:
- uses: actions/checkout@v3