-
Notifications
You must be signed in to change notification settings - Fork 16
/
wp_post.py
49 lines (41 loc) · 1.59 KB
/
wp_post.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#encoding:utf-8
from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods.posts import GetPosts, NewPost,EditPost
from wordpress_xmlrpc.methods.users import GetUserInfo
from wordpress_xmlrpc.methods import taxonomies
from wordpress_xmlrpc import WordPressPost
import json
def wp_post(client,title,content,tags):
post = WordPressPost()
post.title = title
post.content = content
post.terms = tags
post.id=client.call(NewPost(post))
# whoops, I forgot to publish it!
post.post_status = 'publish'
post.custom_fields = []
result=client.call(EditPost(post.id,post))
return result
def wp_post_custom_field(client,title,content,custom_field):
post = WordPressPost()
post.title = title
post.content = content
post.custom_fields = []
post.custom_fields.append(custom_field)
post.id=client.call(NewPost(post))
# whoops, I forgot to publish it!
#post.post_status = 'publish'
post.post_status = 'private'
post.custom_fields = []
result=client.call(EditPost(post.id,post))
return result
if __name__=='__main__':
domain_name=""
user_name=""
password=""
client = Client(domain_name+"/xmlrpc.php",user_name ,password )
categories = client.call(taxonomies.GetTerms('category', {"search": "Uncategorized"}))
title = 'chat_wordpress'
content = '''have a try https://github.com/fendouai/chat_wordpress'''
result=wp_post(client,title,content,categories)
print(result)