A collection of Python scripts for managing Ghost blog content through the Ghost Admin API.
If these scripts were useful to you, consider donating to support the Developer Service Blog: https://buy.stripe.com/bIYdTrggi5lZamkdQW
Updates the visibility of posts in a Ghost blog to "paid" status for all posts published before the current year that are not already marked as paid.
Features:
- Automatically identifies posts from previous years that are not marked as paid
- Updates post visibility to "paid" status
- Handles API authentication securely
- Provides detailed logging of the update process
- Implements proper error handling and collision detection
Updates the visibility of posts in a Ghost blog to "members" status for all public posts published in the current year.
Features:
- Automatically identifies public posts from the current year
- Updates post visibility to "members" status
- Handles API authentication securely
- Provides detailed logging of the update process
- Implements proper error handling and collision detection
Searches for posts in your Ghost blog by title and displays detailed information about matching posts.
Features:
- Search posts by title using partial matches
- Display comprehensive post information including:
- Title
- Publication date
- Status
- Visibility
- Public URL
- Admin edit URL
- Handles API authentication securely
- Provides detailed logging of the search process
- Python 3.6 or higher
- Required Python packages:
requests
python-jwt
python-dotenv
- Clone this repository or download the scripts
- Install the required packages:
pip install requests python-jwt python-dotenv
Create a .env
file in the same directory as the scripts with the following variables:
GHOST_URL=your_ghost_url
GHOST_ADMIN_API_KEY=your_admin_api_key
GHOST_URL
: Your Ghost blog URL (e.g.,https://your-blog.com
)GHOST_ADMIN_API_KEY
: Your Ghost Admin API key (format:id:secret
)
python update_posts_to_paid.py
This script will:
- Connect to your Ghost blog using the Admin API
- Find all posts from previous years that are not marked as paid
- Update their visibility to "paid" status
- Log the progress and results
python update_posts_member.py
This script will:
- Connect to your Ghost blog using the Admin API
- Find all public posts from the current year
- Update their visibility to "members" status
- Log the progress and results
python post_search.py
This script will:
- Prompt you to enter a search term
- Search for posts with matching titles
- Display detailed information about each matching post
- Provide both public and admin edit URLs for each post
All scripts provide detailed logging of their operations:
- Number of posts found that need updating (for update scripts)
- Success/failure status for each post update
- Total number of successfully updated posts
- Detailed post information (for search script)
The scripts include comprehensive error handling:
- Validates environment variables
- Handles API authentication errors
- Manages individual post update failures
- Provides detailed error messages in the logs
- API credentials are stored in environment variables
- JWT tokens are generated with a 5-minute expiration
- No sensitive data is logged
This project is open source and available under the MIT License.