示例#1
0
文件: demo.py 项目: zl1234/TourSite
def search3(query):
    paramssearch['appId'] = appId3
    paramssearch['search_query'] = query
    service = QcloudApi(module, config)
    url = service.generateUrl(action2, paramssearch)
    info = service.call(action2, paramssearch)
    print url
    print info
    re1 = re.compile('"code":(\w+),')
    re2 = re.compile('"result_num":(\w+),')
    re3 = re.compile(
        '"doc_meta":"\{\\\\"id\\\\":\\\\"(.+)\\\\",\\\\"jname\\\\":\\\\"(.+)\\\\",\\\\"jtag\\\\":\\\\"(.+)\\\\"\}'
    )
    if re1.findall(info) != ['0']:
        output = open('errorlog', 'a+')
        output.write("search error:\n")
        output.write(url)
        output.write(info)
        output.write("\n")
        output.close()
        return [{'id': -1, 'jname': 'False', 'jtag': 'False'}]
        #检查是否成功,错误返回信息写入日志
    counter = (int)(re2.findall(info)[0][0])
    port = re3.findall(info)
    pport = {}
    ppport = []
    for i in range(0, counter):
        pport['id'] = (port[i][0].decode('raw_unicode_escape')).encode("utf-8")
        pport['jname'] = (
            port[i][1].decode('raw_unicode_escape')).encode("utf-8")
        pport['jtag'] = (
            port[i][2].decode('raw_unicode_escape')).encode("utf-8")
        ppport.append(pport)
    return ppport
示例#2
0
def getDescribeLVBInfo(action, channel_id=''):
    logging.info('开始查询')
    module = 'live'
    action = action
    config = {
        'Region': 'shanghai',
        'secretId': '你的id',
        'secretKey': '你的key',
        'method': 'post'
    }
    # 获取频道详情需要指定channel_id
    if channel_id == '':
        params = {
            'SignatureMethod':'HmacSHA1',#指定所要用的签名算法,可选HmacSHA256或HmacSHA1,默认为HmacSHA1
        }
    else:
        params = {
            'channelId':'{}'.format(channel_id),
            'SignatureMethod':'HmacSHA1',
        }

    try:
        service = QcloudApi(module, config)
        logging.info(service.generateUrl(action, params))
        rets = service.call(action, params)
        logging.info("请求结果: {}".format(rets))

        return rets
    except Exception, e:
        logging.info(e)
示例#3
0
文件: demo.py 项目: zl1234/TourSite
def delete(doc_id, appId):
    if appId == 1:
        paramsdelete['appId'] = appId1
    elif appId == 2:
        paramsdelete['appId'] = appId2
    elif appId == 3:
        paramsdelete['appId'] = appId3
    else:
        return False
    paramsdelete['contents.0.doc_id'] = doc_id
    service = QcloudApi(module, config)
    url = service.generateUrl(action1, paramsdelete)
    info = service.call(action1, paramsdelete)
    print url
    print info
    re1 = re.compile('"code":(\w+),')
    re2 = re.compile('"errmsg":"(\w+)",')
    if re1.findall(info) != ['0'] or re2.findall(info) != ['succ']:
        output = open('errorlog', 'a+')
        output.write("delete error:\n")
        output.write(url)
        output.write(info)
        output.write("\n")
        output.close()
        return False
    return True
示例#4
0
def getLexicalSynonym(text):
        params = {'text':text}
    # try:
        print len(params['text'].decode('utf-8'))
        print len(text)

        # 生成请求的URL,不发起请求
        service = QcloudApi(module, config)
        print service.generateUrl(action, params)
        # 调用接口,发起请求
        x = service.call(action, params)
        print x
        # print json.loads(x)['syns']
        # print json.loads(x)['syns'][0]['word_ori']
        # print json.loads(x)['syns'][0]['word_syns']
        print

        if None != json.loads(x)['syns']:
            for i in json.loads(x)['syns']:


                ori_text = i['word_ori']['text']
                # idx_beg = i['word_ori']['idx_beg']
                # idx_end = i['word_ori']['idx_end']
                # print idx_beg
                # print idx_end
                print ori_text

                for j in i['word_syns']:
                    print j['text']



                print '-----------------------'
示例#5
0
 def delete_product(self, productID):
     action = 'DeleteProduct'
     params = {
         'productID': productID,
     }
     service = QcloudApi(self.module, self.config)
     service.generateUrl(action, params)
     return service.call(action, params)
示例#6
0
 def create_multi_devices(self, productID, listDeviceName):
     params = {'listDeviceName.' +
               str(ix): device_name for ix, device_name in enumerate(listDeviceName)}
     params['productID'] = productID
     action = 'CreateMultiDevice'
     service = QcloudApi(self.module, self.config)
     service.generateUrl(action, params)
     return service.call(action, params)
示例#7
0
 def get_device_shadow(self, productID, deviceName):
     action = 'GetDeviceShadow'
     params = {
         'productID': productID,
         'deviceName': deviceName,
     }
     service = QcloudApi(self.module, self.config)
     service.generateUrl(action, params)
     return service.call(action, params)
示例#8
0
 def delete_device(self, productID, deviceName):
     action = 'DeleteDevice'
     params = {
         'productID': productID,
         'deviceName': deviceName,
     }
     service = QcloudApi(self.module, self.config)
     service.generateUrl(action, params)
     return service.call(action, params)
示例#9
0
 def list_products(self, pageNum, pageSize):
     action = 'ListProducts'
     params = {
         'pageNum': pageNum,
         'pageSize': pageSize,
     }
     service = QcloudApi(self.module, self.config)
     service.generateUrl(action, params)
     return service.call(action, params)
示例#10
0
 def get_create_multi_devtask(self, productID, taskID):
     action = 'GetCreateMultiDevTask'
     params = {
         'productID': productID,
         'taskID': taskID,
     }
     service = QcloudApi(self.module, self.config)
     service.generateUrl(action, params)
     return service.call(action, params)
示例#11
0
 def create_product(self, productName, encryptionType=1):
     action = 'CreateProduct'
     productProperties = "{\"productDescription\":\"\",\"region\":\"%s\", \"encryptionType\":\"%s\"}" % (self.config[
         'Region'], encryptionType)
     params = {
         'productName': productName,
         'productProperties': productProperties        }
     service = QcloudApi(self.module, self.config)
     service.generateUrl(action, params)
     return service.call(action, params)
示例#12
0
 def publish(self, topic, payload, productID, deviceName):
     action = 'Publish'
     params = {
         'topic': topic,
         'payload': payload,
         'productID': productID,
         'deviceName': deviceName,
     }
     service = QcloudApi(self.module, self.config)
     service.generateUrl(action, params)
     return service.call(action, params)
示例#13
0
 def get_multi_devices(self, productID, taskID, pageNum, pageSize):
     action = 'GetMultiDevices'
     params = {
         'productID': productID,
         'taskID': taskID,
         'pageNum': pageNum,
         'pageSize': pageSize,
     }
     service = QcloudApi(self.module, self.config)
     service.generateUrl(action, params)
     return service.call(action, params)
示例#14
0
 def update_device_shadow(self, productID, deviceName, version, stateString):
     action = 'UpdateDeviceShadow'
     params = {
         'productID': productID,
         'deviceName': deviceName,
         'state': stateString,
         'version': version
     }
     service = QcloudApi(self.module, self.config)
     service.generateUrl(action, params)
     return service.call(action, params)
示例#15
0
def main():
        service = QcloudApi(module, config)
        params["recordValue"] = getip()
        print "Your IP is " + params["recordValue"]

        print  "Setting record"
        service.generateUrl(action, params)
        ans = json.loads(service.call(action,params))
        if(ans["code"] == 0):
            raw_input("设置成功,请等几分钟生效")
        else:
            print("看起来设置失败了QAQ,失败信息是:",ans["message"],"\n失败代码:",ans["code"])
            raw_input()
示例#16
0
def get_overtime_containers(region, projectData):
    module = 'cvm'
    action = 'DescribeInstances'
    secretId = 'AKIDWxMDr345iqht1PJhXYi1k9zJ9khdvj1X'
    secretKey = 'R9PDuyIDLsLL8afFNX2wTFYQ13cdRvHh'
    config = {
        'Region': region,
        'secretId': secretId,
        'secretKey': secretKey,
        'method': 'get'
    }
    params = {
        'limit': 100,
        'Filters.1.Name': 'instance-charge-type',
        'Filters.1.Values.1': 'POSTPAID_BY_HOUR'
    }  # 目前只查询按量付费的参数Filters没起作用
    global instance_list
    try:
        service = QcloudApi(module, config)
        # print service.generateUrl(action, params)
        data = json.loads(service.call(action, params))['instanceSet']
        now = datetime.datetime.now()
        for da in data:
            createTime = datetime.datetime.strptime(da['createTime'],
                                                    '%Y-%m-%d %H:%M:%S')
            second = (now - createTime).total_seconds()
            # if createTime.strftime('%Y-%m-%d') == '2017-11-01' and second >= 1800:
            if da['cvmPayMode'] == 2 and createTime.strftime(
                    '%Y-%m-%d') == now.strftime('%Y-%m-%d') and second >= 1200:
                instance = {}
                print da['createTime'], da['instanceName'], da[
                    'unInstanceId'], int(second / 60)
                for project in projectData['data']:
                    if project['projectId'] == da['projectId']:
                        instance['projectName'] = project['projectName']
                        break
                instance['instanceName'] = da['instanceName']
                instance['unInstanceId'] = da['unInstanceId']
                instance['createTime'] = da['createTime']
                instance['zoneName'] = da['zoneName']
                instance['timeCast'] = int(second / 60)
                if instance['projectName'] != u'东京喰种':
                    instance_list.append(instance)
    except Exception, e:
        print 'exception:', e
示例#17
0
文件: demo.py 项目: zl1234/TourSite
def search2(query):
    paramssearch['appId'] = appId2
    paramssearch['search_query'] = query
    service = QcloudApi(module, config)
    url = service.generateUrl(action2, paramssearch)
    info = service.call(action2, paramssearch)
    re1 = re.compile('"code":(\w+),')
    re2 = re.compile('"result_num":(\w+),')
    re3 = re.compile(
        '"doc_meta":"\{\\\\"forprint\\\\":\\\\"c02b88ca97f3dd17b572e92d7ca07955\\\\",\\\\"id\\\\":\\\\"(.+?)\\\\",\\\\"tdays\\\\":\\\\"(.+?)\\\\",\\\\"tdescrip\\\\":\\\\"(.+?)\\\\",\\\\"tdest\\\\":\\\\"(.+?)\\\\",\\\\"tname\\\\":\\\\"(.+?)\\\\",\\\\"tpeople\\\\":\\\\"(.+?)\\\\"\}'
    )
    if re1.findall(info) != ['0']:
        output = open('errorlog', 'a+')
        output.write("search error:\n")
        output.write(url)
        output.write(info)
        output.write("\n")
        output.close()
        return [{
            'id': -1,
            'tdays': 'False',
            'tname': 'False',
            'tdescrip': 'False',
            'tpeople': 'False',
            'tdest': 'False'
        }]
        #检查是否成功,错误返回信息写入日志
    counter = (int)(re2.findall(info)[0][0])
    port = re3.findall(info)
    ppport = []
    for i in range(0, counter):
        pport = {}
        pport['id'] = (port[i][0].decode('raw_unicode_escape')).encode("utf-8")
        pport['tdays'] = (
            port[i][1].decode('raw_unicode_escape')).encode("utf-8")
        pport['tname'] = (
            port[i][4].decode('raw_unicode_escape')).encode("utf-8")
        pport['tdescrip'] = (
            port[i][2].decode('raw_unicode_escape')).encode("utf-8")
        pport['tpeople'] = (
            port[i][5].decode('raw_unicode_escape')).encode("utf-8")
        pport['tdest'] = (
            port[i][3].decode('raw_unicode_escape')).encode("utf-8")
        ppport.append(pport)
    return ppport
示例#18
0
def printpromotion(word):
    module = 'wenzhi'
    action = 'TextSentiment'
    service = QcloudApi(module, config)

    word = word.encode("utf-8")  ####编码
    #weburl='https://api.prprpr.me/emotion/wenzhi?password=DIYgod&text='+word
    params = {
        'content': word,  #utf8 only
        'type': 4  #(可选参数,默认为4) 1:电商;2:APP;3:美食;4:酒店和其他。
    }
    #r = requests.get('%s' %weburl)
    json_str = json.loads(service.call(action, params))
    print "positive emotion:", (format(json_str["positive"], '0.1%'))
    print "negative emotion:", (format(json_str["negative"], '0.1%'))
    #ps = json_str["positive"]
    #ne = json_str["negative"]
    return json_str
示例#19
0
def printpromotion(word):
    #####腾讯文智感情分析API配置##############
    module = 'wenzhi'
    action = 'TextSentiment'
    service = QcloudApi(module, config)

    word = word.encode("utf-8")  ####编码
    #####腾讯文智感情分析API配置##############
    params = {
        'content': word,  #utf8 only
        'type': 4  #(可选参数,默认为4) 1:电商;2:APP;3:美食;4:酒店和其他。
    }
    #r = requests.get('%s' %weburl)
    json_str = json.loads(service.call(action, params))
    print "positive emotion:", (format(json_str["positive"], '0.1%'))
    print "negative emotion:", (format(json_str["negative"], '0.1%'))
    #ps = json_str["positive"]
    #ne = json_str["negative"]
    return json_str
示例#20
0
文件: demo.py 项目: cnbillow/TourSite
def upload1(did, dname, dinfo):
    paramsupload1['appId'] = appId1
    paramsupload1['contents.0.dname'] = dname
    paramsupload1['contents.0.dinfo'] = dinfo
    paramsupload1['contents.0.id'] = did
    service = QcloudApi(module, config)
    url = service.generateUrl(action1, paramsupload1)
    info = service.call(action1, paramsupload1)
    re1 = re.compile('"code":(\w+),')
    re2 = re.compile('"errmsg":"(\w+)",')
    if re1.findall(info) != ['0'] or re2.findall(info) != ['succ']:
        output = open('errorlog', 'a+')
        output.write("upload error:\n")
        output.write(url)
        output.write(info)
        output.write("\n")
        output.close()
        return False
    return True
示例#21
0
文件: demo.py 项目: zl1234/TourSite
def upload3(jid, jname, jtag):
    paramsupload3['appId'] = appId3
    paramsupload3['contents.0.jname'] = jname
    paramsupload3['contents.0.forprint'] = 'c02b88ca97f3dd17b572e92d7ca07955'
    paramsupload3['contents.0.jtag'] = jtag
    paramsupload3['contents.0.id'] = jid
    service = QcloudApi(module, config)
    url = service.generateUrl(action1, paramsupload3)
    info = service.call(action1, paramsupload3)
    re1 = re.compile('"code":(\w+),')
    re2 = re.compile('"errmsg":"(\w+)",')
    if re1.findall(info) != ['0'] or re2.findall(info) != ['succ']:
        output = open('errorlog', 'a+')
        output.write("upload error:\n")
        output.write(url)
        output.write(info)
        output.write("\n")
        output.close()
        return False
    return True
示例#22
0
文件: demo.py 项目: cnbillow/TourSite
def upload2(tid, tdays, tname, tdescrip, tpeople, tdest):
    paramsupload2['appId'] = appId2
    paramsupload2['contents.0.tname'] = tname
    paramsupload2['contents.0.tdescrip'] = tdescrip
    paramsupload2['contents.0.tpeople'] = tpeople
    paramsupload2['contents.0.tdest'] = tdest
    paramsupload2['contents.0.id'] = tid
    paramsupload2['contents.0.tdays'] = tdays
    service = QcloudApi(module, config)
    url = service.generateUrl(action1, paramsupload2)
    info = service.call(action1, paramsupload2)
    re1 = re.compile('"code":(\w+),')
    re2 = re.compile('"errmsg":"(\w+)",')
    if re1.findall(info) != ['0'] or re2.findall(info) != ['succ']:
        output = open('errorlog', 'a+')
        output.write("upload error:\n")
        output.write(url)
        output.write(info)
        output.write("\n")
        output.close()
        return False
    return True
示例#23
0
#!/usr/bin/python
# -*- coding: utf-8 -*-
import json
from src.QcloudApi.qcloudapi import QcloudApi

module = 'cdn'
action = 'DescribeCdnHosts'
config = {
    'Region': 'gz',
    'secretId': 'AKIDnX6UjeBdjiXDh4TM9oIbigT6YoyzwtdM',
    'secretKey': 'mNm03vdBXihVDj4DC0c4LXYP4XvBHCyc',
    'method': 'get'
}
params = {}
# params = {
#     'entityFileName': '/test.txt',
#     'entityFile': '/tmp/test.txt',
#     'SignatureMethod':'HmacSHA256',#指定所要用的签名算法,可选HmacSHA256或HmacSHA1,默认为HmacSHA1
# }
try:
    service = QcloudApi(module, config)
    print service.generateUrl(action, params)
    print json.loads(service.call(action, params))
    #service.setRequestMethod('get')
    #print service.call('DescribeCdnEntities', {})
except Exception, e:
    print 'exception:', e
示例#24
0
# -*- coding: utf-8 -*-
from src.QcloudApi.qcloudapi import QcloudApi

module = 'wenzhi'

config = {
    'Region': 'my Region',
    'secretId': 'my SecretID',
    'secretKey': 'my SecretKey',
    'method': 'post'
}

action = 'TextClassify'

params = {'content': 'my content'}
try:
    service = QcloudApi(module, config)
    print service.call(action, params).decode('unicode_escape')
except Exception, e:
    print 'exception:', e
示例#25
0
#!/usr/bin/python
# -*- coding: utf-8 -*-

from src.QcloudApi.qcloudapi import QcloudApi

module = 'cdn'
action = 'UploadCdnEntity'
config = {
    'Region': 'gz',
    'secretId': '你的secretId',
    'secretKey': '你的secretKey',
    'method': 'post'
}
params = {
    'entityFileName': '/test.txt',
    'entityFile': '/tmp/test.txt'
}
try:
    service = QcloudApi(module, config)
    print service.generateUrl(action, params)
    print service.call(action, params)
    #service.setRequestMethod('get')
    #print service.call('DescribeCdnEntities', {})
except Exception, e:
    print 'exception:', e
示例#26
0
module = 'cdb'
action = 'DescribeCdbSlowQueryLog'
config = {
    'Region': 'sh',
    'secretId': '',
    'secretKey': '',
    'method': 'post'
}
params = {
    'cdbInstanceId': 'cdb-l1w9eda6',
    'limit': '100'
}
try:
    service = QcloudApi(module, config)
    # print service.generateUrl(action, params)

    with open('/usr/local/zabbix/frontends/php/slowlog/' + datetime.now().date().strftime('%Y.%m.%d') + '_slowquery.txt', 'w') as f:

        # print service.call(action, params)
        print >> f, service.call(action, params)

        result = json.loads(service.call(action, params))
        querycount = result["totalCount"]+21

        triggers = zapi.trigger.update(
        triggerid='15956',
        description="{master_001:mysql.status[Slow_queries].last()}>" + str(querycount),
        expression="{master_001:mysql.status[Slow_queries].last()}>" + str(querycount)
        )

except Exception, e:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import os

sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)) + "/../..")
from src.QcloudApi.qcloudapi import QcloudApi

action = 'DeleteForwardLBListenerRules'  # 删除应用型负载均衡的转发规则
"""
loadBalancerId 必传 负载均衡ID
listenerId     必传 监听器ID
locationIds.n  非必传 转发规则ID,默认全部删除
domain         非必传 转发规则域名,默认不做过滤条件
url            非必传 转发规则路径,默认不做过滤条件
"""
region = 'gz'

params = {
    'loadBalancerId': 'lb-6efswuxa',
    'listenerId': 'lbl-fh7o7b9o',
    'locationIds.0': "loc-jw3a7y2o",
}

try:
    service = QcloudApi(region=region)
    print service.generateUrl(action, params)
    print service.call(action, params)
except Exception, e:
    print 'exception:', e
示例#28
0
#!/usr/bin/python
# -*- coding: utf-8 -*-

from src.QcloudApi.qcloudapi import QcloudApi

module = 'cvm'
action = 'DescribeInstances'
config = {
    'Region': 'gz',
    'secretId': '',
    'secretKey': '',
    'method': 'post'
}
params = {

}
try:
    service = QcloudApi(module, config)
    print(service.generate_url(action, params))
    print(service.call(action, params))
    # service.setRequestMethod('get')
    # print(service.call('DescribeCdnEntities', {}))
except Exception as e:
    print('exception:', e)