Skip to content

Commit

Permalink
fix: change torrent complete condition
Browse files Browse the repository at this point in the history
  • Loading branch information
verdel committed Apr 24, 2024
1 parent 286c140 commit 7273aad
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "torrent-telegram-bot"
version = "0.1.3"
version = "0.1.4"
description = ""
authors = ["Vadim Aleksandrov <[email protected]>"]
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion torrent_telegram_bot/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.3"
__version__ = "0.1.4"
11 changes: 7 additions & 4 deletions torrent_telegram_bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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(
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
13 changes: 10 additions & 3 deletions torrent_telegram_bot/qbittorrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import string
from datetime import datetime, timedelta
from time import sleep
from zoneinfo import ZoneInfo

from qbittorrentapi import Client

Expand Down Expand Up @@ -40,7 +41,9 @@ def get_torrents(self) -> list[Torrent]:
Torrent(
torrent_id=str(torrent.hash),
name=torrent.name,
done_date=datetime.fromtimestamp(torrent.completion_on),
done_date=datetime.fromtimestamp(
0 if torrent.completion_on < 0 else torrent.completion_on, ZoneInfo("UTC")
).replace(tzinfo=None),
eta=timedelta(seconds=torrent.eta),
status=torrent.state,
progress=torrent.progress * 100,
Expand All @@ -61,7 +64,9 @@ def get_torrent(self, torrent_id: str) -> Torrent | None:
return Torrent(
torrent_id=str(torrent.hash),
name=torrent.name,
done_date=datetime.fromtimestamp(torrent.completion_on),
done_date=datetime.fromtimestamp(
0 if torrent.completion_on < 0 else torrent.completion_on, ZoneInfo("UTC")
).replace(tzinfo=None),
eta=timedelta(seconds=torrent.eta),
status=torrent.state,
progress=torrent.progress * 100,
Expand Down Expand Up @@ -104,7 +109,9 @@ def add_torrent(self, torrent_data: bytes, **kwargs) -> Torrent:
return Torrent(
torrent_id=str(torrent.hash),
name=torrent.name,
done_date=datetime.fromtimestamp(torrent.completion_on),
done_date=datetime.fromtimestamp(
0 if torrent.completion_on < 0 else torrent.completion_on, ZoneInfo("UTC")
).replace(tzinfo=None),
eta=timedelta(seconds=torrent.eta),
status=torrent.state,
progress=torrent.progress * 100,
Expand Down

0 comments on commit 7273aad

Please sign in to comment.