Skip to content

Instantly share code, notes, and snippets.

@hjupadhyay
Last active December 20, 2022 11:35
Show Gist options
  • Save hjupadhyay/8286797 to your computer and use it in GitHub Desktop.
Save hjupadhyay/8286797 to your computer and use it in GitHub Desktop.
A csv to wordpress posting adapter written in python
# wpadapter.py inserts posts from a csv file to a wordpress blog
import datetime , xmlrpclib , csv
# STEP 1 create a wp insert function
def insert_wp_post(title="Title was not passed !",content="Content was not passed !"):
wp_url = "http:// <INSERT YOUR WORDPRESS URL HERE >/xmlrpc.php"
wp_username = "wordpress username"
wp_password = "wordpress password"
wp_blogid = ""
postype=""
status_draft = 0
status_published = 1
server = xmlrpclib.ServerProxy(wp_url)
date_created = xmlrpclib.DateTime(datetime.datetime.strptime("2012-10-10 21:08", "%Y-%m-%d %H:%M"))
categories = ["unsorted"]
tags = ["sometag", "othertag"]
data = {'post_type':postype ,'title': title, 'description': content,'dateCreated': date_created, 'categories': categories, 'mt_keywords': tags}
post_id =server.wp.newPost(wp_blogid,wp_username,wp_password,data,status_published)
# STEP 2 open csv file and row by row call insert function
reader=csv.reader(open("test.csv","rb"))
for row in reader:
insert_wp_post(row[1],row[2])
@yabenz
Copy link

yabenz commented Dec 20, 2022

Can you please share with me how the csv looks like, the template, with the title, and several H2,H3... headings and also other formattings like list and .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment