Skip to content

Commit ec4a623

Browse files
committed
Refactoring
1 parent 798fc41 commit ec4a623

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

qbittorrent_examples/common.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33

4-
__author__ = 'ipetrash'
4+
__author__ = "ipetrash"
55

66

7-
import sys
8-
from typing import List, Dict
9-
from pathlib import Path
7+
# pip install humanize
8+
from humanize import naturalsize as sizeof_fmt
109

1110
# pip install tabulate
1211
from tabulate import tabulate
@@ -16,35 +15,37 @@
1615

1716
from config import IP_HOST, USER, PASSWORD
1817

19-
sys.path.append(str(Path(__file__).resolve().parent.parent))
20-
from human_byte_size import sizeof_fmt
2118

22-
23-
def print_table(rows: List[List[str]], headers: List[str], show_index=True):
19+
def print_table(rows: list[list[str]], headers: list[str], show_index=True):
2420
if show_index:
2521
show_index = range(1, len(rows) + 1)
2622

2723
text = tabulate(rows, headers=headers, tablefmt="grid", showindex=show_index)
2824
print(text)
2925

3026

31-
def print_files_table(files: List[Dict]):
32-
rows = [(file['name'], sizeof_fmt(file['size'])) for file in sorted(files, key=lambda x: x['name'])]
33-
headers = ['#', 'File Name', 'Size']
27+
def print_files_table(files: list[dict]):
28+
rows = [
29+
(file["name"], sizeof_fmt(file["size"]))
30+
for file in sorted(files, key=lambda x: x["name"])
31+
]
32+
headers = ["#", "File Name", "Size"]
3433
print_table(rows, headers)
3534

3635

37-
def print_torrents(torrents: List[Dict]):
36+
def print_torrents(torrents: list[dict]):
3837
total_size = 0
3938

4039
for i, torrent in enumerate(torrents, 1):
41-
torrent_size = torrent['total_size']
40+
torrent_size = torrent["total_size"]
4241
total_size += torrent_size
4342

4443
print(f"{i:3}. {torrent['name']} ({sizeof_fmt(torrent_size)})")
4544

4645
print()
47-
print(f'Total torrents: {len(torrents)}, total size: {sizeof_fmt(total_size)} ({total_size} bytes)')
46+
print(
47+
f"Total torrents: {len(torrents)}, total size: {sizeof_fmt(total_size)} ({total_size} bytes)"
48+
)
4849

4950

5051
def get_client() -> Client:

0 commit comments

Comments
 (0)