Skip to content

Commit

Permalink
Merge pull request #36 from Leibniz-HBI/35-python38-compatibility
Browse files Browse the repository at this point in the history
[fix] python3.8 compatibility
  • Loading branch information
FlxVctr authored Feb 3, 2023
2 parents 3abc406 + bd09f76 commit 1379580
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
21 changes: 10 additions & 11 deletions tegracli/dispatch.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
----------
Expand All @@ -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
----------
Expand All @@ -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
----------
Expand Down
4 changes: 2 additions & 2 deletions tegracli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down Expand Up @@ -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"])

Expand Down
6 changes: 3 additions & 3 deletions tests/test_dispatchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 1379580

Please sign in to comment.