×
  • Shared Hosting

    Fast reliable and affordable cPanel Web Hosting from $2.99 per month.

  • Reseller Hosting

    Multiple websites? No problem with our multi-site hosting package. From $5.99 per month.

  • Annual Hosting

    Save money on web hosting by paying annually. Starting at $29.99 per year.

  • VPS Servers

    Need more power and resources? Choose our VPS server, only $7.99 per month.

  • FREE HOSTING PLAN

    Ideal for students and unemployed.

    Register

Xenforo API – Bulk Post Threads (Python)

21/11/2022 | |0 comment

This is for fans of programmatic SEO. Below is a Python script to bulk upload new threads to the Xenforo forum script. The script works by reading a CSV file that is stored in a dataframe and then posted to Xenforo using the tqdm library.

Xenforo has an excellent Rest API with endpoints that are perfect for programmatic SEO.

# Import modules
import pandas as pd
import requests
import csv
import json
import base64
from tqdm.notebook import tqdm

# send the API via header requests
headers = {
'Content-type' : 'application/x-www-form-urlencoded',
'XF-Api-User': '1',
'XF-Api-Key' : 'api-key-goes-here'
}

# Connect with the API Endpoint
url = 'https://example.com/api/threads/'

# Paste your uploaded csv file name here - example: sample-data.csv or paste remote weblink
df = pd.read_csv("https://airwolf.dev/xen/xenforo-test2.csv")
df

# Xenforo_Post_Insert Function to build the JSON array

# (add or remove post schemas to suit your requirements)
def xenforo_post_insert(title, content):
data = {'node_id': '23',
'title': title,
'message': content
}
xenforo_post_insert = requests.post(url, headers=headers, data=data)

# Executes the script and runs the TQDM progress bar
for index, row in tqdm(df.iterrows()):
# Add or remove Xenforo schemas varibles below
xenforo_post_insert(row["title"], row["content"])

 

Chris

Freelance Technical SEO with - https://sitebee.co.uk