def to_mp3(string, name):
    url = 'https://aiapi.jd.com/jdai/tts_vip'
    skey = 'ae90bdffed42ed109865ca2f16a0b8c2'
    bodyStr = string.encode('utf-8')
    params = {
        'Service-Type': 'synthesis',
        'Request-Id': '2c4dc6e2-e1c5-11e8-a867-040973d59110',
        'Sequence-Id': '-1',
        'Protocol': '1',
        'Net-State': '2',
        'Applicator': '1',
        'Property':
        '{"platform":"Linux","version":"0.0.0.1","parameters":{"aue":"3","vol":"1.0","sr":"24000","sp":"0.8","tim":"0","tte":"1"}}',
        'appkey': 'e408b88d69dcd1039d9a02b7d4a3500b',
        'secretkey': skey,
        'sign': wx_sdk.sign(skey)
    }
    print('接口调用中……')
    response = wx_sdk.wx_post_req(url, params, bodyStr=bodyStr)
    rep = response.json()
    print(rep)
    mp = rep['result']['audio']
    code = rep['code']
    remain = rep['remain']
    msg = rep['msg']
    print('返回状态码是:{}\n调用次数还剩:{}次\n{}'.format(code, remain, msg))
    mp = base64.b64decode(mp)
    print('开始写入……')
    with open(r'{}.mp3'.format(name), 'wb') as mpwrite:
        mpwrite.write(mp)
        print('{}\n mp3文件【写入成功!】'.format(name))
Exemplo n.º 2
0
def download_jd_proxies():
    import wx_sdk
    url = 'https://way.jd.com/jisuapi/proxy'
    params = {
        'num': '5',
        'area': '',
        'areaex': '',
        'port': '8080,5000',
        'portex': '3306',
        'protocol': '1',
        'type': '1',
        'appkey': '73c7fe53401ea0f9a94871455e805a7b'
    }

    resp = wx_sdk.wx_post_req(url, params)
    print(resp.content.decode())

    content = resp.json().get('result').get('result').get('list')
    proxies_list = []
    for proxy in content:
        ip = proxy['ip']
        proxies = {
            'http': 'http://%s' % ip,
            'https': 'http://%s' % ip,
        }
        proxies_list.append(proxies)
    print('proxies_list: ', proxies_list)
    return proxies_list
Exemplo n.º 3
0
def to_mp3(string, name):
    """
    将传入的string字符串处理成mp3音频文件
    @param string: 要转换的文字
    @param name: 要保存的mp3的名称
    @return: 无返回
    """
    try:
        url = 'https://aiapi.jd.com/jdai/tts_vip'
        skey = 'ae90bdffed42ed109865ca2f16a0b8c2'  # 这个secretkey京东的控制台可以查看到
        print('输入的文字内容为:\n{}\n{}'.format(string, '*' * 50))
        bodyStr = string.encode('utf-8')  # 传入接口处理的文字,需要先编码成utf-8字节码
        params = {
            'Service-Type': 'synthesis',
            'Request-Id': '2c4dc6e2-e1c5-11e8-a867-040973d59110',
            'Sequence-Id': '-1',
            'Protocol': '1',
            'Net-State': '2',
            'Applicator': '1',
            'Property':
            '{"platform":"Linux","version":"0.0.0.1","parameters":{"aue":"3","vol":"1.0","sr":"24000","sp":"0.9","tim":"0","tte":"1"}}',
            'appkey': 'e408b88d69dcd1039d9a02b7d4a3500b',
            'secretkey': skey,
            'sign': wx_sdk.sign(skey)  # 这是SDK自带的方法,用于生成sign值的。
        }
        print('接口调用中……')
        response = wx_sdk.wx_post_req(url, params,
                                      bodyStr=bodyStr)  # 这个是SDK写的方式,直接调用。
        rep = response.json()  # 通过json格式解析一下返回体,更好的进行后续处理。
        code = rep['code']
        remain = rep['remain']
        msg = rep['msg']
        print('返回状态码是:{}\n调用次数还剩:{}次\n{}'.format(code, remain, msg))
        # print(rep)
        mp = rep['result']['audio']  # 因为json解析后就是一个字典,其中audio是嵌套字典,所以取值有两层。
        mp = base64.b64decode(
            mp
        )  # 查看京东接口文档,发现音频是base64编码方式,这里要用到base64库中的b64decode方法,直接传字符串即可解码。
        print('MP3文件开始写入……')
        # 下面先判断文件夹是否存在,不存在就创建一个,os模块中os.path.exists()判断
        if not os.path.exists(r'..\mp3'):  #
            os.mkdir(r'..\mp3')
        # 使用相对路径来处理,便于程序的移植
        with open(r'..\mp3\{}.mp3'.format(name), 'wb') as mpwrite:
            mpwrite.write(mp)
            print('{}\n mp3文件【写入成功!】'.format(name))
    except Exception as error:
        print('处理文件《{}》时出错,请查看日志记录'.format(name))
        # 并将错误记录写入日志文件
        # if not os.path.exists(r'..\mp3\log.txt'):
        #     os
        with open(r'..\log.txt', 'a') as w:
            w.write('处理文件{}时出错,请查看日志记录----{}\n报错内容:{}\n'.format(
                name, time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),
                error))
        print(error)
        print('*' * 50)
Exemplo n.º 4
0
def get_additional_data(*data):
    " data: [isbn, inventory]"
    isbn = data[0]
    inventory = data[1]
    url = 'https://way.jd.com/showapi/isbn'
    params = {'isbn': isbn, 'appkey': '8b080ec6aae58e0eecf2f42572303851'}
    response = wx_sdk.wx_post_req(url, params)
    try:
        text = json.loads(response.text)
        info = text["result"]["showapi_res_body"]["data"]
        return [info['isbn'], info['title'], info['price'], inventory]
    except:
        print(response)
        return [isbn, "can't find the title", "no price", inventory]
Exemplo n.º 5
0
def msgproc(request):
    dirname = 'reco_img/'
    if not os.path.exists(dirname):
        os.makedirs(dirname)
    #fo = open(dirname + request.POST[tempFiles][0]+'.png', 'wb+')
    #pic_url[-15:-5]+'.png', 'wb+')
    fo = open(dirname + 'imgreco.png', 'wb+')
    fo.write(request.FILES['image'].read())
    print(request.FILES['image'])
    fo.close()
    #print(request.FILES['image'])
    #print(request.FILES.get('name'))
    # for k, v in request.environ.items():
    #     print(k, v)

    import wx_sdk

    url = 'https://aiapi.jd.com/jdai/ocr_universal'
    #img = 'C:\fakepath\微信图片_20200514220220.jpg'
    img = dirname + "微信图片_20200514220235.jpg"  # 上传图片的位置
    params = {
        'appkey': '8cef5cb0ad11b5055526b2c6b374ee7f',
        'secretkey': '0a6549c60bf1affd1f85737302d3d757'
    }

    response = wx_sdk.wx_post_req(url, params, img=img)
    # type(response.text))
    # #contents=response.text['resultData']

    print(response.text)
    # print(contents)
    contents = []
    #a=response.text["result"].json()
    a = (json.loads(response.text))["result"]
    for x in a["resultData"]:
        if x["text"]:
            contents.append(x["text"])
    #print(contents)
    for i in contents:
        print(i)

    return HttpResponse("成功上传")
Exemplo n.º 6
0
# 加载图片,将图片转换为Base64格式
with open('image.jpg', 'rb') as f:
    img_Base64 = base64.b64encode(f.read())
    img_Base64 = bytes.decode(img_Base64)
f.close()

# 参数赋值
url = 'https://aiapi.jd.com/jdai/garbageImageSearch'
bodyStr = '{    "cityId":"310000",  "imgBase64":"%s"}' % img_Base64
params = {
    'type': 'json',
    'content': 'json string',
    'appkey': '7e9ad0497bd9e353119ac73335cbb2bb',
    'secretkey': 'f8be422d899c7623cf0818a696942e33',
}

true = True
false = False
response = wx_sdk.wx_post_req(url, params, bodyStr=bodyStr)
dic = eval(response.text)
# 将字典中的garbage_info取出
garbage_info = dic.get('result').get('garbage_info')
#
#for i in garbage_info:
#    print(i['confidence'])

# 按垃圾概率从大到小排序
sort = sorted(garbage_info, key=lambda a: a['confidence'], reverse=True)
print(sort[0])
#print(dic)
Exemplo n.º 7
0
#!/usr/bin/python
# -*- coding: utf-8 -*-

import wx_sdk

url = 'http://ai.gw.jdcloud.com/wanxianga17/testai'
params = {
    'type': 'json',
    'content': 'json string',
    'appkey': 'aef164550413cde170bd5e07d0c22d57',
    'secretkey': '77f17703b63d14d115ed26d507f5a7fa',
}

response = wx_sdk.wx_post_req(url, params)
print(response.text)