git-svn-id: http://wordpress-library.googlecode.com/svn/trunk@3 c225be49-b319-0410...
[pyWpLib.git] / example.py
blob1931adc1d8b861f29ffe618680121a8fda6d229a
1 #!/usr/bin/env python
3 """
4 Small example script that publish post with JPEG image
5 """
7 # import library
8 import wordpresslib
10 print 'Example of posting.'
11 print
13 wordpress = raw_input('Wordpress URL:')
14 user = raw_input('Username:')
15 password = raw_input('Password:')
17 # prepare client object
18 wp = wordpresslib.WordPressClient(wordpress, user, password)
20 # select blog id
21 wp.selectBlog(0)
23 # upload image for post
24 imageSrc = wp.newMediaObject('python.jpg')
26 if imageSrc:
27 # create post object
28 post = wordpresslib.WordPressPost()
29 post.title = 'Test post'
30 post.description = '''
31 Python is the best programming language in the earth !
33 <img src="%s" />
35 ''' % imageSrc
36 post.categories = (wp.getCategoryIdFromName('Python'),)
38 # pubblish post
39 idNewPost = wp.newPost(post, True)
41 print
42 print 'posting successfull!'