GPT-4官方插件收集到Excel中

发布时间 2023-07-18 11:46:45作者: jeyeshield

1、下载json文件,格式如下。https://github.com/copilot-us/chatgpt-plugins/tree/cefe4e2a917fa07c6f1651fff2e32c45ef98a7a7

2、这里为了方便用户查看,调用百度翻译把描述翻译成中文(若不用可注释掉),需要申请百度翻译开放平台开发者,我这里申请为高级版。申请流程:http://api.fanyi.baidu.com/doc/12

3、按照使用文档编写url。百度翻译通用文本翻译使用文档:http://api.fanyi.baidu.com/doc/21

4、把需要的内容写入Excel里。

import json
import requests
import random
import hashlib
import urllib
from openpyxl import Workbook


def baiduTranslate(translate_text):
    """
    百度翻译接口
    :param translate_text: 需要翻译的文本-英
    :return: 翻译后文本-中
    """
    appid = "xxx"
    secretKey = xxx"
    myurl = 'http://api.fanyi.baidu.com/api/trans/vip/translate'
    fromLang = 'en'  # 原文语种
    toLang = 'zh'  # 译文语种
    salt = random.randint(3276, 65536)

    sign = appid + translate_text + str(salt) + secretKey
    sign = hashlib.md5(sign.encode()).hexdigest()
    url = myurl + '?q=' + urllib.parse.quote(translate_text) + '&from=' + fromLang + \
            '&to=' + toLang + '&appid=' + appid + '&salt=' + str(salt) + '&sign=' + sign
    try:
        response = requests.get(url)
        result = response.json()
        return result['trans_result'][0]['dst']
    except Exception as e:
        print(e)


with open("./chatgpt_plugins.json", "r", encoding="utf-8") as f:
    contents = f.read()
    text_dict = json.loads(contents)

items = text_dict["items"]

wb = Workbook()
ws4 = wb.create_sheet(title="plugins", index=0)
sheet = wb.active
sheet["a1"] = "插件名"
sheet["b1"] = "描述"

c = 1
for i in items:
    name = i["namespace"]
    manifest = i["manifest"]
    description = manifest["description_for_human"]
    # trans_des = baiduTranslate(description)
    sheet.cell(row=c, column=1).value = name
    sheet.cell(row=c, column=2).value = description
    c += 1

wb.save("plugins.xlsx")