Created
December 17, 2015 17:22
-
-
Save tmiz/b50434911dcea0486644 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
from wordpress_xmlrpc import Client, WordPressPost | |
from wordpress_xmlrpc.methods.posts import NewPost | |
from wordpress_xmlrpc.methods import posts | |
import os.path | |
import sys | |
def read_config(filepath): | |
with open(filepath) as f: | |
lines = f.readlines() | |
return lines[0:3] | |
def read_textfile(filepath): | |
with open(filepath) as f: | |
line = f.readline() | |
title = line | |
description = "" | |
while line: | |
line = f.readline() | |
description += line | |
return title, description | |
if __name__=="__main__": | |
homepath = os.environ["HOME"] | |
if os.path.exists("%s/.wppostrc" % homepath): | |
pass | |
else: | |
sys.stderr.write("Config file(%s/.wppostrc) is not existing.\n" % homepath) | |
exit() | |
url, user, password = read_config("%s/.wppostrc" % homepath) | |
if (len(sys.argv) != 2) and (len(sys.argv) != 3): | |
sys.stderr.write("Usage: %s <TextFile>" % sys.argv[1]) | |
exit() | |
wp = Client(url,user,password) | |
post = WordPressPost() | |
post.title, post.content = read_textfile(sys.argv[1]) | |
id = wp.call(NewPost(post)) | |
if sys.argv[2] == "-o": | |
post.post_status = 'publish' | |
wp.call(posts.EditPost(id, post)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment