|
1 | 1 | #!/usr/bin/env python3
|
2 | 2 | # -*- coding: utf-8 -*-
|
3 | 3 |
|
4 |
| -__author__ = 'ipetrash' |
| 4 | +__author__ = "ipetrash" |
5 | 5 |
|
6 | 6 |
|
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 |
10 | 9 |
|
11 | 10 | # pip install tabulate
|
12 | 11 | from tabulate import tabulate
|
|
16 | 15 |
|
17 | 16 | from config import IP_HOST, USER, PASSWORD
|
18 | 17 |
|
19 |
| -sys.path.append(str(Path(__file__).resolve().parent.parent)) |
20 |
| -from human_byte_size import sizeof_fmt |
21 | 18 |
|
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): |
24 | 20 | if show_index:
|
25 | 21 | show_index = range(1, len(rows) + 1)
|
26 | 22 |
|
27 | 23 | text = tabulate(rows, headers=headers, tablefmt="grid", showindex=show_index)
|
28 | 24 | print(text)
|
29 | 25 |
|
30 | 26 |
|
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"] |
34 | 33 | print_table(rows, headers)
|
35 | 34 |
|
36 | 35 |
|
37 |
| -def print_torrents(torrents: List[Dict]): |
| 36 | +def print_torrents(torrents: list[dict]): |
38 | 37 | total_size = 0
|
39 | 38 |
|
40 | 39 | for i, torrent in enumerate(torrents, 1):
|
41 |
| - torrent_size = torrent['total_size'] |
| 40 | + torrent_size = torrent["total_size"] |
42 | 41 | total_size += torrent_size
|
43 | 42 |
|
44 | 43 | print(f"{i:3}. {torrent['name']} ({sizeof_fmt(torrent_size)})")
|
45 | 44 |
|
46 | 45 | 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 | + ) |
48 | 49 |
|
49 | 50 |
|
50 | 51 | def get_client() -> Client:
|
|
0 commit comments