测试了很多地方,Z-U-I主要的是个python-xmlrpc的代码是非常古老,修复了好几个问题,不停的测试才Z-U-I终测试出来

不过现在还有个问题是,xmlclient调用了xmlclient.http这个地方,没有timeout的修改地方,导致这个脚本在运行一段时间还是有点问题

但是相对来说,已经太太节约时间了

用rest-api也可以实现,但是感觉xmlrpc直接简单一些

'''
Author: 20004@163.com
Date: 2022-07-17 15:08:36
LastEditors: error: git config user.name && git config user.email & please set dead value or install git
LastEditTime: 2022-07-21 00:34:03
FilePath: PythonCode华为题库小程序数据h12-821.py
'''
import codecs
import json
import os
import io
from http import client
from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods.posts import GetPosts
from wordpress_xmlrpc.methods import posts
from wordpress_xmlrpc import WordPressTerm
from wordpress_xmlrpc.methods import taxonomies


File_name='h12-821.json'
file=open('./'+File_name,encoding="utf-8")
data=json.loads(file.read())
print(len(data))
################################
for i in range (1105,len(data)):
################################
    tiku_bianhao=str(i)
    tiku_wenti=data[i]['question']
    tiku_xuanxiang=''
    xuanxiang=json.loads(data[i]['options'])
    tiku_xuanxiang=''
    for j in range(0,len(xuanxiang)):

        #print(xuanxiang[j]['Key'] + xuanxiang[j]['Value'])
        tiku_xuanxiang=tiku_xuanxiang+ ((xuanxiang[j]['Key'] + xuanxiang[j]['Value']))+'n'

    tiku_daan=data[i]['answer']
    title= 'H12-821-v1-' + tiku_bianhao+'-' + tiku_wenti.split('<')[0]
    content=tiku_wenti + 'n'+ tiku_xuanxiang+'n参考答案:'+tiku_daan
    wp = Client('https://www.xacisco.net/blog/xmlrpc.php', 'xxx', 'xxx')
    widget = WordPressPost()
    widget.post_type = 'docs'
    widget.title = title
    widget.content = content
    widget.post_status = 'publish'
    doc_category = wp.call(taxonomies.GetTerm('doc_category', 883))
    widget.terms.append(doc_category)
    kb_category = wp.call(taxonomies.GetTerm('knowledge_base', 872))
    widget.terms.append(kb_category)
    print (title)
    widget.id = wp.call(posts.NewPost(widget))