Compare commits
No commits in common. "fe755c0455104a34e699f6834980036198fce07f" and "551ba4a04aa142c16064dde777b5632d336dd322" have entirely different histories.
fe755c0455
...
551ba4a04a
|
@ -8,12 +8,10 @@ import datetime
|
||||||
# 获取当前日期
|
# 获取当前日期
|
||||||
current_date = datetime.date.today()
|
current_date = datetime.date.today()
|
||||||
previous_date = current_date - datetime.timedelta(days=2)
|
previous_date = current_date - datetime.timedelta(days=2)
|
||||||
|
|
||||||
formatted_current_date = current_date.strftime("%Y-%m-%dT%H:%M:%SZ")
|
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_date = previous_date.strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||||
|
|
||||||
|
print('开始加载数据:custom_events_5:获取线索事件_c_minipro_page_view')
|
||||||
print('开始加载数据:custom_events_update:合并SCRM CONTACT')
|
|
||||||
authUrl='https://api.huiju.cool/v2/oauth2/token?app_id=cl037b184ebccd97c&secret=deaa83fdd8d385eec0d1d04d34282c4ec8c33b60&grant_type=client_credentials'
|
authUrl='https://api.huiju.cool/v2/oauth2/token?app_id=cl037b184ebccd97c&secret=deaa83fdd8d385eec0d1d04d34282c4ec8c33b60&grant_type=client_credentials'
|
||||||
|
|
||||||
print('开始请求令牌。')
|
print('开始请求令牌。')
|
||||||
|
@ -22,7 +20,7 @@ auth=json.loads(authRequest.text)
|
||||||
print('开始请求数据总数。')
|
print('开始请求数据总数。')
|
||||||
url='https://api.huiju.cool/v2/customerEvents'
|
url='https://api.huiju.cool/v2/customerEvents'
|
||||||
header={}
|
header={}
|
||||||
body={'access_token':auth['access_token'],'sort':'lastUpdated','lastUpdated[ge]':formatted_current_date,'lastUpdated[le]':formatted_previous_date,'limit':'2000',}
|
body={'access_token':auth['access_token'],'limit':'2000','event':'c_minipro_page_view','sort':'date','date[ge]':formatted_previous_date,'date[le]':formatted_current_date,}
|
||||||
dataReqL=requests.get(url,headers=header,params=body)
|
dataReqL=requests.get(url,headers=header,params=body)
|
||||||
resL=json.loads(dataReqL.text)
|
resL=json.loads(dataReqL.text)
|
||||||
# print(resL)
|
# print(resL)
|
||||||
|
@ -35,9 +33,9 @@ dataId=str(uuid.uuid4())
|
||||||
print('临时id:'+dataId)
|
print('临时id:'+dataId)
|
||||||
json_object = json.dumps(dataList)
|
json_object = json.dumps(dataList)
|
||||||
cur=conn.cursor()
|
cur=conn.cursor()
|
||||||
sql="update data_api.api_data set is_loaded = '1' where api_id = 'ff5c7bf6-0d18-4201-9501-8fdd6152';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),'')"
|
sql="update data_api.api_data set is_loaded = '1' where api_id = 'a71a43ff-efcd-4427-8dbc-ed2686e4';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,'ff5c7bf6-0d18-4201-9501-8fdd6152',json_object,total])
|
cur.execute(sql,[dataId,'a71a43ff-efcd-4427-8dbc-ed2686e4',json_object,total])
|
||||||
conn.commit()
|
conn.commit()
|
||||||
cur.close()
|
cur.close()
|
||||||
conn.close()
|
conn.close()
|
||||||
print('加载数据结束:custom_events_update:合并SCRM CONTACT')
|
print('加载数据结束:custom_events_5:获取线索事件_c_minipro_page_view')
|
|
@ -3,103 +3,91 @@
|
||||||
\set AUTOCOMMIT on
|
\set AUTOCOMMIT on
|
||||||
\timing on
|
\timing on
|
||||||
|
|
||||||
DELETE FROM data_api.customer_events_lastupdated;
|
DELETE FROM data_api.customer_events_c_minipro_page_view;
|
||||||
|
|
||||||
insert into data_api.customer_events_lastupdated (
|
insert into data_api.customer_events_c_minipro_page_view (
|
||||||
date
|
browser
|
||||||
, screen_width
|
, browser_version
|
||||||
, target_name
|
, c_name
|
||||||
|
, c_source_content
|
||||||
|
, c_url
|
||||||
|
, customer_id
|
||||||
|
, customer_id_str
|
||||||
|
, date
|
||||||
|
, event
|
||||||
|
, external_id
|
||||||
|
, id
|
||||||
|
, id_str
|
||||||
|
, ip
|
||||||
, ip_city
|
, ip_city
|
||||||
, ip_country
|
, ip_country
|
||||||
, platform
|
|
||||||
, last_updated
|
|
||||||
, page_type
|
|
||||||
, os_version
|
|
||||||
, browser
|
|
||||||
, browser_version
|
|
||||||
, customer_id
|
|
||||||
, id
|
|
||||||
, tag
|
|
||||||
, event
|
|
||||||
, id_str
|
|
||||||
, os
|
|
||||||
, target_id
|
|
||||||
, customer_id_str
|
|
||||||
, ip
|
|
||||||
, screen_height
|
|
||||||
, external_id
|
|
||||||
, ip_county
|
|
||||||
, page_id
|
|
||||||
, url
|
|
||||||
, ip_province
|
, ip_province
|
||||||
, device
|
, last_updated
|
||||||
|
, os
|
||||||
|
, os_version
|
||||||
|
, platform
|
||||||
|
, target_id
|
||||||
|
, target_name
|
||||||
|
, url
|
||||||
,etl_tx_dt
|
,etl_tx_dt
|
||||||
)
|
)
|
||||||
select
|
select
|
||||||
case when trim(both from date)='' then null else date::text end date
|
case when trim(both from browser)='' then null else browser::text end browser
|
||||||
, case when trim(both from screen_width)='' then null else screen_width::text end screen_width
|
, case when trim(both from browser_version)='' then null else browser_version::text end browser_version
|
||||||
, case when trim(both from target_name)='' then null else target_name::text end target_name
|
, case when trim(both from c_name)='' then null else c_name::text end c_name
|
||||||
|
, case when trim(both from c_source_content)='' then null else c_source_content::text end c_source_content
|
||||||
|
, case when trim(both from c_url)='' then null else c_url::text end c_url
|
||||||
|
, case when trim(both from customer_id)='' then null else customer_id::text end customer_id
|
||||||
|
, case when trim(both from customer_id_str)='' then null else customer_id_str::text end customer_id_str
|
||||||
|
, case when trim(both from date)='' then null else date::text end date
|
||||||
|
, case when trim(both from event)='' then null else event::text end event
|
||||||
|
, case when trim(both from external_id)='' then null else external_id::text end external_id
|
||||||
|
, case when trim(both from id)='' then null else id::text end id
|
||||||
|
, case when trim(both from id_str)='' then null else id_str::text end id_str
|
||||||
|
, case when trim(both from ip)='' then null else ip::text end ip
|
||||||
, case when trim(both from ip_city)='' then null else ip_city::text end ip_city
|
, case when trim(both from ip_city)='' then null else ip_city::text end ip_city
|
||||||
, case when trim(both from ip_country)='' then null else ip_country::text end ip_country
|
, case when trim(both from ip_country)='' then null else ip_country::text end ip_country
|
||||||
, case when trim(both from platform)='' then null else platform::text end platform
|
|
||||||
, case when trim(both from last_updated)='' then null else last_updated::text end last_updated
|
|
||||||
, case when trim(both from page_type)='' then null else page_type::text end page_type
|
|
||||||
, case when trim(both from os_version)='' then null else os_version::text end os_version
|
|
||||||
, case when trim(both from browser)='' then null else browser::text end browser
|
|
||||||
, case when trim(both from browser_version)='' then null else browser_version::text end browser_version
|
|
||||||
, case when trim(both from customer_id)='' then null else customer_id::text end customer_id
|
|
||||||
, case when trim(both from id)='' then null else id::text end id
|
|
||||||
, case when trim(both from tag)='' then null else tag::text end tag
|
|
||||||
, case when trim(both from event)='' then null else event::text end event
|
|
||||||
, case when trim(both from id_str)='' then null else id_str::text end id_str
|
|
||||||
, case when trim(both from os)='' then null else os::text end os
|
|
||||||
, case when trim(both from target_id)='' then null else target_id::text end target_id
|
|
||||||
, case when trim(both from customer_id_str)='' then null else customer_id_str::text end customer_id_str
|
|
||||||
, case when trim(both from ip)='' then null else ip::text end ip
|
|
||||||
, case when trim(both from screen_height)='' then null else screen_height::text end screen_height
|
|
||||||
, case when trim(both from external_id)='' then null else external_id::text end external_id
|
|
||||||
, case when trim(both from ip_county)='' then null else ip_county::text end ip_county
|
|
||||||
, case when trim(both from page_id)='' then null else page_id::text end page_id
|
|
||||||
, case when trim(both from url)='' then null else url::text end url
|
|
||||||
, case when trim(both from ip_province)='' then null else ip_province::text end ip_province
|
, case when trim(both from ip_province)='' then null else ip_province::text end ip_province
|
||||||
, case when trim(both from device)='' then null else device::text end device
|
, case when trim(both from last_updated)='' then null else last_updated::text end last_updated
|
||||||
|
, case when trim(both from os)='' then null else os::text end os
|
||||||
|
, case when trim(both from os_version)='' then null else os_version::text end os_version
|
||||||
|
, case when trim(both from platform)='' then null else platform::text end platform
|
||||||
|
, case when trim(both from target_id)='' then null else target_id::text end target_id
|
||||||
|
, case when trim(both from target_name)='' then null else target_name::text end target_name
|
||||||
|
, case when trim(both from url)='' then null else url::text end url
|
||||||
,etl_tx_dt
|
,etl_tx_dt
|
||||||
from (
|
from (
|
||||||
select
|
select
|
||||||
(json_array_elements(data::json)::json->>'date') date
|
(json_array_elements(data::json)::json->>'browser') browser
|
||||||
, (json_array_elements(data::json)::json->>'screenWidth') screen_width
|
, (json_array_elements(data::json)::json->>'browserVersion') browser_version
|
||||||
, (json_array_elements(data::json)::json->>'targetName') target_name
|
, (json_array_elements(data::json)::json->>'c_name') c_name
|
||||||
|
, (json_array_elements(data::json)::json->>'c_sourceContent') c_source_content
|
||||||
|
, (json_array_elements(data::json)::json->>'c_url') c_url
|
||||||
|
, (json_array_elements(data::json)::json->>'customerId') customer_id
|
||||||
|
, (json_array_elements(data::json)::json->>'customerIdStr') customer_id_str
|
||||||
|
, (json_array_elements(data::json)::json->>'date') date
|
||||||
|
, (json_array_elements(data::json)::json->>'event') event
|
||||||
|
, (json_array_elements(data::json)::json->>'externalId') external_id
|
||||||
|
, (json_array_elements(data::json)::json->>'id') id
|
||||||
|
, (json_array_elements(data::json)::json->>'idStr') id_str
|
||||||
|
, (json_array_elements(data::json)::json->>'ip') ip
|
||||||
, (json_array_elements(data::json)::json->>'ipCity') ip_city
|
, (json_array_elements(data::json)::json->>'ipCity') ip_city
|
||||||
, (json_array_elements(data::json)::json->>'ipCountry') ip_country
|
, (json_array_elements(data::json)::json->>'ipCountry') ip_country
|
||||||
, (json_array_elements(data::json)::json->>'platform') platform
|
|
||||||
, (json_array_elements(data::json)::json->>'lastUpdated') last_updated
|
|
||||||
, (json_array_elements(data::json)::json->>'pageType') page_type
|
|
||||||
, (json_array_elements(data::json)::json->>'osVersion') os_version
|
|
||||||
, (json_array_elements(data::json)::json->>'browser') browser
|
|
||||||
, (json_array_elements(data::json)::json->>'browserVersion') browser_version
|
|
||||||
, (json_array_elements(data::json)::json->>'customerId') customer_id
|
|
||||||
, (json_array_elements(data::json)::json->>'id') id
|
|
||||||
, (json_array_elements(data::json)::json->>'tag') tag
|
|
||||||
, (json_array_elements(data::json)::json->>'event') event
|
|
||||||
, (json_array_elements(data::json)::json->>'idStr') id_str
|
|
||||||
, (json_array_elements(data::json)::json->>'os') os
|
|
||||||
, (json_array_elements(data::json)::json->>'targetId') target_id
|
|
||||||
, (json_array_elements(data::json)::json->>'customerIdStr') customer_id_str
|
|
||||||
, (json_array_elements(data::json)::json->>'ip') ip
|
|
||||||
, (json_array_elements(data::json)::json->>'screenHeight') screen_height
|
|
||||||
, (json_array_elements(data::json)::json->>'externalId') external_id
|
|
||||||
, (json_array_elements(data::json)::json->>'ipCounty') ip_county
|
|
||||||
, (json_array_elements(data::json)::json->>'pageId') page_id
|
|
||||||
, (json_array_elements(data::json)::json->>'url') url
|
|
||||||
, (json_array_elements(data::json)::json->>'ipProvince') ip_province
|
, (json_array_elements(data::json)::json->>'ipProvince') ip_province
|
||||||
, (json_array_elements(data::json)::json->>'device') device
|
, (json_array_elements(data::json)::json->>'lastUpdated') last_updated
|
||||||
|
, (json_array_elements(data::json)::json->>'os') os
|
||||||
|
, (json_array_elements(data::json)::json->>'osVersion') os_version
|
||||||
|
, (json_array_elements(data::json)::json->>'platform') platform
|
||||||
|
, (json_array_elements(data::json)::json->>'targetId') target_id
|
||||||
|
, (json_array_elements(data::json)::json->>'targetName') target_name
|
||||||
|
, (json_array_elements(data::json)::json->>'url') url
|
||||||
,CURRENT_TIMESTAMP(0) etl_tx_dt
|
,CURRENT_TIMESTAMP(0) etl_tx_dt
|
||||||
from (select * from data_api.api_data
|
from (select * from data_api.api_data
|
||||||
WHERE api_id='ff5c7bf6-0d18-4201-9501-8fdd6152' and is_loaded = '0' order by request_tm desc limit 1) p )p;
|
WHERE api_id='a71a43ff-efcd-4427-8dbc-ed2686e4' and is_loaded = '0' order by request_tm desc limit 1) p )p;
|
||||||
|
|
||||||
update data_api.api_data
|
update data_api.api_data
|
||||||
set is_loaded = '1' ,
|
set is_loaded = '1' ,
|
||||||
status = '1',
|
status = '1',
|
||||||
request_tm = current_timestamp(0)
|
request_tm = current_timestamp(0)
|
||||||
where api_id='ff5c7bf6-0d18-4201-9501-8fdd6152';
|
where api_id='a71a43ff-efcd-4427-8dbc-ed2686e4';
|
||||||
\q
|
\q
|
Loading…
Reference in New Issue