askrobots / dbbasic-content
Public
WordPress-style content management with block-based pages, stored as JSON files on disk instead of MySQL.
wordpress_migration.py · 1.2 KB · 44 lines
| 1 | """ |
| 2 | WordPress migration example. |
| 3 | |
| 4 | Shows how to import content from WordPress database. |
| 5 | """ |
| 6 | |
| 7 | from dbbasic_content import WordPressImporter, ContentDB |
| 8 | |
| 9 | # Import from WordPress database |
| 10 | with WordPressImporter( |
| 11 | host='localhost', |
| 12 | database='wordpress', |
| 13 | user='root', |
| 14 | password='secret' |
| 15 | ) as importer: |
| 16 | # Import all content |
| 17 | stats = importer.import_to('/var/app/content') |
| 18 | |
| 19 | print("Import complete!") |
| 20 | print(f" Posts: {stats['posts']}") |
| 21 | print(f" Pages: {stats['pages']}") |
| 22 | print(f" Drafts: {stats['drafts']}") |
| 23 | print(f" Total: {sum(stats.values())}") |
| 24 | |
| 25 | # Verify imported content |
| 26 | content = ContentDB('/var/app/content') |
| 27 | posts = content.get_posts() |
| 28 | |
| 29 | print(f"\nVerification: Found {len(posts)} posts in content directory") |
| 30 | |
| 31 | # Show sample post |
| 32 | if posts: |
| 33 | sample = posts[0] |
| 34 | print(f"\nSample post:") |
| 35 | print(f" Slug: {sample['slug']}") |
| 36 | print(f" Title: {sample['title']}") |
| 37 | print(f" Blocks: {len(sample['blocks'])}") |
| 38 | |
| 39 | # Show categories and tags |
| 40 | categories = content.get_categories() |
| 41 | tags = content.get_tags() |
| 42 | |
| 43 | print(f"\nCategories: {', '.join(categories)}") |
| 44 | print(f"Tags: {', '.join(tags[:10])}..." if len(tags) > 10 else f"Tags: {', '.join(tags)}") |