add workflow 天润Smart-ccc客户数据,dev
This commit is contained in:
parent
3b2692fb01
commit
965022f290
|
@ -62,38 +62,39 @@ def build_query_string(params):
|
||||||
return query_string
|
return query_string
|
||||||
|
|
||||||
|
|
||||||
|
def request_data_signature_post(customerId):
|
||||||
def request_data_signature_post():
|
print(f'开始请求客户可用标签数据:{formatted2_previous_hour(0)}')
|
||||||
print('开始请求数据...')
|
|
||||||
url='https://api-bj.clink.cn/crm/list_customer_labels'
|
url='https://api-bj.clink.cn/crm/list_customer_labels'
|
||||||
header={}
|
header={'Content-Type':'application/json;charset=UTF-8'}
|
||||||
param={'AccessKeyId':'b17759d3a36fba9a2cf522fbf4cbf177','Timestamp':current_time_utc,'Expires':Expires,}
|
param={'AccessKeyId':'b17759d3a36fba9a2cf522fbf4cbf177','Timestamp':current_time_utc,'Expires':86400}
|
||||||
print(f'param: {param}')
|
print(f'param: {param}')
|
||||||
paramJson = {"Timestamp":""}
|
|
||||||
print(f'paramJson: {paramJson}')
|
|
||||||
url_path = build_query_string(param)
|
url_path = build_query_string(param)
|
||||||
url_param = build_query_string(param)
|
url_param = url_path
|
||||||
print(f'url_param: {url_param}')
|
print(f'url_param: {url_param}')
|
||||||
url_param = f'POSTapi-bj.clink.cn/crm/list_customer_labels?{url_param}'
|
url_param = f'POSTapi-bj.clink.cn/crm/list_customer_labels?{url_param}'
|
||||||
print(f'url_param2: {url_param}')
|
print(f'待计算字符串: {url_param}')
|
||||||
signature= generate_signature(url_param,'5g027B6w06630Y5240c1')
|
signature= generate_signature(url_param,'5g027B6w06630Y5240c1')
|
||||||
print(f'signature: {signature}')
|
print(f'计算签名: {signature}')
|
||||||
url = f'{url}?{url_path}&Signature={signature}'
|
print(f'编码后签名: {urllib.parse.quote_plus(signature)}')
|
||||||
|
url = f'{url}?{url_path}&Signature={urllib.parse.quote_plus(signature)}'
|
||||||
print(f'url: {url}')
|
print(f'url: {url}')
|
||||||
|
|
||||||
body={}
|
body={}
|
||||||
print(f'body: {body}')
|
jsonData = json.dumps(body)
|
||||||
dataReqL=requests.post(url,headers=header,params=body)
|
print(f'body: {jsonData}')
|
||||||
|
dataReqL=requests.post(url,headers=header,data=jsonData)
|
||||||
|
resText = dataReqL.text
|
||||||
i = 0
|
i = 0
|
||||||
while 'error' in dataReqL and i < 5:
|
while 'error' in resText and i < 5:
|
||||||
|
print(f'请求客户可用标签数据失败,再次请求第{i+1}次')
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
dataReqL=requests.post(url,headers=header,params=body)
|
dataReqL=requests.post(url,headers=header,params=body)
|
||||||
i = i + 1
|
i = i + 1
|
||||||
resL=json.loads(dataReqL.text)
|
resL=json.loads(resText)
|
||||||
print(dataReqL)
|
|
||||||
resL=json.loads(dataReqL.text)
|
|
||||||
return resL
|
return resL
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def load_data_to_db(dataList):
|
def load_data_to_db(dataList):
|
||||||
conn = psycopg2.connect(database="dataops_db", user="dbuser_dops", password="MIgTi3jA",host="172.17.0.8", port="5432")
|
conn = psycopg2.connect(database="dataops_db", user="dbuser_dops", password="MIgTi3jA",host="172.17.0.8", port="5432")
|
||||||
print('数据库连接成功')
|
print('数据库连接成功')
|
||||||
|
@ -113,11 +114,13 @@ def load_data_to_db(dataList):
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
print(f'{formatted2_previous_hour(0)}开始请求客户可用标签数据')
|
||||||
resL = request_data_signature_post()
|
resL = request_data_signature_post()
|
||||||
print(resL)
|
# print(resL)
|
||||||
|
|
||||||
|
|
||||||
if 'error' in resL:
|
if 'error' in resL:
|
||||||
load_error_to_db(resl)
|
error = resL['error']
|
||||||
load_data_to_db(resL[''customerLabels'])
|
print(f'请求客户资料列表失败,失败原因:{error}')
|
||||||
|
else:
|
||||||
|
dataList = resL['customerLabels']
|
||||||
|
load_data_to_db(dataList)
|
||||||
|
print(f'{formatted2_previous_hour(0)}请求客户可用标签数据结束')
|
Loading…
Reference in New Issue