1 Star 1 Fork 0

KongLi/Keyword_get_article

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
post_img.py 1.36 KB
一键复制 编辑 原始数据 按行查看 历史
KongLi 提交于 2021-08-01 23:47 . Initial commit
import os
from wordpress_xmlrpc import Client
from wordpress_xmlrpc.compat import xmlrpc_client
from wordpress_xmlrpc.methods import media
#pip install python-wordpress-xmlrpc
def post_image(domain,loginuser,loginpass,picpath,picfilename):
'''
wordpress 自动上传图片
:param domain: 域名
:param loginuser: 用户名
:param loginpass: 密码
:param picpath: 图片路径
:param picfilename: 图片名字
:return: 返回图片url
'''
wp = Client(f'http://{domain}/xmlrpc.php', loginuser, loginpass)
filename = f'{picpath}' # 上传的图片文件路径
# prepare metadata
data = {
'name': f'{picfilename}.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 = wp.call(media.UploadFile(data))
print(response)
return response.get('link')
if __name__ == '__main__':
# domain = 'www.wpauto.io'
# loginuser = 'admin'
# loginpass = 'admin'
# filepath = 'default.jpg'
# filename = '这是图片的标题'
# imgurl = post_image(domain=domain,loginuser=loginuser,loginpass=loginpass,picpath=filepath,picfilename=filename)
# print(imgurl)
path = os.path.split(os.path.realpath(__file__))[0]
print(path)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/annals-code/Keyword_get_article.git
[email protected]:annals-code/Keyword_get_article.git
annals-code
Keyword_get_article
Keyword_get_article
master

搜索帮助