Skip to content

Instantly share code, notes, and snippets.

@dersteppenwolf
Created August 18, 2012 15:45
Show Gist options
  • Save dersteppenwolf/3387824 to your computer and use it in GitHub Desktop.
Save dersteppenwolf/3387824 to your computer and use it in GitHub Desktop.
Publicar información en Wordpress utilizando python
#!/usr/bin/python
# -*- coding: latin-1 -*-
#basado en el script originalmente publicado en
#http://www.jansipke.nl/using-python-to-add-new-posts-in-wordpress/
import datetime, xmlrpclib
from xml.sax.saxutils import escape
wp_url = "http://server.com/wordpress/xmlrpc.php"
wp_username = "usuario"
wp_password = "clave"
wp_blogid = ""
status_draft = 0
status_published = 1
server = xmlrpclib.ServerProxy(wp_url)
now = datetime.datetime.now()
title = escape("Publicar Datos en Wordpress con Python")
content = "Contenido de Ejemplo "+now.strftime("%Y-%m-%d %H:%M:%S")+"\n "
date_created = xmlrpclib.DateTime(datetime.datetime.now())
categories = ["somecategory"]
tags = [ "python", "xmlRpc"]
data = {'title': title, 'description': content, 'dateCreated': date_created, 'categories': categories, 'mt_keywords': tags}
post_id = server.metaWeblog.newPost(wp_blogid, wp_username, wp_password, data, status_published)
print post_id
#La publicación de comentarios no funciona a través de server.metaWeblog
#data = {'content': 'un comentario', 'post_id': post_id, 'author': 'test'}
#comment_id = server.metaWeblog.newComment(wp_blogid, wp_username, wp_password, data, status_published)
#print comment_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment