Skill: dinghaibin/notion-helper (version 1.0.0)

--- name: notion-integration description: Work with Notion databases, pages, and APIs. Use when user needs to create, read, update, or delete Notion pages and databases; automate Notion workflows; sync data between Notion and other apps; or build integrations with Notion. --- # Notion Integration Manage Notion workspaces via API for automation and integration. ## Quick Start ```bash # Install Notion client pip install notion-client # Set API key export NOTION_TOKEN="secret_xxx" ``` ## Core Features - **Database Operations**: Create, query, update databases - **Page Management**: Create, read, update, delete pages - **Block Operations**: Add/update content blocks - **User Info**: Get workspace user information ## Script Usage ```bash # Query a database python scripts/notion.py query --database-id <id> # Create a page python scripts/notion.py create-page --database-id <id> --title "Task Name" # Get page content python scripts/notion.py get-page --page-id <id> ``` ## Setup 1. Create integration at https://www.notion.so/my-integrations 2. Share database/page with integration 3. Set NOTION_TOKEN environment variable ## Examples See `references/examples.md` for detailed use cases.

path: references/examples.md
content: # Notion Integration Examples

## Setup

1. Go to https://www.notion.so/my-integrations
2. Create a new integration
3. Copy the "Internal Integration Token" (starts with `secret_`)
4. Export it: `export NOTION_TOKEN='secret_xxx'`
5. Share your database with the integration (click ... on database > Add connections > Select your integration)

## Example 1: Query a Database

```bash
# Get all items from a todo database
python scripts/notion.py query --database-id YOUR_DATABASE_ID
```

## Example 2: Create a Task

```bash
# Create a new task in a database
python scripts/notion.py create-page \
  --database-id YOUR_DATABASE_ID \
  --title "Finish project report"
```

## Example 3: Update Task Status

```bash
# Update a page's status
python scripts/notion.py update-page \
  --page-id YOUR_PAGE_ID \
  --properties '{"Status": {"select": {"name": "Done"}}}'
```

## Example 4: Use in Python Code

```python
from notion_client import Client

notion = Client(auth=os.environ['NOTION_TOKEN'])

# Query database
results = notion.databases.query(
    database_id="YOUR_DATABASE_ID",
    filter={"property": "Status", "select": {"equals": "In Progress"}}
)

# Create page
notion.pages.create(
    parent={"database_id": "YOUR_DATABASE_ID"},
    properties={
        "Name": {"title": [{"text": {"content": "New Task"}}]},
        "Status": {"select": {"name": "To Do"}}
    }
)
```

## Common Use Cases

- **Task Management**: Sync tasks between Notion and other tools
- **Content Calendar**: Manage content schedules in Notion
- **CRM**: Track customers and deals
- **Knowledge Base**: Automated documentation

## Finding Database ID

From the database URL:
`https://notion.so/{username}/{database_id}?v={view_id}`

The database ID is the 32-character string after the username/.


path: scripts/notion.py
content: #!/usr/bin/env python3
"""
Notion Integration - Work with Notion API
Requires: pip install notion-client
"""

import os
import sys
import json
import argparse

NOTION_TOKEN = os.environ.get('NOTION_TOKEN')

def check_token():
    if not NOTION_TOKEN:
        print("Error: NOTION_TOKEN not set")
        print("Set it with: export NOTION_TOKEN='secret_xxx'")
        return False
    return True


def query_database(database_id):
    """Query a Notion database."""
    try:
        from notion_client import Client
        notion = Client(auth=NOTION_TOKEN)
        results = notion.databases.query(database_id=database_id)
        return results
    except ImportError:
        print("Error: notion-client not installed")
        print("Install with: pip install notion-client")
        return None
    except Exception as e:
        print(f"Error: {e}")
        return None


def create_page(database_id, title, properties=None):
    """Create a new page in a database."""
    try:
        from notion_client import Client
        notion = Client(auth=NOTION_TOKEN)
        
        props = {"Name": {"title": [{"text": {"content": title}}]}}
        if properties:
            props.update(properties)
        
        result = notion.pages.create(parent={"database_id": database_id}, properties=props)
        return result
    except ImportError:
        print("Error: notion-client not installed")
        return None
    except Exception as e:
        print(f"Error: {e}")
        return None


def get_page(page_id):
    """Get page content."""
    try:
        from notion_client import Client
        notion = Client(auth=NOTION_TOKEN)
        result = notion.pages.retrieve(page_id=page_id)
        return result
    except ImportError:
        print("Error: notion-client not installed")
        return None
    except Exception as e:
        print(f"Error: {e}")
        return None


def update_page(page_id, properties):
    """Update page properties."""
    try:
        from notion_client import Client
        notion = Client(auth=NOTION_TOKEN)
        result = notion.pages.update(page_id=page_id, properties=properties)
        return result
    except ImportError:
        print("Error: notion-client not installed")
        return None
    except Exception as e:
        print(f"Error: {e}")
        return None


def main():
    if not check_token():
        return 1
    
    parser = argparse.ArgumentParser(description='Notion Integration CLI')
    subparsers = parser.add_subparsers(dest='command', help='Commands')
    
    # Query command
    query_parser = subparsers.add_parser('query', help='Query a database')
    query_parser.add_argument('--database-id', required=True, help='Database ID')
    
    # Create page command
    create_parser = subparsers.add_parser('create-page', help='Create a page')
    create_parser.add_argument('--database-id', required=True, help='Database ID')
    create_parser.add_argument('--title', required=True, help='Page title')
    
    # Get page command
    get_parser = subparsers.add_parser('get-page', help='Get page content')
    get_parser.add_argument('--page-id', required=True, help='Page ID')
    
    # Update page command
    update_parser = subparsers.add_parser('update-page', help='Update page')
    update_parser.add_argument('--page-id', required=True, help='Page ID')
    update_parser.add_argument('--properties', help='JSON properties')
    
    args = parser.parse_args()
    
    if args.command == 'query':
        result = query_database(args.database_id)
    elif args.command == 'create-page':
        result = create_page(args.database_id, args.title)
    elif args.command == 'get-page':
        result = get_page(args.page_id)
    elif args.command == 'update-page':
        props = json.loads(args.properties) if args.properties else {}
        result = update_page(args.page_id, props)
    else:
        parser.print_help()
        return 0
    
    if result:
        print(json.dumps(result, indent=2))
        return 0
    return 1


if __name__ == '__main__':
    sys.exit(main())


Security scan verdicts — ClawScan: clean | static analysis: clean | VirusTotal: clean | SkillSpector: suspicious (HIGH)