瀏覽代碼

Merge branch 'master' of http://git.tjyourong.com.cn/renyupeng/hcst_api_etl

zhl 3 年之前
父節點
當前提交
d32dc5931b
共有 2 個文件被更改,包括 108 次插入0 次删除
  1. 53 0
      OuterDataCompareInnerData/Utils/SendEmail.py
  2. 55 0
      OuterDataCompareInnerData/kwai/AudienceReportMonitor.py

+ 53 - 0
OuterDataCompareInnerData/Utils/SendEmail.py

@@ -0,0 +1,53 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2021/11/30 6:02 下午
+# @Site    : 
+# @File    : SendEmail.py
+# @Software: PyCharm
+# @contact: renyupeng@c-top.com.cn
+# @Tel 1501435553
+import smtplib
+import time
+from email.mime.multipart import MIMEMultipart
+from email.mime.text import MIMEText
+
+
+class SendEmail:
+    @staticmethod
+    def mail(content):
+        try:
+            # 邮件的内容
+            my_sender = 'notice@c-top.com.cn'  # 发件人邮箱账号
+            my_pass = 'Hcst@2019'  # 发件人邮箱授权码 / 腾讯企业邮箱请使用登陆密码
+            recipients = ['liyuyi@c-top.com.cn', 'zhaoxian@c-top.com.cn', 'yumengmeng@c-top.com.cn']  # 收件人邮箱账号
+            # content = "Please check the attachment. "
+            msg = MIMEMultipart()
+
+            msg['date'] = time.strftime('%a, %d %b %Y %H:%M:%S %z')
+            msg.attach(MIMEText(content, 'html', 'utf-8'))
+            # att = MIMEText(open(attachment, 'rb').read(), 'base64', 'utf8')
+            # att["Content-Type"] = 'application/octet-stream'
+            # att["Content-Disposition"] = 'attachment; filename="%s"' % attachment
+            # msg.attach(att)
+            # [发件人的邮箱昵称、发件人邮箱账号], 昵称随便
+            msg['From'] = my_sender
+            # [收件人邮箱昵称、收件人邮箱账号], 昵称随便
+            msg['To'] = ",".join(recipients)
+
+            # 邮件的主题,也就是邮件的标题
+            msg['Subject'] = "人群分析报表数据异常监控"
+
+            # 备注:这里使用的是QQ邮箱的服务器, 加入用腾讯企业邮箱作为发件人的话,请将"smtp.qq.com" 修改为 "smtp.exmail.qq.com"
+            # 发件人邮箱中的SMTP服务器,qq端口是465
+            # server = smtplib.SMTP_SSL("smtp.exmail.qq.com", port=465)
+
+            server = smtplib.SMTP_SSL("smtp.exmail.qq.com", port=465)
+            # (发件人邮箱账号、邮箱密码)
+            server.login(my_sender, my_pass)
+            # (发件人邮箱账号、收件人邮箱账号、发送邮件)
+            server.sendmail(my_sender, recipients, msg.as_string())
+
+            server.quit()  # 关闭连接
+            print("邮件发送成功")
+        except Exception as e:
+            print("邮件发送失败: ", e)

+ 55 - 0
OuterDataCompareInnerData/kwai/AudienceReportMonitor.py

@@ -0,0 +1,55 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2021/11/30 6:11 下午
+# @Site    : 
+# @File    : AudienceReportMonitor.py
+# @Software: PyCharm
+# @contact: renyupeng@c-top.com.cn
+# @Tel 1501435553
+import datetime
+import logging
+
+from Apietl.conn.TidbProConn import TidbProConn
+from OuterDataCompareInnerData.Utils.SendEmail import SendEmail
+
+
+class AudienceReportMonitor:
+    def __init__(self):
+        self.conn = TidbProConn.get_connection()
+        self.Audience_list = ['ctop_kuaishou_audience_report_daily_age_material',
+                              'ctop_kuaishou_audience_report_daily_business_material',
+                              'ctop_kuaishou_audience_report_daily_city_material',
+                              'ctop_kuaishou_audience_report_daily_client_material',
+                              'ctop_kuaishou_audience_report_daily_gender_material',
+                              'ctop_kuaishou_audience_report_daily_province_material']
+        self.stat_date = (datetime.date.today() + datetime.timedelta(-1)).strftime("%Y-%m-%d")
+
+    def monitor(self):
+        try:
+            messageList = ''
+            for table in self.Audience_list:
+                try:
+                    sql = """select count(1) from `jeecg-boot`.{table} where stat_date='{stat_date}'""".format(
+                        table=table, stat_date=self.stat_date)
+                    print(sql)
+                    rowCount = TidbProConn.quary(self.conn, sql)[0][0]
+                    if rowCount == 0:
+                        message = """{stat_date}日:{table} 数据量为零 请检查  
+                        """.format(stat_date=self.stat_date,
+                                   table=table)
+
+                        messageList += message
+
+                    else:
+                        logging.info("""{stat_date}日:{table} 数据正常""".format(stat_date=self.stat_date, table=table))
+
+                except Exception as e:
+                    logging.error(e)
+
+            SendEmail.mail(messageList)
+        except Exception as e:
+            logging.error(e)
+
+
+if __name__ == '__main__':
+    AudienceReportMonitor().monitor()