Commit f920de06 authored by 赵威's avatar 赵威

try send msg

parent 52807b5e
...@@ -9,7 +9,7 @@ from pyspark import SparkConf ...@@ -9,7 +9,7 @@ from pyspark import SparkConf
from pyspark.sql import SparkSession from pyspark.sql import SparkSession
from tool import (get_doris_prod, get_redis_client, get_tag3_user_log, get_tag3_user_order_log, get_user_portrait_tag3_with_score, from tool import (get_doris_prod, get_redis_client, get_tag3_user_log, get_tag3_user_order_log, get_user_portrait_tag3_with_score,
send_email, write_user_portrait) send_email, write_user_portrait, send_msg_to_dingtalk)
# [{'激光': 1.949194898204873}, {'手术': 1.949194898204873}, {'手术': 1.949194898204873}, {'手术': 1.949194898204873, '植发际线': 7.1}] # [{'激光': 1.949194898204873}, {'手术': 1.949194898204873}, {'手术': 1.949194898204873}, {'手术': 1.949194898204873, '植发际线': 7.1}]
...@@ -379,7 +379,9 @@ if __name__ == "__main__": ...@@ -379,7 +379,9 @@ if __name__ == "__main__":
# cl_id = "867617044159377" # cl_id = "867617044159377"
# print(update_tag3_user_portrait(cl_id)) # print(update_tag3_user_portrait(cl_id))
consume_kafka() # consume_kafka()
send_msg_to_dingtalk("test")
end = datetime.datetime.now() end = datetime.datetime.now()
print(end - start) print(end - start)
print("done") print("done")
...@@ -2,11 +2,15 @@ ...@@ -2,11 +2,15 @@
from __future__ import absolute_import, division, print_function from __future__ import absolute_import, division, print_function
import base64
import datetime import datetime
import hashlib
import hmac
import json import json
import smtplib import smtplib
import time import time
import traceback import traceback
import urllib
from email.mime.application import MIMEApplication from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText from email.mime.text import MIMEText
...@@ -16,6 +20,31 @@ import numpy as np ...@@ -16,6 +20,31 @@ import numpy as np
import pandas as pd import pandas as pd
import pymysql import pymysql
import redis import redis
import requests
def send_msg_to_dingtalk(msg, mobiles=[]):
try:
secret = "SECca234e669d42b8ee9d6aa73817457785be7556ee3b4c5249c31d2c3422732511"
timestamp = str(round(time.time() * 1000))
secret_enc = secret.encode("utf-8")
string_to_sign = "{}\n{}".format(timestamp, secret)
string_to_sign_enc = string_to_sign.encode("utf-8")
hmac_code = hmac.new(secret_enc, string_to_sign_enc, digestmod=hashlib.sha256).digest()
sign = urllib.parse.quote_plus(base64.b64encode(hmac_code))
headers = {"Content-Type": "application/json"}
data = {"msgtype": "text", "text": {"content": msg}}
if mobiles:
data = {"msgtype": "text", "text": {"content": msg}, "at": {"atMobiles": mobiles, "isAtAll": False}}
json_data = json.dumps(data)
url = "https://oapi.dingtalk.com/robot/send?access_token=5812943d740c3072c7cee3f32226e05caa5d3b7887592c4c11ae8004a6e2c6a4&sign={}&timestamp={}".format(
sign, timestamp)
response = requests.post(url=url, data=json_data, headers=headers)
return str(response.status_code) + " " + str(response.content.decode("utf-8"))
except Exception as e:
print(e)
return str(e)
def send_email(app, id, e): def send_email(app, id, e):
...@@ -444,9 +473,7 @@ def get_tag3_user_log(cl_id): ...@@ -444,9 +473,7 @@ def get_tag3_user_log(cl_id):
# select log_time, score_type, business_tags, event_cn from kafka_tag3_log where cl_id = '867617044159377' and event_cn in ('支付订单', '验证订单'); # select log_time, score_type, business_tags, event_cn from kafka_tag3_log where cl_id = '867617044159377' and event_cn in ('支付订单', '验证订单');
def get_tag3_user_order_log(cl_id): def get_tag3_user_order_log(cl_id):
columns = [ columns = ["log_time", "score_type", "business_tags", "event_cn"]
"log_time", "score_type", "business_tags", "event_cn"
]
try: try:
sql = """select log_time, score_type, business_tags, event_cn sql = """select log_time, score_type, business_tags, event_cn
from kafka_tag3_log from kafka_tag3_log
......
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