WordPress-style content management with block-based pages, stored as JSON files on disk instead of MySQL.

0 downloads

dbbasic-content/examples/basic_usage.py
Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-content.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-content.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-content.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

danq9 Release v0.2.0 - Pages support 25b7e5e 1 year, 1 month ago History
basic_usage.py · 1.9 KB · 83 lines
1"""
2Basic usage examples for dbbasic-content.
3"""
4
5from dbbasic_content import ContentDB
6
7# Initialize content database
8content = ContentDB('/tmp/example_content')
9
10# Create a post
11post = content.create_post(
12 slug='hello-world',
13 title='Hello World',
14 author='john',
15 categories=['Technology', 'Python'],
16 tags=['tutorial', 'beginner'],
17 blocks=[
18 {
19 'type': 'paragraph',
20 'data': {
21 'content': 'Welcome to my blog! This is my first post.'
22 }
23 },
24 {
25 'type': 'heading',
26 'data': {
27 'level': 2,
28 'content': 'Getting Started'
29 }
30 },
31 {
32 'type': 'paragraph',
33 'data': {
34 'content': 'Here are some things you should know...'
35 }
36 },
37 {
38 'type': 'list',
39 'data': {
40 'listType': 'unordered',
41 'items': [
42 'Item one',
43 'Item two',
44 'Item three'
45 ]
46 }
47 }
48 ]
49)
50
51print(f"Created post: {post['slug']}")
52
53# Get a post
54retrieved_post = content.get_post('hello-world')
55print(f"Retrieved: {retrieved_post['title']}")
56
57# Get all published posts
58posts = content.get_posts(status='published', limit=10)
59print(f"Found {len(posts)} published posts")
60
61# Get posts by category
62tech_posts = content.get_posts(categories=['Technology'])
63print(f"Found {len(tech_posts)} tech posts")
64
65# Search posts
66results = content.search('Python')
67print(f"Search found {len(results)} results")
68
69# Update a post
70updated = content.update_post(
71 'hello-world',
72 title='Hello World - Updated!',
73 status='draft'
74)
75print(f"Updated post: {updated['title']}")
76
77# Get all categories
78categories = content.get_categories()
79print(f"Categories: {', '.join(categories)}")
80
81# Get all tags
82tags = content.get_tags()
83print(f"Tags: {', '.join(tags)}")