使用CloudSight API进行图像识别的Python脚本

CloudSight: https://www.cloudsightapi.com/

#!/usr/bin/evn python
# coding=utf8
# author=evi1m0@2015<ff0000team>

import sys
import time
import requests

def _api(url):
    count = 0
    api_url = 'http://api.cloudsightapi.com/image_requests'
    res_url = 'http://api.cloudsightapi.com/image_responses/'
    headers = {
                'Origin': 'http://cloudsightapi.com',
                'HOST': 'api.cloudsightapi.com',
                'Authorization': 'CloudSight amZd_zG32VK-AoSz05JLIA',
              }
    post_data = {
                'image_request[remote_image_url]': url,
                'image_request[locale]': 'zh-CN',
                'image_request[language]': 'zh-CN',
                }
    while count<10:
        try:
            count += 1
            print '[+] Loading...'
            token_req = requests.post(api_url, data=post_data, headers=headers)
            token = token_req.json()['token']
            result = requests.get('%s%s'%(res_url, token), headers=headers)
            status = result.json()['status']
            if status == 'completed':
                print '[+] Pic: %s' % url
                print '[*] Name: %s' % result.json()[u'name']
                break
        except Exception, e:
            print '[-] False: %s' % str(e)
            pass


if __name__ == '__main__':
    try:
        url = sys.argv[1]
        _api(url)
    except Exception, e:
        print 'Usage: cloudsightapi.py http://pic_url.com/test.jpg'
        print 'Error: %s' % str(e)
        pass
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值