Created
October 29, 2012 16:18
-
-
Save jplattel/3974585 to your computer and use it in GitHub Desktop.
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
# Imports | |
from wordpress_xmlrpc import Client, WordPressPost | |
from wordpress_xmlrpc.methods.posts import GetPosts, NewPost | |
from wordpress_xmlrpc.methods.users import GetUserInfo | |
import markdown | |
import sys | |
import webbrowser | |
# Converts a markdown file to a post and asks for titles, tags and categories | |
def post(f): | |
# New instance of blogpost | |
post = WordPressPost() | |
# Parse the markdown file for content to HTML, ignoring any unicode errors | |
post.content = markdown.markdown(unicode(f,errors='ignore')) | |
# Edit all necessary things like title, tags and categories | |
post.title = raw_input('Title: ') | |
tags = raw_input('Tags (comma-seperated): ') | |
categories = raw_input('Catagories (comma-seperated): ') | |
post.terms_names = { | |
'post_tag': tags.split(','), | |
'category': categories.split(',') | |
} | |
# Mark for publishing | |
post.post_status = 'publish' | |
return post | |
if __name__ == '__main__': | |
# Initiate blog | |
wp = Client('blogurl' + 'xmlrpc.php', 'username', 'password') | |
# You need to supply the path to the markdown file for blogging | |
if len(sys.argv) == 2: | |
# Opens the file supplied as an argument | |
f = open(str(sys.argv[1]), 'r').read() | |
# Generate a blogpost, returns the entire post for inserting yrough XML RPC | |
p = post(f) | |
# Try to make the blogpost | |
try: | |
n = wp.call(NewPost(p)) | |
print "Post made opening webbrowser:" | |
webbrowser.open('http://www.jplattel.nl/?p=' + str(n)) | |
except: | |
print "Post failed" | |
# If the arguments are incorrect, let the user know. | |
else: | |
print "Please insert a markdown file as a parameter to this script" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment