Create and post content without human intervention
Say you had a blog on any topic and wanted AI (OpenAi, xAi) to automatically write or translate existing content for you and post it directly to your WordPress website.
- Add user to WordPress with Application Password
After adding a new User (or use an existing one) set an application password in WordPress (Users -> Edit User)
# RSS_AI_Wordpress
import requests
import json
import base64
from _AI_Writer import get_news_response
response = get_news_response("What are the main headlines today?")
# WordPress API endpoint
url = "https://YOURWEBSITE.com/wp-json/wp/v2/posts"
# Authentication credentials
user = "BOT"
password = "YOUR_APPLICATION_PASSWORT_MATE"
credentials = user + ':' + password
token = base64.b64encode(credentials.encode())
header = {
'Authorization': 'Basic ' + token.decode('utf-8'),
'Content-Type': 'application/json; charset=utf-8',
'Accept': 'application/json, */*',
'User-Agent': 'Python/RequestsClient'
}
# Post content to WordPress
post = {
'title': 'AI BOT - Daily News',
'content': response,
'status': 'publish',
}
# Send POST request with verify=False to debug SSL issues
response = requests.post(url, headers=header, json=post, verify=True)
# Check if the request was successful
if response.status_code == 201: # 201 is the success code for creation
print("Post created successfully!")
#print(response.json())
else:
print(f"Error: {response.status_code}")
print(response.text)
This code posts automatically to your WordPress blog. The actual content (stored in “response”) we retrieve from a module called _AI_Writer.
2. Writing Content with Your AI Writer Bot
Our AI writer module fetches an RSS Feed (Google News in our case; bur could be any website or feed) and writes a short blog post in his own words on today’s news. This gets posted directly to our blog (see code above).
# _AI_Writer.py
import os
from openai import OpenAI
import feedparser
XAI_API_KEY = "YOUR_XAI_KEY_HERE"
client = OpenAI(
api_key=XAI_API_KEY,
base_url="https://api.x.ai/v1",
)
def chat_with_gpt(prompt):
response = client.chat.completions.create(
model = "grok-beta",
messages=[{"role": "user", "content": prompt}],
#temperature = 0.8,
)
return response.choices[0].message.content.strip()
def get_rss_feed(url):
"""Fetch and parse RSS feed from given URL"""
feed = feedparser.parse(url)
return feed
def get_feed_entries(feed, limit=10):
"""Extract entries from feed, with optional limit"""
entries = []
for entry in feed.entries[:limit]:
entries.append({
'title': entry.get('title', ''),
'link': entry.get('link', ''),
'published': entry.get('published', ''),
'summary': entry.get('summary', '')
})
return entries
def get_news_response(user_input):
"""Get AI response based on RSS feed news and user input"""
rss_url = "https://news.google.com/news/rss"
feed = get_rss_feed(rss_url)
entries = get_feed_entries(feed)
prompt = f"""Here are the latest news entries. {user_input}
{[entry['title'] + ': ' + entry['summary'] for entry in entries]}"""
return chat_with_gpt(prompt)
# Modified main block for testing
if __name__ == "__main__":
# Test the module
response = get_news_response("Please provide a brief summary")
print("Test response:", response)
Like all AI workflows this offers a plethora of use cases
You could have it fill a website with articles without ever touching said website. Or maybe translate content of one website and repost content on another.
Or maybe – if you are evil – scale this x 1000 and fill hundreds of websites with your propaganda. Unfortunately this is all too easy.