diff --git a/antur/app.py b/antur/app.py index f442a21..4223823 100644 --- a/antur/app.py +++ b/antur/app.py @@ -35,7 +35,7 @@ class AnturApp(App): SUB_TITLE = f"v{__version__}" - show_markdown = reactive(False) + show_markdown = reactive(default=False) def __init__(self: "AnturApp", url: str | None = None, *, max_concurrent_requests: int) -> None: """Initialize the Antur application.""" @@ -46,7 +46,7 @@ def __init__(self: "AnturApp", url: str | None = None, *, max_concurrent_request def compose(self: "AnturApp") -> ComposeResult: """Compose the layout of the app.""" - yield Header(False) + yield Header(show_clock=False) yield SearchBar(self.url) with Vertical(id="contents"): with Vertical(id="main"): diff --git a/antur/utils/__init__.py b/antur/utils/__init__.py new file mode 100644 index 0000000..fbc0646 --- /dev/null +++ b/antur/utils/__init__.py @@ -0,0 +1 @@ +"""General utilities used through the application, such as sitemap parsing.""" diff --git a/antur/utils/sitemap_parser.py b/antur/utils/sitemap_parser.py index bc92e09..4c8361d 100644 --- a/antur/utils/sitemap_parser.py +++ b/antur/utils/sitemap_parser.py @@ -4,7 +4,7 @@ from dataclasses import dataclass import aiohttp -from lxml.etree import Element, fromstring, tostring +from lxml.etree import Element, XMLSyntaxError, fromstring, tostring from antur import __version__ @@ -29,7 +29,7 @@ class Error: HEADERS = { - "User-Agent": f"Mozilla/5.0 (compatible; AnturSitemap/{__version__}; +http://github.com/jb3/antur)" + "User-Agent": f"Mozilla/5.0 (compatible; AnturSitemap/{__version__}; +http://github.com/jb3/antur)", } IGNORE_TAGS = ["lastmod", "changefreq", "priority", "loc"] @@ -51,9 +51,13 @@ def __init__(self: "SitemapParser", url: str, max_concurrent_requests: int) -> N async def get_data(self: "SitemapParser", url: str) -> bytes: """Fetch the data from the URL.""" - async with aiohttp.ClientSession() as session, session.get( - url, headers=HEADERS - ) as response: + async with ( + aiohttp.ClientSession() as session, + session.get( + url, + headers=HEADERS, + ) as response, + ): return await response.read() def _filter_out_children(self: "SitemapParser", element: Element) -> Element: @@ -86,7 +90,7 @@ async def parse(self: "SitemapParser", url: str | None = None) -> dict[str, Entr try: parsed = fromstring(data) # noqa: S320 - except Exception as e: + except XMLSyntaxError as e: self.xml_errors += 1 return Error(url, str(e)) @@ -100,8 +104,9 @@ async def parse(self: "SitemapParser", url: str | None = None) -> dict[str, Entr results = await asyncio.gather(*child_tasks.values()) - for loc, result in zip(child_tasks.keys(), results): - level[loc] = result + level_data = dict(zip(child_tasks.keys(), results, strict=False)) + + level.update(level_data) if parsed.tag.endswith("urlset"): for child in parsed: diff --git a/antur/widgets/__init__.py b/antur/widgets/__init__.py new file mode 100644 index 0000000..c917d44 --- /dev/null +++ b/antur/widgets/__init__.py @@ -0,0 +1 @@ +"""Widgets used to display information through the application.""" diff --git a/antur/widgets/search_bar.py b/antur/widgets/search_bar.py index d6aa6ba..bb81d8c 100644 --- a/antur/widgets/search_bar.py +++ b/antur/widgets/search_bar.py @@ -19,7 +19,7 @@ def is_url(value: str) -> bool: return False return all([result.scheme, result.netloc]) - except Exception: + except ValueError: return False diff --git a/antur/widgets/sitemap_tree.py b/antur/widgets/sitemap_tree.py index 2ef455b..b579e17 100644 --- a/antur/widgets/sitemap_tree.py +++ b/antur/widgets/sitemap_tree.py @@ -28,7 +28,7 @@ def dict_to_tree(dictionary: dict, tree: Tree | TreeNode) -> None: """Move a dictionary into the provided tree structure in-place.""" for key, value in dictionary.items(): - if isinstance(value, (Entry, Error)): + if isinstance(value, Entry | Error): tree.add_leaf(key, data=value) else: sub_tree = tree.add(key) @@ -39,13 +39,17 @@ class CustomTree(Tree): """Custom tree widget to aid with formatting.""" def render_label( - self: "CustomTree", node: TreeNode, base_style: Style, additional_style: Style + self: "CustomTree", + node: TreeNode, + base_style: Style, + additional_style: Style, ) -> Text: """Render the label with a custom style.""" if hasattr(node, "data"): # noqa: SIM102 if isinstance(node.data, Error): additional_style = Style.chain( - additional_style, Style.from_color(Color.parse("red")) + additional_style, + Style.from_color(Color.parse("red")), ) return super().render_label(node, base_style, additional_style)