askrobots / dbbasic-cli
Public
Make a complete, running app (a CRM, a shop, a blog) with one command, such as dbbasic crm.
blog.py · 2.2 KB · 67 lines
| 1 | """Create instant blog application""" |
| 2 | |
| 3 | import typer |
| 4 | from rich.console import Console |
| 5 | from rich.progress import Progress, SpinnerColumn, TextColumn |
| 6 | import time |
| 7 | from pathlib import Path |
| 8 | |
| 9 | console = Console() |
| 10 | |
| 11 | def create_blog( |
| 12 | name: str = typer.Argument("blog", help="Project name"), |
| 13 | port: int = typer.Option(8000, "--port", "-p", help="Port to run on") |
| 14 | ): |
| 15 | """Create instant blog application with posts, comments, and SEO""" |
| 16 | |
| 17 | start_time = time.time() |
| 18 | |
| 19 | with Progress( |
| 20 | SpinnerColumn(), |
| 21 | TextColumn("[progress.description]{task.description}"), |
| 22 | console=console, |
| 23 | ) as progress: |
| 24 | |
| 25 | task = progress.add_task("Creating blog application...", total=5) |
| 26 | project_dir = Path.cwd() / name |
| 27 | |
| 28 | if project_dir.exists(): |
| 29 | console.print(f"[red]Directory {name} already exists![/red]") |
| 30 | raise typer.Exit(1) |
| 31 | |
| 32 | project_dir.mkdir(parents=True) |
| 33 | progress.advance(task) |
| 34 | |
| 35 | progress.update(task, description="Setting up content management...") |
| 36 | time.sleep(0.5) |
| 37 | progress.advance(task) |
| 38 | |
| 39 | progress.update(task, description="Configuring SEO...") |
| 40 | time.sleep(0.5) |
| 41 | progress.advance(task) |
| 42 | |
| 43 | progress.update(task, description="Adding comment system...") |
| 44 | time.sleep(0.5) |
| 45 | progress.advance(task) |
| 46 | |
| 47 | progress.update(task, description="Creating sample posts...") |
| 48 | time.sleep(0.5) |
| 49 | progress.advance(task) |
| 50 | |
| 51 | elapsed = time.time() - start_time |
| 52 | |
| 53 | console.print(f"\n[bold green]✅ Blog created in {elapsed:.1f} seconds![/bold green]\n") |
| 54 | console.print(f"[bold]Your blog is ready at:[/bold] {project_dir}\n") |
| 55 | console.print("[bold]Features included:[/bold]") |
| 56 | console.print("• Post editor with Markdown") |
| 57 | console.print("• Categories & tags") |
| 58 | console.print("• Comments with moderation") |
| 59 | console.print("• SEO optimization") |
| 60 | console.print("• RSS feed") |
| 61 | console.print("• Social sharing") |
| 62 | console.print("• Sample posts\n") |
| 63 | |
| 64 | console.print("[bold]To start your blog:[/bold]") |
| 65 | console.print(f" cd {name}") |
| 66 | console.print(f" dbbasic start\n") |
| 67 | console.print(f"Then open: [blue]http://localhost:{port}[/blue]") |