pyWordpresXML-Importer #10 Rozmowa z wordpressem

Kolejny research/badania/testy zakonczone sukcesem.
Jedna malutka biblioteka “wordpress_xmlrpc” i publikowanie
postów z pythona staje się dziecinne proste.

import wordpress_xmlrpc as wp_rpc
import wordpress_xmlrpc.methods as wp_methods


class MyWp:
    def __init__(self):
        self.user = None
        self.password = None
        self.url = None
        self.post = wp_rpc.WordPressPost()

    def create_post(self, title, content):
        conn = wp_rpc.Client(self.url, self.user, self.password)
        self.post.title = title
        self.post.content = content
        self.post.post_status = 'publish'
        self.post.id = conn.call(wp_methods.posts.NewPost(self.post))
        return self.post.id


if __name__ == "__main__":
    wp = MyWp()
    wp.user = 'test'
    wp.password = 'test'
    wp.url = "http://wordpress/xmlrpc.php"

    new_title = "Bla bla"
    new_content = "Magic content :)"
    post_id = wp.create_post(new_title, new_content)
    print("Post id:" + post_id)

I nawet działa 🙂
C:\Python3\python.exe C:/Users/CLT/PycharmProjects/pyWordpresXML-Importer/pwx_wp.py
Post id:76984
Process finished with exit code 0

Post utworzony i opublikowany :]

Pełen sukces.
Teraz czas na nagrodę 😛

One thought on “pyWordpresXML-Importer #10 Rozmowa z wordpressem

Leave a Reply

Your email address will not be published. Required fields are marked *