基于科大讯飞api做文本情感分析详细教程

#!/usr/bin/python
# -*- coding: UTF-8 -*-

import time
import urllib.request
import urllib.parse
import json
import hashlib
import base64
import re


def xinxi(url,x_appid,api_key):
    # 参数检查
    try:
        if len(str(url))!=0:
            return url,x_appid,api_key
    except:
          print("输入错误")


def input_1():
    # 输入判断
    text=input("请输入一句话:")
    if len(text)>0:
        return text
    else:
        print("请重新输入!")

def main(TEXT):
    # 在线解析
    body = urllib.parse.urlencode({'text': TEXT}).encode('utf-8')
    param = {"type": "dependent"}
    x_param = base64.b64encode(json.dumps(param).replace(' ', '').encode('utf-8'))
    x_time = str(int(time.time()))
    x_checksum = hashlib.md5(api_key.encode('utf-8') + str(x_time).encode('utf-8') + x_param).hexdigest()
    x_header = {'X-Appid': x_

你可能感兴趣的:(python实战100例,人工智能,深度学习,python)