Automation

Automate WordPress Blog Posting with Python, MySQL & Cloudinary (Step-by-Step)

📘 Automate WordPress Blog Posting with Python, MySQL & Cloudinary – Step-by-Step Guide

Automating your WordPress blog posting can save hours of manual work. In this guide, we’ll show how to automatically post Qur’anic ayahs and tafsir content directly to your WordPress.com blog using:

  • ✅ Python for scripting
  • ✅ MySQL for ayah storage
  • ✅ Cloudinary for image hosting
  • ✅ WordPress.com REST API

✅ What You’ll Need

  • A free WordPress.com blog (e.g. yourblog.wordpress.com)
  • Developer app created at: WordPress Developer Console
  • MySQL database with ayah content
  • Cloudinary account (for uploading ayah images)
  • Python 3 environment with required libraries

✅ Step 1: Setup WordPress App

Go to WordPress Developer Console and register your app:

  • Redirect URLs: http://localhost (or your app site)
  • Client ID & Secret: Copy these values for your script

✅ Step 2: Authenticate via OAuth

Use this Python snippet to get the access token:


import requests, webbrowser

CLIENT_ID = 'YOUR_CLIENT_ID'
REDIRECT_URI = 'http://localhost'
auth_url = f"https://public-api.wordpress.com/oauth2/authorize?client_id={CLIENT_ID}&redirect_uri={REDIRECT_URI}&response_type=code"
webbrowser.open(auth_url)
  

After logging in, copy the ?code=XYZ from the URL.

✅ Step 3: Exchange Code for Token


response = requests.post('https://public-api.wordpress.com/oauth2/token', data={
    'client_id': CLIENT_ID,
    'client_secret': 'YOUR_CLIENT_SECRET',
    'redirect_uri': REDIRECT_URI,
    'grant_type': 'authorization_code',
    'code': 'PASTED_CODE'
})
access_token = response.json()['access_token']
  

✅ Step 4: Upload Image to Cloudinary


import cloudinary
import cloudinary.uploader

cloudinary.config(
  cloud_name='your_cloud',
  api_key='your_key',
  api_secret='your_secret'
)

def upload_image(path):
    return cloudinary.uploader.upload(path)['secure_url']
  

✅ Step 5: Post to WordPress


post_data = {
    'title': 'Surah Baqarah – Ayah 1',
    'content': '<p>Bismillah...</p>',
    'status': 'publish',
    'tags': 'Surah Baqarah, Tafsir',
    'categories': 'Quran'
}

headers = {'Authorization': f'Bearer {access_token}'}
requests.post('https://public-api.wordpress.com/rest/v1.1/sites/yourblog.wordpress.com/posts/new', data=post_data, headers=headers)
  

✅ Step 6: Full Automation Loop

You can connect to your MySQL database and loop through ayahs that are not yet posted.


import mysql.connector

conn = mysql.connector.connect(
    host='localhost', user='root', password='pass', database='quran'
)
cursor = conn.cursor(dictionary=True)
cursor.execute("SELECT * FROM ayat_indian WHERE sent_status = 0 LIMIT 1")

for row in cursor:
    arabic = row['arabic']
    translation = row['translation']
    tafsir = row['tafsir']
    # Build HTML, upload image, then post
  

✅ Final Tips

  • Keep a delay between posts to avoid API rate limits
  • Track `sent_status` in your DB after successful post
  • Use try/except for handling errors gracefully

✅ Live Example

Visit: quran4ever2026.wordpress.com to see posts made by this script.

Follow us for more automation scripts and Qur’an learning resources!

Leave a Reply

Your email address will not be published. Required fields are marked *