The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Create a blog auto-publisher

To create a blog auto-publisher, you can develop a script or web app that takes your articles and automatically publishes them to your blog (e.g., WordPress, Ghost, or a custom CMS) on a schedule or via API integration. Here’s a basic outline using Python for a WordPress site via REST API. This script assumes you already have your article content available as plain text or HTML.


Prerequisites

  • Python 3 installed

  • WordPress site with REST API enabled

  • Application password for authentication

  • requests library (pip install requests)


Python Script: Blog Auto-Publisher for WordPress

python
import requests from datetime import datetime, timedelta import os # === Configuration === WORDPRESS_URL = "https://yourdomain.com/wp-json/wp/v2" USERNAME = "your_username" APPLICATION_PASSWORD = "your_app_password" POSTS_DIR = "path/to/articles" # Folder with text or HTML files # === Authentication === auth = (USERNAME, APPLICATION_PASSWORD) # === Helper Function to Post === def publish_post(title, content, categories=[], tags=[], status="publish"): post = { "title": title, "content": content, "status": status, # draft, publish, future "categories": categories, "tags": tags, } response = requests.post(f"{WORDPRESS_URL}/posts", auth=auth, json=post) if response.status_code == 201: print(f"Published: {title}") else: print(f"Failed to publish {title}: {response.text}") # === Main Script to Loop Through Articles === def run_auto_publisher(schedule_days=0): files = [f for f in os.listdir(POSTS_DIR) if f.endswith(".txt") or f.endswith(".html")] for index, filename in enumerate(sorted(files)): filepath = os.path.join(POSTS_DIR, filename) with open(filepath, "r", encoding="utf-8") as file: content = file.read() title = filename.replace("-", " ").replace("_", " ").replace(".txt", "").replace(".html", "").title() scheduled_date = datetime.now() + timedelta(days=schedule_days * index) status = "future" if schedule_days > 0 else "publish" post = { "title": title, "content": content, "status": status, "date": scheduled_date.isoformat(), } response = requests.post(f"{WORDPRESS_URL}/posts", auth=auth, json=post) if response.status_code == 201: print(f"Scheduled: {title} for {scheduled_date}") else: print(f"Error: {response.status_code} - {response.text}") # === Run the Auto-Publisher === run_auto_publisher(schedule_days=1) # Adjust to 0 for instant publish, 1 for daily schedule

Features

  • Reads .txt or .html files from a folder

  • Converts filenames to titles

  • Publishes immediately or schedules with a daily interval

  • Automatically publishes via WordPress REST API


Optional Enhancements

  • Read article metadata (title, tags, categories) from front matter

  • Add logging for successful/failed posts

  • Email notification on publish

  • Integration with Google Sheets or CMS backend

Let me know your blog platform if you’re not using WordPress, and I can tailor the solution.

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About