From 6ee02687b1a9924cae35a46910be06c8c82c8249 Mon Sep 17 00:00:00 2001 From: Vadim Aleksandrov Date: Wed, 24 Apr 2024 17:43:11 +0300 Subject: [PATCH] fix: change torrent complete condition --- pyproject.toml | 2 +- torrent_telegram_bot/_version.py | 2 +- torrent_telegram_bot/bot.py | 11 +++++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f59c4d3..a92a395 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "torrent-telegram-bot" -version = "0.1.3" +version = "0.1.4" description = "" authors = ["Vadim Aleksandrov "] readme = "README.md" diff --git a/torrent_telegram_bot/_version.py b/torrent_telegram_bot/_version.py index ae73625..bbab024 100644 --- a/torrent_telegram_bot/_version.py +++ b/torrent_telegram_bot/_version.py @@ -1 +1 @@ -__version__ = "0.1.3" +__version__ = "0.1.4" diff --git a/torrent_telegram_bot/bot.py b/torrent_telegram_bot/bot.py index ddb9b3c..45bad9f 100755 --- a/torrent_telegram_bot/bot.py +++ b/torrent_telegram_bot/bot.py @@ -7,6 +7,7 @@ from pathlib import Path from textwrap import dedent from typing import Coroutine +from zoneinfo import ZoneInfo import sentry_sdk from emoji import emojize @@ -297,7 +298,9 @@ async def list_torrent_action(update, context, **kwargs): if len(torrents) > 0: try: for torrent in torrents: - if torrent.done_date is None or torrent.done_date == datetime.fromtimestamp(0): + if torrent.done_date is None or torrent.done_date == datetime.fromtimestamp(0, ZoneInfo("UTC")).replace( + tzinfo=None + ): try: eta = str(torrent.eta) except ValueError: @@ -319,7 +322,7 @@ async def list_torrent_action(update, context, **kwargs): Status: {torrent.status} Speed: {tools.humanize_bytes(torrent.upload_speed)}/s Peers: {torrent.num_seeds_upload} - Ratio: {torrent.ratio} + Ratio: {round(torrent.ratio, 2)} """ ) await context.bot.send_message( @@ -429,7 +432,7 @@ async def check_torrent_download_status(context): # noqa: C901 if ( task is not None and task.done_date is not None - and task.done_date != datetime.fromtimestamp(0) + and task.done_date != datetime.fromtimestamp(0, ZoneInfo("UTC")).replace(tzinfo=None) ): await db.complete_torrent(torrent[1]) except Exception as exc: @@ -438,7 +441,7 @@ async def check_torrent_download_status(context): # noqa: C901 if ( task is not None and task.done_date is not None - and task.done_date != datetime.fromtimestamp(0) + and task.done_date != datetime.fromtimestamp(0, ZoneInfo("UTC")).replace(tzinfo=None) ): response = f'Torrent "*{task.name}*" was successfully downloaded' try: