dataops/TK_Cust/dev/tk_api/获取SCRM contact/scrm_contact_feign.py

43 lines
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# coding: utf-8
import requests
import json
import psycopg2
import uuid
import datetime
# 获取当前日期
current_date = datetime.date.today()
previous_date = current_date - datetime.timedelta(days=1)
previous_date2 = current_date - datetime.timedelta(days=3)
formatted_current_date = current_date.strftime("%Y-%m-%dT%H:%M:%SZ")
formatted_previous_date = previous_date.strftime("%Y-%m-%dT%H:%M:%SZ")
formatted_previous_date2 = previous_date2.strftime("%Y-%m-%dT%H:%M:%SZ")
print('开始加载数据scrm_contact:获取SCRM contact')
authUrl='https://api.huiju.cool/v2/oauth2/token?app_id=cl037b184ebccd97c&secret=deaa83fdd8d385eec0d1d04d34282c4ec8c33b60&grant_type=client_credentials'
print('开始请求令牌。')
authRequest=requests.get(authUrl)
auth=json.loads(authRequest.text)
print('开始请求数据总数。')
url='https://api.huiju.cool/v2/customers'
header={}
body={'access_token':auth['access_token'],'sort':'dateJoin','limit':'2000','dateJoin[le]':formatted_previous_date1,'dateJoin[ge]':formatted_previous_date2,}
dataReqL=requests.get(url,headers=header,params=body)
resL=json.loads(dataReqL.text)
# print(resL)
dataList=resL['data']
total=len(dataList)
conn = psycopg2.connect(database="dataops_db", user="dbuser_dops", password="MIgTi3jA",
host="172.17.0.8", port="5432")
print('数据库连接成功')
dataId=str(uuid.uuid4())
print('临时id'+dataId)
json_object = json.dumps(dataList)
cur=conn.cursor()
sql="update data_api.api_data set is_loaded = '1' where api_id = 'cab1a761-b8e5-4db4-a769-88db3ec1';INSERT INTO data_api.api_data (id,api_id,data,total_num,is_loaded,status,request_tm,execute_tm,remark) values (%s,%s,%s,%s,'0','0',current_timestamp(0),current_timestamp(0),'')"
cur.execute(sql,[dataId,'cab1a761-b8e5-4db4-a769-88db3ec1',json_object,total])
conn.commit()
cur.close()
conn.close()
print('加载数据结束scrm_contact:获取SCRM contact')