Last active
August 28, 2015 14:19
-
-
Save solanoize/c42386c168b65329e3fc 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
| """ | |
| Quick Start - Create Content Post. | |
| check out -- https://python-wordpress-xmlrpc.readthedocs.org/en/latest/overview.html#quick-start | |
| """ | |
| from wordpress_xmlrpc import Client | |
| from wordpress_xmlrpc import WordPressPost | |
| from wordpress_xmlrpc.methods.posts import GetPosts | |
| from wordpress_xmlrpc.methods.posts import NewPost | |
| from wordpress_xmlrpc.methods.users import GetUserInfo | |
| def posting(site_url, site_user, site_pass): | |
| """Quick Start, posting content in wordpress. | |
| Keyword arguments: | |
| site_url -- the url wordpress | |
| site_user -- the username wordpress | |
| site_pass -- the password wordpress | |
| """ | |
| # Creating object client wp | |
| wp = Client(site_url, site_user, site_pass) | |
| # get all object post, isntance of WordPressPost | |
| # wp_list_post result : | |
| # [ <WordPressPost: b'Title1'>, <WordPressPost: b'Title2'> ] | |
| wp_list_post = wp.call(GetPosts()) | |
| # add post content in wordpress | |
| post = WordPressPost() | |
| post.title = "Title Example 2" # set title | |
| post.content = "This is the body of my new post Title Example 2." | |
| post.terms_names = { | |
| 'post_tag': ['python', 'xmlrpc', 'coding', 'test'], | |
| # Note: category values must be defined in wordpress blog. | |
| # if category item in list not available in wordpress, | |
| # it couse category worth uncategoriez. | |
| 'category': ['coding', 'cinta', 'cerita'] | |
| } | |
| post.post_status = 'publish' | |
| wp.call(NewPost(post)) | |
| if __name__ == '__main__': | |
| site_url = "https://xxx.wordpress.com/xmlrpc.php" | |
| site_user = "xxx" | |
| site_pass = "xxx" | |
| posting(site_url, site_user, site_pass) | |
| """ QUICK DOCUMENTATION | |
| Help on module test_wpython1: | |
| NAME | |
| test_wpython1 | |
| DESCRIPTION | |
| Quick Start - Create Content Post. | |
| check out -- https://python-wordpress-xmlrpc.readthedocs.org/en/latest/overview.html#quick-start | |
| FUNCTIONS | |
| posting(site_url, site_user, site_pass) | |
| Quick Start, posting content in wordpress. | |
| Keyword arguments: | |
| site_url -- the url wordpress | |
| site_user -- the username wordpress | |
| site_pass -- the password wordpress | |
| FILE | |
| d:\workspaces\app_python\wppython\test_wpython1.py | |
| [Finished in 0.4s] | |
| """ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment