Jul-05-2018, 06:21 AM
Im learning xmlrpc. I am able to import 1 image at a time. How do I import all images in a folder into a post?
from wordpress_xmlrpc import Client, WordPressPost from wordpress_xmlrpc.compat import xmlrpc_client from wordpress_xmlrpc.methods import media, posts from wordpress_xmlrpc import Client, WordPressPost from wordpress_xmlrpc.methods.taxonomies import * from wordpress_xmlrpc.methods.posts import * from wordpress_xmlrpc.methods.users import * from wordpress_xmlrpc.methods import * wp_url = "http://192.168.0.105:80/wordpress/xmlrpc.php" wp_username = 'admin' wp_password = '#####' wp = Client(wp_url, wp_username, wp_password) filename = 'picture2.jpg' data = { 'name': 'picture2.jpg', 'type': 'image/jpeg', # mimetype } with open(filename, 'rb') as img: data ['bits'] = xmlrpc_client.Binary(img.read()) response = wp.call(media.UploadFile(data)) response == { 'id': 7, 'file': 'picture2.jpg', 'url': 'http://192.168.0.105/wordpress/wp-content/uploads/2018/07/04/picture2.jpg', 'type': 'image/jpeg', } attachment_id = response['id'] post = WordPressPost() post.title = 'Pictures' post.content = 'What a lovely picture today!' post.post_status = 'publish' post.thumbnail = attachment_id post.id = wp.call(posts.NewPost(post))