Python Forum
wordpress-python-xmlrpc. I can import 1 file. How do I import the entire folder?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
wordpress-python-xmlrpc. I can import 1 file. How do I import the entire folder?
#1
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))
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Puzzling import issue that I have no idea how to solvr starseeker 3 511 Feb-21-2024, 05:07 PM
Last Post: deanhystad
Question How to add Python folder in Windows Registry ? Touktouk 1 268 Feb-20-2024, 01:04 PM
Last Post: DeaD_EyE
  Make entire script run again every 45 mo NDillard 0 320 Jan-23-2024, 09:40 PM
Last Post: NDillard
  Compare folder A and subfolder B and display files that are in folder A but not in su Melcu54 3 548 Jan-05-2024, 05:16 PM
Last Post: Pedroski55
  Different Ways to Import Modules RockBlok 2 528 Dec-11-2023, 04:29 PM
Last Post: deanhystad
  How secure is the use of "secret" import? ejwjohn 12 1,253 Nov-09-2023, 08:31 AM
Last Post: ejwjohn
  is import cointegration_analysis a recognized module mitcht33 1 429 Nov-06-2023, 09:29 PM
Last Post: deanhystad
  problem in import module from other folder akbarza 5 1,409 Sep-01-2023, 07:48 AM
Last Post: Gribouillis
  Reading a file name fron a folder on my desktop Fiona 4 916 Aug-23-2023, 11:11 AM
Last Post: Axel_Erfurt
  can not import anaconda pandas module. PySpark pandas module is imported!! aupres 0 719 Aug-06-2023, 01:09 AM
Last Post: aupres

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020