renyupeng 11 달 전
부모
커밋
0ae1286779

+ 90 - 0
Apietl/email/KuaishouMaterialToQingQMonth.py

@@ -0,0 +1,90 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2021/12/20 11:18 上午
+# @Site    :
+# @File    : TouTiaoMaterialToQingQMonth.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 TouTiaoMaterialToQingQMonth:
+    def __init__(self):
+        self.OuterStr = "mysql+pymysql://%s:%s@%s:%d/%s" % (
+            "hcst", parse.quote_plus("hcst@2024"), "192.168.0.101", 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 a.project_name as `项目名称`,
+       signature      as `md5`,
+       video_name     as `视频名称`,
+       photo_url      as `视频链接`,
+       a.leader_name  as `设计负责人`,
+       a.shot_name    as `拍摄`,
+       a.clip_name    as `剪辑`,
+       a.plan_name    as `编导`,
+       charge         as `消耗`
+from (select project_name,
+             project_id,
+             signature,
+             video_name,
+             photo_url,
+             leader_name,
+             shot_name,
+             clip_name,
+             plan_name,
+             sum(charge) as charge
+      from application.kuaishou_material_video_report_daily_dw
+WHERE stat_date >= date_format(date_sub(NOW() , INTERVAL 1 MONTH), '%%Y%%m01')
+  AND stat_date <=  date_format(date_sub(DATE_FORMAT(NOW() , '%%Y-%%m-01'),interval 1 day),'%%Y%%m%%d')
+      group by signature, project_id) a
+         left join application.app_kuaishou_material_info b
+                   on a.signature = b.material_id
+where b.tag_id = 60155
+
+        """
+        print(sql)
+        path = """/data/excel/快手真人素材_{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 = ['keqingqing@c-top.com.cn', 'yumengmeng@c-top.com.cn']  # 收件人邮箱账号
+        # content = "Please check the attachment. "
+        msg = MIMEMultipart()
+        # [发件人的邮箱昵称、发件人邮箱账号], 昵称随便
+        msg['From'] = my_sender
+        # [收件人邮箱昵称、收件人邮箱账号], 昵称随便
+        msg['To'] = ",".join(recipients)
+        # 邮件的主题,也就是邮件的标题
+        msg['Subject'] = "快手真人素材_{stat_date}".format(stat_date=self.stat_date)
+
+        att1 = MIMEText(
+            open(path, 'rb').read(), 'base64', 'utf-8')
+        att1["Content-Type"] = 'application/octet-stream'
+        att1["Content-Disposition"] = 'attachment; filename="kuaishou_month.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__':
+    TouTiaoMaterialToQingQMonth().handler()

+ 90 - 0
Apietl/email/KuaishouMaterialToQingQWeek.py

@@ -0,0 +1,90 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2021/12/20 11:18 上午
+# @Site    :
+# @File    : TouTiaoMaterialToQingQWeek.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 TouTiaoMaterialToQingQWeek:
+    def __init__(self):
+        self.OuterStr = "mysql+pymysql://%s:%s@%s:%d/%s" % (
+            "hcst", parse.quote_plus("hcst@2024"), "192.168.0.101", 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 a.project_name as `项目名称`,
+       signature      as `md5`,
+       video_name     as `视频名称`,
+       photo_url      as `视频链接`,
+       a.leader_name  as `设计负责人`,
+       a.shot_name    as `拍摄`,
+       a.clip_name    as `剪辑`,
+       a.plan_name    as `编导`,
+       charge         as `消耗`
+from (select project_name,
+             project_id,
+             signature,
+             video_name,
+             photo_url,
+             leader_name,
+             shot_name,
+             clip_name,
+             plan_name,
+             sum(charge) as charge
+      from application.kuaishou_material_video_report_daily_dw
+WHERE stat_date >= date_format(date_sub({stat_date}, INTERVAL 6 DAY), '%%Y%%m%%d') 
+and stat_date<={stat_date}
+      group by signature, project_id) a
+         left join application.app_kuaishou_material_info b
+                   on a.signature = b.material_id
+where b.tag_id = 60155
+
+        """
+        print(sql)
+        path = """/data/excel/快手真人素材_{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 = ['keqingqing@c-top.com.cn', 'yumengmeng@c-top.com.cn']  # 收件人邮箱账号
+        # content = "Please check the attachment. "
+        msg = MIMEMultipart()
+        # [发件人的邮箱昵称、发件人邮箱账号], 昵称随便
+        msg['From'] = my_sender
+        # [收件人邮箱昵称、收件人邮箱账号], 昵称随便
+        msg['To'] = ",".join(recipients)
+        # 邮件的主题,也就是邮件的标题
+        msg['Subject'] = "快手真人素材_{stat_date}".format(stat_date=self.stat_date)
+
+        att1 = MIMEText(
+            open(path, 'rb').read(), 'base64', 'utf-8')
+        att1["Content-Type"] = 'application/octet-stream'
+        att1["Content-Disposition"] = 'attachment; filename="kuaishou_Week.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__':
+    TouTiaoMaterialToQingQWeek().handler()

+ 90 - 0
Apietl/email/TouTiaoMaterialToQingQMonth.py

@@ -0,0 +1,90 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2021/12/20 11:18 上午
+# @Site    :
+# @File    : TouTiaoMaterialToQingQMonth.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 TouTiaoMaterialToQingQMonth:
+    def __init__(self):
+        self.OuterStr = "mysql+pymysql://%s:%s@%s:%d/%s" % (
+            "hcst", parse.quote_plus("hcst@2024"), "192.168.0.101", 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 a.project_name as `项目名称`,
+       signature      as `md5`,
+       video_name     as `视频名称`,
+       a.video_url      as `视频链接`,
+       a.leader_name  as `设计负责人`,
+       a.shot_name    as `拍摄`,
+       a.clip_name    as `剪辑`,
+       a.plan_name    as `编导`,
+       charge         as `消耗`
+from (select project_name,
+             project_id,
+             signature,
+             video_name,
+             video_url,
+             leader_name,
+             shot_name,
+             clip_name,
+             plan_name,
+             sum(cost) as charge
+      from application.bytedance_material_video_report_daily_dw
+WHERE stat_datetime >= date_format(date_sub(NOW() , INTERVAL 1 MONTH), '%%Y%%m01')
+  AND stat_datetime <=  date_format(date_sub(DATE_FORMAT(NOW() , '%%Y-%%m-01'),interval 1 day),'%%Y%%m%%d')
+      group by signature, project_id) a
+         left join application.app_bytedance_material_info b
+                   on a.signature = b.material_id
+where b.tag_id = 60155
+
+        """
+        print(sql)
+        path = """/data/excel/头条真人素材_{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 = ['keqingqing@c-top.com.cn', 'yumengmeng@c-top.com.cn']  # 收件人邮箱账号
+        # content = "Please check the attachment. "
+        msg = MIMEMultipart()
+        # [发件人的邮箱昵称、发件人邮箱账号], 昵称随便
+        msg['From'] = my_sender
+        # [收件人邮箱昵称、收件人邮箱账号], 昵称随便
+        msg['To'] = ",".join(recipients)
+        # 邮件的主题,也就是邮件的标题
+        msg['Subject'] = "头条真人素材_{stat_date}".format(stat_date=self.stat_date)
+
+        att1 = MIMEText(
+            open(path, 'rb').read(), 'base64', 'utf-8')
+        att1["Content-Type"] = 'application/octet-stream'
+        att1["Content-Disposition"] = 'attachment; filename="bytedance_month.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__':
+    TouTiaoMaterialToQingQMonth().handler()

+ 90 - 0
Apietl/email/TouTiaoMaterialToQingQWeek.py

@@ -0,0 +1,90 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2021/12/20 11:18 上午
+# @Site    :
+# @File    : TouTiaoMaterialToQingQWeek.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 TouTiaoMaterialToQingQWeek:
+    def __init__(self):
+        self.OuterStr = "mysql+pymysql://%s:%s@%s:%d/%s" % (
+            "hcst", parse.quote_plus("hcst@2024"), "192.168.0.101", 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 a.project_name as `项目名称`,
+       signature      as `md5`,
+       video_name     as `视频名称`,
+       a.video_url      as `视频链接`,
+       a.leader_name  as `设计负责人`,
+       a.shot_name    as `拍摄`,
+       a.clip_name    as `剪辑`,
+       a.plan_name    as `编导`,
+       charge         as `消耗`
+from (select project_name,
+             project_id,
+             signature,
+             video_name,
+             video_url,
+             leader_name,
+             shot_name,
+             clip_name,
+             plan_name,
+             sum(cost) as charge
+      from application.bytedance_material_video_report_daily_dw
+WHERE stat_datetime >= date_format(date_sub({stat_date}, INTERVAL 6 DAY), '%%Y%%m%%d')
+        and stat_datetime <= {stat_date}
+      group by signature, project_id) a
+         left join application.app_bytedance_material_info b
+                   on a.signature = b.material_id
+where b.tag_id = 60155
+
+        """
+        print(sql)
+        path = """/data/excel/头条真人素材_{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 = ['keqingqing@c-top.com.cn', 'yumengmeng@c-top.com.cn']  # 收件人邮箱账号
+        # content = "Please check the attachment. "
+        msg = MIMEMultipart()
+        # [发件人的邮箱昵称、发件人邮箱账号], 昵称随便
+        msg['From'] = my_sender
+        # [收件人邮箱昵称、收件人邮箱账号], 昵称随便
+        msg['To'] = ",".join(recipients)
+        # 邮件的主题,也就是邮件的标题
+        msg['Subject'] = "头条真人素材_{stat_date}".format(stat_date=self.stat_date)
+
+        att1 = MIMEText(
+            open(path, 'rb').read(), 'base64', 'utf-8')
+        att1["Content-Type"] = 'application/octet-stream'
+        att1["Content-Disposition"] = 'attachment; filename="bytedance_Week.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__':
+    TouTiaoMaterialToQingQWeek().handler()