ไลบรารีนี้มีชื่อว่า python-wordpress-xmlrpc
- รองรับทั้ง Python 2 และ Python 3
- ใช้ XML-RPC ของ Wordpress ในการเข้าถึงข้อมูล
- License: BSD
- เข้ากันได้กับ WordPress 3.4 ขึ้นไป
ในการติดตั้งสามารถใช้คำสั่ง pip ในการติดตั้งได้ดังนี้
pip install python-wordpress-xmlrpc
หรือจะใช้ easy_install ในการติดตั้งด้วยคำสั่ง
easy_install python-wordpress-xmlrpc
ตัวอย่างการใช้งานเบื้องต้น
[python]
>>> from wordpress_xmlrpc import Client, WordPressPost
>>> from wordpress_xmlrpc.methods.posts import GetPosts, NewPost
>>> from wordpress_xmlrpc.methods.users import GetUserInfo
>>> wp = Client('http://mysite.wordpress.com/xmlrpc.php', 'username', 'password')
>>> wp.call(GetPosts())
[<WordPressPost: hello-world (id=1)>]
>>> wp.call(GetUserInfo())
<WordPressUser: max>
>>> post = WordPressPost()
>>> post.title = 'My new title'
>>> post.content = 'This is the body of my new post.'
>>> post.terms_names = {
>>> 'post_tag': ['test', 'firstpost'],
>>> 'category': ['Introductions', 'Tests']
>>> }
>>> wp.call(NewPost(post))
5
[/python]
อ่านเอกสารการใช้งานได้ที่ http://python-wordpress-xmlrpc.readthedocs.org/en/latest/index.html
ติดตามบทความต่อไปนะครับ
ขอบคุณครับ
0 ความคิดเห็น:
แสดงความคิดเห็น
แสดงความคิดเห็นได้ครับ :)