运行效果:
代码:
''' 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-18 02:10:01 FilePath: PythonCode华为题库小程序数据读取json发送网站.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-831.json' file=open('./'+File_name,encoding="utf-8") data=json.loads(file.read()) print(len(data)) for i in range (0,len(data)): tiku_bianhao=str(i) tiku_wenti=data[i]['question'] tiku_xuanxiang='' xuanxiang=json.loads(data[i]['options']) tiku_xuanxiang='' for i in range(0,len(xuanxiang)): #print(xuanxiang[i]['Key'] + xuanxiang[i]['Value']) tiku_xuanxiang=tiku_xuanxiang+ ((xuanxiang[i]['Key'] + xuanxiang[i]['Value']))+'n' tiku_daan=data[i]['answer'] title= 'H12-831-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', 877)) 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)) print ('写入完成,继续干活,他奶奶的')