|
@@ -0,0 +1,90 @@
|
|
|
|
+# Author renyupeng
|
|
|
|
+# coding=utf-8
|
|
|
|
+# @Time : 2021/12/20 11:18 上午
|
|
|
|
+# @Site :
|
|
|
|
+# @File : send_material_report_huabei_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_huabei_weekly:
|
|
|
|
+ def __init__(self):
|
|
|
|
+ self.OuterStr = "mysql+pymysql://%s:%s@%s:%d/%s" % (
|
|
|
|
+ "hcst", parse.quote_plus("hcst@2021"), "192.168.0.184", 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(t3.company_name, t2.company_name) AS '公司',
|
|
|
|
+ ifnull(t1.project_name, '-') AS '项目',
|
|
|
|
+ ifnull(t1.signature, '-') AS '素材标识',
|
|
|
|
+ ifnull(t3.media_time, '-') AS '上线时间',
|
|
|
|
+ ifnull(t1.channel_name, '-') AS '渠道',
|
|
|
|
+ round(sum(t1.charge), 3) AS '消耗',
|
|
|
|
+ ifnull(t1.clip_name, '-') AS '剪辑',
|
|
|
|
+ ifnull(t1.shot_name, '-') AS '拍摄',
|
|
|
|
+ ifnull(t1.plan_name, '-') AS '编导',
|
|
|
|
+ ifnull(t1.leader_name, '-') AS '负责人',
|
|
|
|
+ case
|
|
|
|
+ when t3.material_innovate = 1 then '非创新素材'
|
|
|
|
+ when t3.material_innovate = 2 then '创新素材'
|
|
|
|
+ else '其它' end AS '是否创新素材',
|
|
|
|
+ ifnull(t1.video_name, '-') AS '素材名称',
|
|
|
|
+ ifnull(t1.photo_url, '-') AS '链接'
|
|
|
|
+from application.kuaishou_material_video_report_daily_dw t1
|
|
|
|
+ left join (select material_id, media_time, company_name, material_innovate, company_id
|
|
|
|
+ from application.app_kuaishou_material_info) t3
|
|
|
|
+ on t1.signature = t3.material_id
|
|
|
|
+ left join `jeecg-boot`.user_company t2
|
|
|
|
+ on t1.user_id = t2.user_id
|
|
|
|
+ left join `jeecg-boot`.ctop_project pro
|
|
|
|
+on t1.project_id=pro.id
|
|
|
|
+where t1.stat_date between date_format(date_sub({stat_date}, INTERVAL 6 DAY), '%%Y%%m%%d') and {stat_date}
|
|
|
|
+ and pro.agent_code=1
|
|
|
|
+ and t1.signature is not null
|
|
|
|
+group by t1.signature;""".format(stat_date=self.stat_date)
|
|
|
|
+ print(sql)
|
|
|
|
+ path = """/data/excel/material_week_huabei_{stat_date}.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 = ['caiwu@c-top.com.cn', 'videomanager@c-top.com.cn','shiyuke@s-hcst.com'
|
|
|
|
+ ] # 收件人邮箱账号
|
|
|
|
+ # 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="material_report_weekly.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_huabei_weekly().handler()
|