Skip to content

Instantly share code, notes, and snippets.

@n8henrie
Forked from sgerin/Post to WordPress
Last active December 21, 2015 20:09
Show Gist options
  • Save n8henrie/6359001 to your computer and use it in GitHub Desktop.
Save n8henrie/6359001 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python3
import datetime
import sys
try:
import xmlrpc.client as xmlrpclib
except:
import xmlrpclib
wp_url = "http://n8henrie.com/xmlrpc.php"
wp_username = 'n8henrie'
if sys.platform == 'unknown':
import keychain
import clipboard
wp_password = keychain.get_password('wordpress', wp_username)
elif sys.platform == 'darwin' or sys.platform == 'linux2':
import keyring
wp_password = keyring.get_password('http://n8henrie.com', wp_username)
else:
raise Exception('Not sure what platform we\'re on here.')
wp_blogid = ""
status_draft = 1
status_published = 0
server = xmlrpclib.ServerProxy(wp_url)
# title = raw_input("Post title: ")
# content = clipboard.get()
title = 'fake title'
content = 'fake content'
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 = 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 = 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