- https://modstart.com/m/BlogAdminApi))
[ModStar]
# token
ModStar_token =
# 分类ID
categoryId = 6
# TAG标签
tag = 服务器知识
# 发布状态 true false
isPublished = true
# 是否置顶 true false
isTop = false
# 封面图片 可以使API接口,也可以是单图
img =">ModStar API
# API插件:博客对接API (https://modstart.com/m/BlogAdminApi))
[ModStar]
# token
ModStar_token =
# 分类ID
categoryId = 6
# TAG标签
tag = 服务器知识
# 发布状态 true false
isPublished = true
# 是否置顶 true false
isTop = false
# 封面图片 可以使API接口,也可以是单图
img = - ModStar API博文对接参数
config = configparser.ConfigParser()
config.read(‘config/config.ini’, encoding=”utf-8”) # 读取配置文件 - 获取配置信息
try:
# 公共信息获取
proxy_info = config.get(‘proxy’, ‘proxy’)
isopen_proxy = config.get(‘proxy’, ‘isopen_proxy’)
website = config.get(‘website’, ‘website’)
# 模块信息获取
ModStar_token = config.get(‘ModStar’, ‘ModStar_token’)
categoryId = config.get(‘ModStar’, ‘categoryId’)
tag = config.get(‘ModStar’, ‘tag’)
img = config.get(‘ModStar’, ‘img’)
isPublished = config.get(‘ModStar’, ‘isPublished’)
isTop = config.get(‘ModStar’, ‘isTop’)
except Exception as e:
print(‘ini信息错误:%s’%(e)) - 检测代理开关
首先AiPie的插件模块是在这个文件夹的:
我们今天给大家讲解一下插件的运作原理,AiPie主程序的调用方式,首先配置信息我们是写在/config/config.ini的目录
1.配置ini插件信息的语法:
我们首先以ModStar的博客API插件来为大家讲解,配置文件如下:
:::info
ModStar API
# API插件:博客对接API (https://modstart.com/m/BlogAdminApi))
[ModStar]
# token
ModStar_token =
# 分类ID
categoryId = 6
# TAG标签
tag = 服务器知识
# 发布状态 true false
isPublished = true
# 是否置顶 true false
isTop = false
# 封面图片 可以使API接口,也可以是单图
img =
:::
语法为:
:::danger
[模块]
参数1=值1
参数2=值2
:::
调用模式: :::warning import configparser
ModStar API博文对接参数
config = configparser.ConfigParser()
config.read(‘config/config.ini’, encoding=”utf-8”) # 读取配置文件
获取配置信息
try:
# 公共信息获取
proxy_info = config.get(‘proxy’, ‘proxy’)
isopen_proxy = config.get(‘proxy’, ‘isopen_proxy’)
website = config.get(‘website’, ‘website’)
# 模块信息获取
ModStar_token = config.get(‘ModStar’, ‘ModStar_token’)
categoryId = config.get(‘ModStar’, ‘categoryId’)
tag = config.get(‘ModStar’, ‘tag’)
img = config.get(‘ModStar’, ‘img’)
isPublished = config.get(‘ModStar’, ‘isPublished’)
isTop = config.get(‘ModStar’, ‘isTop’)
except Exception as e:
print(‘ini信息错误:%s’%(e))
::: 主要看try函数中的ModStar的参数获取,一一对应了配置中的参数和值,这方便我们在编写插件时,调用指定信息
2.数据返回接口
AiPie在接收到OPENAI返回的数据时,仅仅会返回两个参数到插件,一个是title一个是msg
title 对应的就是文章标题
msg 为文章的返回内容
3.构造请求函数
我们打开ModStar的插件 /moudle/modstar.py 后,我们会发现插件可以配置我们的代理信息:
检测代理开关
if isopen_proxy == str(1):
# 获取代理信息try:proxies = {"http": "http://127.0.0.1:"+str(proxy_info),"https": "http://127.0.0.1:"+str(proxy_info)}except:print("请检查config/config.ini中的代理端口信息!")input('please input any key to exit')sys.exit(1)else: pass
同时也可以构造函数,构造post请求,向目标发送内容:
def post_msg(title, today, msg): url = website + ‘/api/blog_admin_api/blog/add’
# Here we construct data in dictionary formatdata = {# API Key"ADMIN_API_KEY": ModStar_token,# Category ID"categoryId": int(categoryId),# Title"title": str(title),# TAG"tag": tag,# Summary"summary": str(title),# Image"images": img,# Content"content": msg,# Whether it is published"isPublished": str(isPublished),# Publication Time"postTime": today,# Click Count"clickCount": random.randint(12, 5000),# SEO Keywords"seoKeywords": "",# SEO Description"seoDescription": "",# Whether it is on top"isTop": str(isTop)}print(data)# Use requests.post to send requests like GET requests; r is the response objecttry:if isopen_proxy == str(1):r = requests.post(url, json=data, proxies=proxies)else:r = requests.post(url, json=data)except Exception as e:print('ModStar插件错误:%s'%(e))# Check the response resultprint(r.json())
甚至在这里你可以自定义更多参数,或者改变对应的逻辑,均可!
4.申请上架或者并入AiPie能力的步骤
开发文档是不是超级简单?
关于提交上架或者优化插件,可联系QQ741500926进行审核,并对接到AiPie中,如果想要更多的接口能力也请联系开发即可!
