zhangyong 8 bulan lalu
induk
melakukan
6fb1a09a82
2 mengubah file dengan 38 tambahan dan 2 penghapusan
  1. 17 0
      common/sql_help.py
  2. 21 2
      data_channel/sph_crawling_data.py

+ 17 - 0
common/sql_help.py

@@ -118,6 +118,12 @@ class sqlCollect():
             return True
         return False
 
+    @classmethod
+    def sph_data_info_count(cls, user, channel):
+        sql = """SELECT count(*) FROM sph_data_info WHERE nick_name = %s and channel = %s """
+        data = MysqlHelper.get_values(sql, (user, channel))
+        return data[0]
+
     """查询是否有视频号数据"""
     @classmethod
     def sph_channel_user_list(cls):
@@ -131,6 +137,17 @@ class sqlCollect():
             return None
         return data
 
+    @classmethod
+    def update_sph_channel_user_status(cls, user):
+        """
+        视频号账号状态改为1 代表已经抓取过
+        """
+        sql = f"""UPDATE sph_channel_user set status = 1 where user_id = '{user}'"""
+        res = AigcMysqlHelper.update_values(
+            sql=sql
+        )
+        return res
+
     """插入视频号信息"""
     @classmethod
     def insert_sph_channel_user(cls, channel, user_id):

+ 21 - 2
data_channel/sph_crawling_data.py

@@ -4,7 +4,7 @@ import time
 
 import requests
 
-from common import Material, Oss, Common
+from common import Material, Oss, Common, Feishu
 from common.sql_help import sqlCollect
 from data_channel.shipinhao import SPH
 
@@ -91,10 +91,27 @@ class SphHistory:
                         fav_count = obj['fav_count']  # 大拇指点赞数
                         sqlCollect.sph_data_info('视频号', objectId, video_url, cover, video_title, str(share_cnt), str(like_cnt), oss_video_key, oss_cover_key, nick_name, user_name, comment_count, fav_count, create_time)
                         Common.logger("sph_crawling").info(f"{nick_name}插入数据成功")
+                sqlCollect.update_sph_channel_user_status(user)
+                Common.logger("sph_crawling").info(f"{user}用户抓取完成")
+                count = sqlCollect.sph_data_info_count(user, "视频号")
+                text = (
+                    f"**{user}抓取完成共抓了{count}条数据**\n"
+                )
+                Feishu.finish_bot(text,
+                                  "https://open.feishu.cn/open-apis/bot/v2/hook/029fa989-9847-4574-8e1b-5c396e665f16",
+                                  "【 视频号历史数据抓取通知 】")
             except Exception as e:
                 Common.logger("sph_crawling").info(f"{user}异常,异常信息{e}")
+                Feishu.finish_bot(e,
+                                  "https://open.feishu.cn/open-apis/bot/v2/hook/029fa989-9847-4574-8e1b-5c396e665f16",
+                                  "【 视频号抓取异常通知 】")
                 continue
 
+
+
+
+
+
     @classmethod
     def get_sph_user(cls):
         data = sqlCollect.sph_channel_user_list()
@@ -110,4 +127,6 @@ class SphHistory:
 
 
 if __name__ == '__main__':
-    SphHistory.sph_data_info()
+    # SphHistory.sph_data_info()
+    count = sqlCollect.sph_data_info_count("郑蓝旗", "视频号")
+    print(count)