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