Skip to content

Commit 48e70c5

Browse files
committed
Fix code formatting and linting issues
1 parent ad38d27 commit 48e70c5

File tree

1 file changed

+24
-27
lines changed

1 file changed

+24
-27
lines changed

src/mdtk/bookmarks.py

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
"""Convert Chrome bookmarks to markdown format."""
22

3-
from bs4 import BeautifulSoup
3+
import argparse
4+
import sys
45
from pathlib import Path
56
from typing import Optional
67

8+
from bs4 import BeautifulSoup
9+
10+
711
class BookmarkError(Exception):
812
"""Base exception for bookmark conversion errors."""
9-
pass
1013

11-
def convert_bookmarks(input_file: Path, output_file: Path, folder_name: Optional[str] = "EXPORT_FOLDER") -> None:
14+
15+
def convert_bookmarks(
16+
input_file: Path, output_file: Path, folder_name: Optional[str] = "EXPORT_FOLDER"
17+
) -> None:
1218
"""Convert Chrome bookmarks HTML file to markdown format."""
1319
# Validate inputs
1420
if not isinstance(input_file, Path):
@@ -27,13 +33,13 @@ def convert_bookmarks(input_file: Path, output_file: Path, folder_name: Optional
2733
raise BookmarkError(f"Output directory does not exist: {output_file.parent}")
2834

2935
try:
30-
with open(input_file, 'r', encoding='utf-8') as f:
31-
soup = BeautifulSoup(f, 'html.parser')
36+
with open(input_file, "r", encoding="utf-8") as f:
37+
soup = BeautifulSoup(f, "html.parser")
3238
except Exception as e:
3339
raise BookmarkError(f"Failed to parse HTML file: {e}")
3440

3541
# Find target folder
36-
folders = soup.find_all('h3')
42+
folders = soup.find_all("h3")
3743
target_folder = None
3844
for folder in folders:
3945
if folder.string == folder_name:
@@ -44,39 +50,29 @@ def convert_bookmarks(input_file: Path, output_file: Path, folder_name: Optional
4450
raise BookmarkError(f"Folder '{folder_name}' not found!")
4551

4652
try:
47-
bookmarks_dl = target_folder.find_next('dl')
53+
bookmarks_dl = target_folder.find_next("dl")
4854
if not bookmarks_dl:
4955
raise BookmarkError(f"No bookmarks found in folder '{folder_name}'")
50-
bookmarks = bookmarks_dl.find_all('a')
56+
bookmarks = bookmarks_dl.find_all("a")
5157

52-
with open(output_file, 'w', encoding='utf-8') as f:
58+
with open(output_file, "w", encoding="utf-8") as f:
5359
for bookmark in bookmarks:
5460
title = bookmark.string or "Untitled"
55-
url = bookmark.get('href', '')
61+
url = bookmark.get("href", "")
5662
f.write(f"- [{title}]({url})\n")
5763
except Exception as e:
5864
raise BookmarkError(f"Failed to process bookmarks: {e}")
5965

66+
6067
def main():
6168
"""Command line interface."""
62-
import argparse
63-
import sys
64-
65-
parser = argparse.ArgumentParser(
66-
description="Convert Chrome bookmarks to markdown format"
67-
)
68-
parser.add_argument(
69-
'input_file',
70-
help="Chrome bookmarks HTML file"
71-
)
69+
parser = argparse.ArgumentParser(description="Convert Chrome bookmarks to markdown format")
70+
parser.add_argument("input_file", help="Chrome bookmarks HTML file")
71+
parser.add_argument("output_file", help="Output markdown file")
7272
parser.add_argument(
73-
'output_file',
74-
help="Output markdown file"
75-
)
76-
parser.add_argument(
77-
'--folder',
73+
"--folder",
7874
default="EXPORT_FOLDER",
79-
help="Folder name to extract (default: EXPORT_FOLDER)"
75+
help="Folder name to extract (default: EXPORT_FOLDER)",
8076
)
8177

8278
args = parser.parse_args()
@@ -90,5 +86,6 @@ def main():
9086
print(f"Unexpected error: {e}", file=sys.stderr)
9187
sys.exit(1)
9288

93-
if __name__ == '__main__':
89+
90+
if __name__ == "__main__":
9491
main()

0 commit comments

Comments
 (0)