renyupeng 3 年 前
コミット
23f1de76f5
1 ファイル変更104 行追加0 行削除
  1. 104 0
      Apietl/task/huaDongMaterialReport.py

+ 104 - 0
Apietl/task/huaDongMaterialReport.py

@@ -0,0 +1,104 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2021/12/20 11:18 上午
+# @Site    : 
+# @File    : send_material_report_weekly.py.py
+# @Software: PyCharm
+# @contact: renyupeng@c-top.com.cn
+# @Tel 1501435553
+import datetime
+from urllib import parse
+import pandas as pd
+import smtplib
+from email.mime.text import MIMEText
+from email.mime.multipart import MIMEMultipart
+from sqlalchemy import create_engine
+
+
+class send_material_report_weekly:
+    def __init__(self):
+        self.OuterStr = "mysql+pymysql://%s:%s@%s:%d/%s" % (
+            "hcst", parse.quote_plus("hcst@2021"), "111.206.86.186", 3390, "application")
+        self.OuterConn = create_engine(self.OuterStr,
+                                       pool_size=10,
+                                       max_overflow=5,
+                                       pool_timeout=10,
+                                       pool_recycle=3600)
+        self.stat_date = (datetime.date.today() + datetime.timedelta(-1)).strftime("%Y%m%d")
+
+    def handler(self):
+        sql = """ select
+       ifnull(stat_date,0) as '日期',
+ ifnull(video.company_name,report.company_name) as '公司',
+ ifnull(report.project_name,'-') AS '项目',
+ ifnull(report.signature,'-') AS '素材标识',
+ ifnull(video.farst_cost_time,'-') AS '上线时间',
+ ifnull(report.channel_name,'-') AS '渠道',
+ case when video.material_innovate=1 then '非创新素材'
+      when video.material_innovate=2 then '创新素材'
+      else '其它' end AS '是否创新素材',
+ ifnull(sum(report.charge),0)  AS '消耗',
+ ifnull(report.clip_name,'-') AS '剪辑',
+ ifnull(report.shot_name,'-') AS '拍摄',
+ ifnull(report.plan_name,'-') AS '编导',
+ ifnull(report.leader_name,'-') AS '负责人',
+ ifnull(report.video_name,'-') AS '素材名称',
+ ifnull(report.photo_url,'-') AS '素材'
+from
+(select
+        t1.stat_date,
+ t1.account_id,
+ t2.company_name,
+ t1.photo_id,
+ t1.project_name ,
+ t1.signature,
+ t1.channel_name,
+ t1.charge,
+ t1.clip_name,
+ t1.shot_name,
+ t1.plan_name,
+ t1.leader_name,
+ t1.video_name,
+ t1.photo_url
+from application.kuaishou_material_video_report_daily_dw t1
+left join `jeecg-boot`.user_company t2
+on t1.user_id=t2.user_id
+WHERE stat_date between  concat(date_format(date_sub(now(),interval 1 day),'%%Y%%m'),'01') and date_format(date_sub(now(),interval 1 day),'%%Y%%m%%d')
+ AND t2.company_id = '4b10089775c040119e139087517aed88') report
+left  join
+application.app_kuaishou_material_info video
+on report.signature=video.material_id
+group by
+report.signature,stat_date; """.format(stat_date=self.stat_date)
+        print(sql)
+        path = """/data/excel/huaDongMaterial.xls""".format(stat_date=self.stat_date)
+        print(path)
+        pd.read_sql(sql, self.OuterConn).to_excel(path, index=False, engine='openpyxl')
+        my_sender = 'renyupeng@c-top.com.cn'  # 发件人邮箱账号
+        my_pass = 'fcyJKkHUyPo6Zztw'  # 发件人邮箱授权码 / 腾讯企业邮箱请使用登陆密码
+        recipients = ['panyuxia@c-top.com.cn','daipeng@c-top.com.cn']  # 收件人邮箱账号
+        # content = "Please check the attachment. "
+        msg = MIMEMultipart()
+        # [发件人的邮箱昵称、发件人邮箱账号], 昵称随便
+        msg['From'] = my_sender
+        # [收件人邮箱昵称、收件人邮箱账号], 昵称随便
+        msg['To'] = ",".join(recipients)
+        # 邮件的主题,也就是邮件的标题
+        msg['Subject'] = "快手-全量素材周报"
+
+        att1 = MIMEText(
+            open(path, 'rb').read(), 'base64', 'utf-8')
+        att1["Content-Type"] = 'application/octet-stream'
+        att1["Content-Disposition"] = 'attachment; filename="HuaDongMaterial.xls"'
+        msg.attach(att1)
+        server = smtplib.SMTP_SSL("smtp.exmail.qq.com", port=465)
+        server.login(my_sender, my_pass)
+        try:
+            server.sendmail(my_sender, recipients, msg.as_string())
+            print("发送成功")
+        except Exception as e:
+            print("发送失败", e)
+
+
+if __name__ == '__main__':
+    send_material_report_weekly().handler()