Skip to content

Commit faa7dd7

Browse files
committed
Refactoring. Using f-strings
1 parent 10d6229 commit faa7dd7

11 files changed

Lines changed: 23 additions & 37 deletions

PySvn_examples/analys_commits.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
url = config.SVN_FILE_NAME
1212

1313
log_list = get_log_list(url)
14-
print("Total commits ({}):".format(len(log_list)))
14+
print(f"Total commits ({len(log_list)}):")
1515

1616
author_by_log = get_log_list_by_author(url, log_list)
1717

1818
for author, logs in sorted(
1919
author_by_log.items(), key=lambda item: len(item[1]), reverse=True
2020
):
21-
print(" {}: {}".format(author, len(logs)))
21+
print(f" {author}: {len(logs)}")

PySvn_examples/commit_watcher.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
last_log = get_log_list(url, limit=1)[0]
1616
last_revision = last_log.revision
1717
print(
18-
'Start from commit rev{} by {}: "{}" in {}'.format(
19-
last_revision, last_log.author, repr(last_log.msg), last_log.date
20-
)
18+
f'Start from commit rev{last_revision} by {last_log.author}: "{repr(last_log.msg)}" in {last_log.date}'
2119
)
2220

2321
while True:
@@ -30,14 +28,8 @@
3028

3129
if last_revision != last_log.revision:
3230
print(
33-
'commits +{} from: rev{} by {}: "{}" in {}....{}\n'.format(
34-
len(log_list),
35-
last_revision,
36-
last_log.author,
37-
repr(last_log.msg),
38-
last_log.date,
39-
log_list,
40-
)
31+
f'commits +{len(log_list)} from: rev{last_revision} by {last_log.author}: '
32+
f'"{repr(last_log.msg)}" in {last_log.date}....{log_list}\n'
4133
)
4234

4335
last_revision = last_log.revision

PySvn_examples/commits__draw_plot__by_all_authors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
ax.plot(
3838
df_month["year_month"],
3939
df_month["count"],
40-
label="{} ({})".format(author, len(logs)),
40+
label=f"{author} ({len(logs)})",
4141
)
4242

4343
ax.legend()

PySvn_examples/commits__draw_plot__by_single_author.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
ax.plot(
4040
df_month["year_month"],
4141
df_month["count"],
42-
label="{} ({})".format(AUTHOR, len(author_by_log[AUTHOR])),
42+
label=f"{AUTHOR} ({len(author_by_log[AUTHOR])})",
4343
)
4444
ax.legend()
4545
ax.grid()

PySvn_examples/commits__draw_plot__by_top5_authors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
ax.plot(
3838
df_month["year_month"],
3939
df_month["count"],
40-
label="{} ({})".format(author, len(logs)),
40+
label=f"{author} ({len(logs)})",
4141
)
4242

4343
ax.legend()

PySvn_examples/filter_log_by_message__print_release_version.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@
2222
release_version_log_list = [
2323
log for log in log_list if log.msg and "Release version" in log.msg
2424
]
25-
print("Release version log ({}):".format(len(release_version_log_list)))
25+
print(f"Release version log ({len(release_version_log_list)}):")
2626

2727
for i, log in enumerate(release_version_log_list, 1):
2828
print(
29-
' {:6}. [rev {}] {} {:15} "{}"'.format(
30-
i, log.revision, log.date, log.author, log.msg
31-
)
29+
f' {i:6}. [rev {log.revision}] {log.date} {log.author:15} "{log.msg}"'
3230
)

PySvn_examples/print_jira_by_date.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ def get_jira(msg):
5454
jira_items, key=lambda x: (x.split("-")[0], int(x.split("-")[1]))
5555
)
5656

57-
print("{}: ({})\t{}".format(month, len(jira_items), jira_items))
57+
print(f"{month}: ({len(jira_items)})\t{jira_items}")

qbittorrent_examples/check_changes_in_torrent.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def remove_previous_torrent_from_qbittorrent(qb, new_info_hash):
6868
# Remove previous torrents
6969
if info_hash_list:
7070
print(
71-
"Удаление предыдущих раздач этого торрента: {}".format(info_hash_list)
71+
f"Удаление предыдущих раздач этого торрента: {info_hash_list}"
7272
)
7373
qb.delete(info_hash_list)
7474

@@ -95,13 +95,11 @@ def remove_previous_torrent_from_qbittorrent(qb, new_info_hash):
9595
torrent_url
9696
)
9797
print(
98-
"{}: Проверка {}: {} / {}".format(
99-
today, torrent_url, torrent_file_url, info_hash
100-
)
98+
f"{today}: Проверка {torrent_url}: {torrent_file_url} / {info_hash}"
10199
)
102100

103101
if qb.get_torrent(info_hash):
104-
print("Торрент {} уже есть в списке раздачи".format(info_hash))
102+
print(f"Торрент {info_hash} уже есть в списке раздачи")
105103

106104
else:
107105
if info_hash != last_info_hash:
@@ -117,14 +115,12 @@ def remove_previous_torrent_from_qbittorrent(qb, new_info_hash):
117115

118116
if last_info_hash is None:
119117
print(
120-
"Добавление торрента с {} файлами: {}".format(
121-
len(new_files), new_files
122-
)
118+
f"Добавление торрента с {len(new_files)} файлами: {new_files}"
123119
)
124120
else:
125121
print("Торрент изменился, пора его перекачивать")
126122
print(
127-
"Добавлено {} файлов: {}".format(len(new_files), new_files)
123+
f"Добавлено {len(new_files)} файлов: {new_files}"
128124
)
129125

130126
last_info_hash = info_hash
@@ -138,7 +134,7 @@ def remove_previous_torrent_from_qbittorrent(qb, new_info_hash):
138134
url = "https://sms.ru/sms/send?api_id={api_id}&to={to}&text={text}".format(
139135
api_id=API_ID,
140136
to=TO,
141-
text="Вышла новая серия '{}'".format(torrent["info"]["name"]),
137+
text=f"Вышла новая серия '{torrent['info']['name']}'",
142138
)
143139
rs = requests.get(url)
144140
print(rs.text)

qbittorrent_examples/get_top5_torrent_by_size.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
print("Max top5:")
1818
for i, torrent in enumerate(torrents_max_top5, 1):
1919
print(
20-
" {}. {} ({})".format(i, torrent["name"], sizeof_fmt(torrent["total_size"]))
20+
f" {i}. {torrent['name']} ({sizeof_fmt(torrent['total_size'])})"
2121
)
2222

2323
print()
2424

2525
print("Min top5:")
2626
for i, torrent in enumerate(torrents_min_top5, 1):
2727
print(
28-
" {}. {} ({})".format(i, torrent["name"], sizeof_fmt(torrent["total_size"]))
28+
f" {i}. {torrent['name']} ({sizeof_fmt(torrent['total_size'])})"
2929
)

qbittorrent_examples/get_top5_torrent_by_size__use_api_sort_limit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
print("Max top5:")
1616
for i, torrent in enumerate(torrents_max_top5, 1):
1717
print(
18-
" {}. {} ({})".format(i, torrent["name"], sizeof_fmt(torrent["total_size"]))
18+
f" {i}. {torrent['name']} ({sizeof_fmt(torrent['total_size'])})"
1919
)
2020

2121
print()
2222

2323
print("Min top5:")
2424
for i, torrent in enumerate(torrents_min_top5, 1):
2525
print(
26-
" {}. {} ({})".format(i, torrent["name"], sizeof_fmt(torrent["total_size"]))
26+
f" {i}. {torrent['name']} ({sizeof_fmt(torrent['total_size'])})"
2727
)

0 commit comments

Comments
 (0)