Skip to content

Commit 89b5a05

Browse files
committed
feat: implement site auditing command with crawler and PDF report generation capabilities
1 parent a0b1907 commit 89b5a05

7 files changed

Lines changed: 15 additions & 7 deletions

File tree

-6.88 KB
Binary file not shown.

results/site_seo_report.pdf

-77.7 KB
Binary file not shown.
-11.2 KB
Binary file not shown.

src/openseo/commands/audit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ def audit(
409409
max_pages: Annotated[int, typer.Option("--max-pages", help="Max pages to crawl for site audits (0 for unlimited)")] = 10,
410410
max_depth: Annotated[int, typer.Option("--depth", help="Maximum directory depth to crawl")] = 3,
411411
ignore_robots: Annotated[bool, typer.Option("--ignore-robots", help="Ignore robots.txt instructions")] = False,
412-
report: Annotated[bool, typer.Option("--report", help="Generate a PDF report in results/ folder")] = False,
412+
report: Annotated[bool, typer.Option("--report", help="Generate a PDF report in Downloads folder")] = False,
413413
sitemap_only: Annotated[bool, typer.Option("--sitemap-only", help="Only crawl URLs listed in sitemap.xml")] = False,
414414
interactive: Annotated[bool, typer.Option("--interactive", "-i", help="Run audit in interactive mode")] = False,
415415
verbose: Annotated[bool, typer.Option("--verbose", "-v", help="Verbose output")] = False,
@@ -444,7 +444,7 @@ def audit(
444444
no_llm = disable_llm
445445

446446
# Ask about PDF report
447-
report = typer.confirm("Generate a PDF report in results/ folder?", default=True)
447+
report = typer.confirm("Generate a PDF report in Downloads folder?", default=True)
448448
typer.secho("\n🚀 Configuration locked! Starting audit...\n", fg=typer.colors.GREEN)
449449

450450
asyncio.run(

src/openseo/crawler/site_crawler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from openseo.crawler.http import HttpCrawler
1313
from openseo.crawler.playwright_crawler import PlaywrightCrawler
1414
from openseo.models.page import Page
15-
from openseo.constants import USER_AGENT
15+
from openseo.constants import CRAWLER_TIMEOUT, USER_AGENT
1616

1717
logger = logging.getLogger(__name__)
1818

@@ -84,7 +84,7 @@ async def initialize(self) -> None:
8484
if page.status_code == 200 and page.body_text:
8585
# Page extractor gets visible text. We need raw body, let's fetch it as text
8686
import httpx
87-
async with httpx.AsyncClient(headers={"User-Agent": USER_AGENT}) as client:
87+
async with httpx.AsyncClient(headers={"User-Agent": USER_AGENT}, timeout=CRAWLER_TIMEOUT) as client:
8888
resp = await client.get(robots_url, follow_redirects=True)
8989
if resp.status_code == 200:
9090
self.robots_txt_content = resp.text
@@ -109,7 +109,7 @@ async def initialize(self) -> None:
109109
for s_url in self.sitemap_urls:
110110
try:
111111
import httpx
112-
async with httpx.AsyncClient(headers={"User-Agent": USER_AGENT}) as client:
112+
async with httpx.AsyncClient(headers={"User-Agent": USER_AGENT}, timeout=CRAWLER_TIMEOUT) as client:
113113
resp = await client.get(s_url, follow_redirects=True)
114114
if resp.status_code == 200:
115115
soup = BeautifulSoup(resp.text, "xml")

src/openseo/outputs/pdf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class PdfRenderer:
2727
"""Generates beautiful, professional PDF reports for website audits."""
2828

2929
def __init__(self, output_dir: Path | None = None) -> None:
30-
# Default to "results" folder in the current working directory
31-
self.output_dir = output_dir or Path.cwd() / "results"
30+
# Default to "Downloads" folder in the user's home directory
31+
self.output_dir = output_dir or Path.home() / "Downloads"
3232
self.output_dir.mkdir(parents=True, exist_ok=True)
3333

3434
def generate_report(self, result: Any) -> str:

tests/unit/test_pdf.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,11 @@ def test_pdf_report_generation(tmp_path):
3636

3737
assert Path(file_path).exists()
3838
assert Path(file_path).name == "example_com_seo_report.pdf"
39+
40+
41+
def test_pdf_report_generation_default_dir(monkeypatch, tmp_path):
42+
monkeypatch.setattr(Path, "home", lambda: tmp_path)
43+
renderer = PdfRenderer()
44+
assert renderer.output_dir == tmp_path / "Downloads"
45+
assert renderer.output_dir.exists()
46+

0 commit comments

Comments
 (0)