利用python-wordpress-xmlrpc远程发布WordPress文章缩略图,可以通过采集后的数据批量发布WordPress文章,对于采集站很实用。
from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.compat import xmlrpc_client
from wordpress_xmlrpc.methods import media, posts
client = Client(...)
# set to the path to your file
filename = '/path/to/my/picture.jpg'
# prepare metadata
data = {
'name': 'picture.jpg',
'type': 'image/jpeg', # mimetype
}
# read the binary file and let the XMLRPC library encode it into base64
with open(filename, 'rb') as img:
data['bits'] = xmlrpc_client.Binary(img.read())
response = client.call(media.UploadFile(data))
# response == {
# 'id': 6,
# 'file': 'picture.jpg'
# 'url': 'http://www.example.com/wp-content/uploads/2012/04/16/picture.jpg',
# 'type': 'image/jpeg',
# }
attachment_id = response['id']
上传图片文件后,可以将此图片设置为文章缩略图:
post = WordPressPost() post.title = 'Picture of the Day' post.content = 'What a lovely picture today!' post.post_status = 'publish' post.thumbnail = attachment_id post.id = client.call(posts.NewPost(post))
© 版权声明
THE END


![Toroflix v1.82 – 电影在线播放下载WordPress主题汉化修复版[只能导入TMDB电影]-四颗橙子](https://www.4korange.com/wp-content/uploads/2020/08/1600011471-75d750950a0ab43-500x246.jpg)


![ToroFilm v2.5.9 – 电影剧集在线播放下载WordPress主题模板[汉化修复版]-四颗橙子](https://www.4korange.com/wp-content/uploads/2022/01/QQ浏览器截图20220104230010-500x250.jpg)
![MIBT V1.29 – 电影在线BT下载WordPress主题[已修复主题设置无法保存]-四颗橙子](https://www.4korange.com/wp-content/uploads/2021/12/QQ浏览器截图20211225165905-500x249.png)





学习了
暂无评论内容