|
@@ -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()
|