Commit 5f524fac authored by 桂秋月's avatar 桂秋月

钉钉发送消息

parent cb8e5b06
No preview for this file type
......@@ -3,3 +3,4 @@
/recommend/tempFile/*
/tools/changeLXQpassword.py
/tools/temp.py
/auto/*
\ No newline at end of file
......@@ -2,5 +2,6 @@
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
import allure
from databaseConn import *
from tools import *
from tools.publicFun import *
from tools.httprequest import *
from tools.listOperation import *
from databaseConn.mysqlOperation import *
from databaseConn.redisOperation import *
from recommend.publicSql import *
cur_dir=os.path.dirname(os.path.abspath(__file__))
auto_path=os.path.join(cur_dir,'tempFile')
......@@ -23,7 +23,7 @@ mysql_info={
"host":"172.30.220.11",
"port":"15307"
},
"saas5":{
"tobsaas5":{
"name":"root",
"pwd":"123456",
"host":"172.29.2.5",
......@@ -59,6 +59,12 @@ mysql_info={
"host":"172.16.9.89",
"port":"3306"
},
"onlinetob":{
"name":"qiuyue.gui",
"pwd":"bJ3q6DqrbUxL0YnL",
"host":"10.250.2.212",
"port":"13312"
},
"feature_aliyun":{
"host":"aliyun-test.mysql.rds.aliyuncs.com",
"pwd":"NaL7F7j522Kn8D5kJz",
......
......@@ -58,16 +58,24 @@ def concatSql(sql,**kwargs):
'''
:param sql:
:param kwargs:
:return: 只针对select的sql拼接,拼接后where是and的关系
:return: 只针对select的sql拼接,拼接后where是and|or的关系
'''
if not kwargs:
return sql
temp=' '
for k,v in kwargs.items():
if k=='oper':
continue
if isinstance(v,(list,tuple)):
if len(v)>1:
if kwargs.get('oper') and kwargs.get('oper')=='not':
concatinfo=k+" not in "+ '{}' +' and '
else:
concatinfo=k+" in "+ '{}' +' and '
temp+=concatinfo.format(tuple(v))
else:
if kwargs.get('oper') and kwargs.get('oper')=='not':
temp+=k+'<>'+"'"+str(v[0])+"'" +' and '
else:
temp+=k+'='+"'"+str(v[0])+"'" +' and '
......@@ -76,5 +84,5 @@ def concatSql(sql,**kwargs):
return sql+' where '+temp[:-4]
if __name__ == '__main__':
#print(mysqlInfo('test1'))
print(execmysl('yxm',"select 1 "))
\ No newline at end of file
print(mysqlInfo('saas4'))
#print(execmysl('yxm',"select 1 "))
\ No newline at end of file
......@@ -75,6 +75,7 @@ def getRedisValue(redis_key=None,key=None,conntype=None,oper='select'):
:param oper:如果是delete,则做删除操作。目前只支持delete,select
:return:select->获取所有匹配到key的值
'''
flag=0
redis_db_conn=redis_conn(redis_key)
if 'select' in key or 'from' in key:
raise Exception('在redis看来不是有效的key',key)
......@@ -98,7 +99,11 @@ def getRedisValue(redis_key=None,key=None,conntype=None,oper='select'):
elif redis_key_type in ('dict','hash'):
redis_value[i]=redis_db_conn.hgetall(i)
for k,v in redis_value[i].items():
print('redis key[{}]'.format(i),"===>",k,'===>',v)
print('前10条记录,redis key[{}]'.format(i),"===>",k,'===>',v)
flag+=1
if flag>10:
break
# uuid_redis_result = redis_db_conn.hgetall(i)
elif redis_key_type=='string':
#print(i)
......@@ -126,11 +131,14 @@ if __name__ == '__main__':
#redis_db.lpush(redis_key,*sku_list.split(','))
redis_key="appstart:1d0cdee1-85af-4e5b-856e-4a2e453befb6-2"
redis_key="price-tracker:stock:9"
redis_key="nearline_recommend:real-time:user_feature:*"
redis_key="nearline_recommend:real-time:user_feature:54ad92ae-d1f1-4dad-a001-38904248fba5"
#redis_key="nearline_recommend:real-time:user_feature:*"
#redis_key="nearline_recommend:offline:feed_sort_sku_cid3_feature3"
#print(getRedisValue('yxm',redis_key,oper='delete1'))
#print(getRedisValue(redis_key='89',key=redis_key))
print(getRedisValue('89',key=redis_key))
conn=redis_conn('89')
print(conn.type(redis_key))
#print(getRedisValue('89',key=redis_key))
......
from recommend import *
def feed_data(uuid):
##获取实时cid3
cid3_dict={}
cid3_list=[]
online_feature_change_redis=online_feature_redis.format(uuid).strip()
online_cid3=getRedisValue('89',online_feature_change_redis)
online_cid3_temp=json.loads(online_cid3.get(online_feature_change_redis)) if online_cid3 else 0
cid3_online_real=online_cid3_temp.get('user_latest_cid3_intention_today')
cid3_dict['online_cid3']=cid3_online_real
cid3_temp=online_cid3_temp.get('user_all_intention_cid3_count_with_timestamp_today')
print("---",cid3_temp)
for k,v in cid3_temp.items():
if v.get('count')>=5:
cid3_list.append(k)
if cid3_list:
#print(cid3_list,cid3_online_real)
#cid3_list.remove(cid3_online_real) if cid3_list.index(cid3_online_real) else 0
cid3_dict['offline_cid3']=cid3_list
else:
##获取长期cid3
offline_cid3=getRedisValue('89',offline_feature_redis)
offline_cid3_temp=offline_cid3.get(offline_feature_redis.strip()) if offline_cid3 else []
cid3_offline_real=offline_cid3_temp.get(uuid)
cid3_dict['offline_cid3']=removeRepeat(cid3_offline_real.append(cid3_online_real))
return cid3_dict
def dapan(remove_cid3_list):
dapan_change_sql=concatSql(dapan_sql,**{"cid3":remove_cid3_list,"oper":"not"}) +" order by all_rank limit 100"
dapan_df=execmysl('89',dapan_change_sql)
return dapan_df.drop_duplicates(['cid3'])['cid3'].to_list()[:5]
def main(uuid):
online_offline_result=feed_data(uuid)
print(online_offline_result)
cid3_list=removeRepeat(str(online_offline_result.get('online_cid3')).split()+online_offline_result.get('offline_cid3'))
dapan_temp=dapan(cid3_list)
print(cid3_list)
print(dapan_temp)
if __name__ == '__main__':
#t=dapan([1,2])
#print(t)
#print(feed_data('54ad92ae-d1f1-4dad-a001-38904248fba5'))
print(main('54ad92ae-d1f1-4dad-a001-38904248fba5'))
......@@ -156,7 +156,7 @@ select item_ids from offline_recommend.kdsp_personalize_recall_swing
########################################feed流重排策略#################################################################
online_feature_redis="""
nearline_recommend:real-time:user_feature:{uid_or_gid}
nearline_recommend:real-time:user_feature:{}
"""
offline_feature_redis="""
nearline_recommend:offline:feed_sort_sku_cid3_feature3
......
......@@ -50,6 +50,7 @@ def main(thnum,list_data,func,**kwargs):
if __name__ == '__main__':
flag={"init_data":10}
list_data=[i for i in range(100)]
......
import dingtalkchatbot
import requests
from tools import *
def get_data():
sql="""
SELECT
hour(a.create_date) as hour,
case when POSITION('天创' in a.address)>0 then '天创'
when POSITION('电子' in a.address)>0 then '电子大厦'
when POSITION('虚拟' in a.address)>0 then '折扣劵'
when POSITION('虚拟' in a.address)>0 then '折扣劵'
when LENGTH(a.address)>2 then right(a.address,10)
else '空地址'
end as 'address',
a.amount_paid as 'amount_paid'
-- a.create_date, b.name,a.address,a.amount_paid,a.fee,a.invoice_title,a.phone,a.sn,a.order_type,a.order_status,a.payment_status,a.payment_method
from shop_5000.master_xx_order_202105 a join shop_5000.master_xx_order_item_202105 b on a.id=b.orders
WHERE -- year(create_date)=2022 and month(create_date)=8 and day(create_date)=17
a.create_date>=DATE(NOW()) and a.order_status<3 and a.payment_status>0
"""
return execmysl('onlinetob',sql)
def fill_data():
data_tob=get_data()
temp=[]
# total_temp_feiqi={}
# total_temp_feiqi['ordernos']=data_tob.shape[0]
# total_temp_feiqi['price']=round(data_tob['amount_paid'].sum(),2)
total_temp=[]
total_temp.append(data_tob.shape[0])
total_temp.append(round(data_tob['amount_paid'].sum(),2))
total_temp=[str(i) for i in total_temp]
if data_tob.empty:
temp.append("没有数据")
return temp
df_temp=data_tob.groupby(['hour','address'])['amount_paid'].sum().reset_index()
df_temp['amount_paid']=df_temp['amount_paid'].apply(lambda x:round(x,2))
df_temp=df_temp.astype(str)
for i in df_temp.itertuples():
temp.append("###### "+i.__getattribute__('hour')+','+i.__getattribute__('address')+','+i.__getattribute__('amount_paid'))
return temp,total_temp
def final_msg():
temp,total_temp=fill_data()
template_msg={
"msgtype": "markdown",
"markdown": {
"title": "消费地图当天的小时段订单及收入数据 ",
"text": """### 消费地图当天的小时段订单及收入(总订单数:{0}笔,总收入:{1})
##### 小时段,收货地址,收入
"""
}
}
#print('\n'.join(temp))
template_msg['markdown']['text']=template_msg['markdown']['text'].format(*total_temp)
#print(template_msg['markdown']['text'])
template_msg['markdown']['text']+='\n'.join(temp)
return template_msg
def send(access_token):
template=final_msg()
print(template)
url="https://oapi.dingtalk.com/robot/send?access_token="+str(access_token)
header={"Content-Type": "application/json"}
t=requests.post(url,headers=header,json=template)
return t.json()
if __name__ == '__main__':
#print(send('e3da3eccd05a93f0667ffe1bdd67bb68760e112cbd73c7bcfd2949811ed46c81'))
print(final_msg())
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment