Created
July 25, 2013 12:15
-
-
Save sgerin/6079085 to your computer and use it in GitHub Desktop.
Post to WordPress from Python.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import xmlrpclib | |
import keychain | |
import clipboard | |
wp_url = "http://www.yoursite.com/xmlrpc.php" | |
wp_username = 'username' | |
wp_password = keychain.get_password('wordpress', wp_username) | |
wp_blogid = "" | |
status_draft = 0 | |
status_published = 1 | |
server = xmlrpclib.ServerProxy(wp_url) | |
title = raw_input("Post title: ") | |
content = clipboard.get() | |
cat = server.wp.getTerms(wp_blogid, wp_username, wp_password, 'category') | |
i = 0 | |
for x in cat: | |
print str(i) + "- " + x['name'] | |
i = i+1 | |
cat_nb = raw_input("Which category do you want to use (input number between 0 and " + str(len(cat)-1) + "): ") | |
tag = server.wp.getTerms(wp_blogid, wp_username, wp_password, 'post_tag') | |
i = 0 | |
for x in tag: | |
print str(i) + "- " + x['name'] | |
i = i+1 | |
line = raw_input("Which tags do you want to use (input number between 0 and " + str(len(tag)-1) + ", separated by a comma): ") | |
tags_nb = line.split(',') | |
tags = [] | |
for x in tags_nb: | |
tags.append(tag[int(x)]['name']) | |
categories = [cat[int(cat_nb)]['name']] | |
data = {'title': title, 'description': content, 'post_type': 'post', 'categories': categories, 'mt_keywords': tags} | |
post_id = server.metaWeblog.newPost(wp_blogid, wp_username, wp_password, data, status_published) | |
post_infos = server.metaWeblog.getPost(post_id, wp_username, wp_password) | |
print post_infos['link'] | |
clipboard.set(post_infos['link']) | |
''' | |
available fields | |
int blog_id | |
string username | |
string password | |
struct content | |
string post_type | |
string post_status | |
string post_title | |
int post_author | |
string post_excerpt | |
string post_content | |
datetime post_date_gmt | post_date | |
string post_format | |
string post_name | |
string post_password | |
string comment_status | |
string ping_status | |
bool sticky | |
int post_thumbnail | |
int post_parent | |
array custom_fields | |
struct | |
string key | |
string value | |
struct terms: Taxonomy names as keys, array of term IDs as values. | |
struct terms_names: Taxonomy names as keys, array of term names as values. | |
struct enclosure | |
string url | |
int length | |
string type | |
any other fields supported by wp_insert_post | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you have time to help me modify this for use in Editorial app. I got here via @viticci. I'm trying to use his Editorial workflow to post to WP on my self-hosted site.
Thanks in advance.