-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathexample_usage.py
More file actions
103 lines (80 loc) · 3.09 KB
/
Copy pathexample_usage.py
File metadata and controls
103 lines (80 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python3
"""
Example usage of the Base44 Documentation Scraper
Demonstrates different ways to query and use the system
"""
from pathlib import Path
from rich.console import Console
from rich.table import Table
from base44_docs_scraper import Base44DocsScraper
from cursor_integration import search_docs, get_page_content, get_docs_stats
console = Console()
def demo_basic_search():
"""Demonstrate basic search functionality."""
console.print("\n[bold blue]Basic Search Demo[/bold blue]")
console.print("=" * 50)
scraper = Base44DocsScraper()
queries = [
"authentication",
"integrations",
"AI agents",
"custom domain"
]
for query in queries:
console.print(f"\n[cyan]Searching for: '{query}'[/cyan]")
results = scraper.search(query, limit=3, include_content=False)
if results:
for result in results:
console.print(f" - {result['title']} ({result['section']})")
else:
console.print("[yellow]No results found[/yellow]")
def demo_stats():
"""Show database statistics."""
console.print("\n[bold blue]Database Stats[/bold blue]")
console.print("=" * 50)
stats = get_docs_stats()
table = Table()
table.add_column("Metric", style="cyan")
table.add_column("Value", style="green")
table.add_row("Total Pages", str(stats['total_pages']))
table.add_row("Total Words", f"{stats['total_words']:,}")
table.add_row("Last Update", stats['last_update'] or "Never")
console.print(table)
if stats['section_counts']:
console.print("\n[cyan]Pages by Section:[/cyan]")
for section, count in stats['section_counts'].items():
console.print(f" {section}: {count}")
def demo_page_retrieval():
"""Demonstrate page retrieval."""
console.print("\n[bold blue]Page Retrieval Demo[/bold blue]")
console.print("=" * 50)
urls = [
"/Getting-Started/Quick-start-guide",
"/Integrations/Using-integrations"
]
for url in urls:
console.print(f"\n[cyan]Getting: {url}[/cyan]")
page = get_page_content(url)
if page:
console.print(f" Title: {page.get('title', 'N/A')}")
console.print(f" Words: {page.get('word_count', 0)}")
console.print(f" Section: {page.get('section', 'N/A')}")
else:
console.print("[yellow]Page not found[/yellow]")
def main():
"""Run demonstrations."""
console.print("[bold green]Base44 Docs Scraper Demo[/bold green]")
db_path = Path("base44_docs.db")
if not db_path.exists():
console.print("\n[red]No database found![/red]")
console.print("[yellow]Run 'python3 base44_docs_scraper.py scrape' first[/yellow]")
return
try:
demo_stats()
demo_basic_search()
demo_page_retrieval()
console.print("\n[bold green]Demo completed![/bold green]")
except Exception as e:
console.print(f"\n[red]Demo failed: {e}[/red]")
if __name__ == "__main__":
main()