Selaa lähdekoodia

实现需求 20220607

wangkun 2 vuotta sitten
vanhempi
commit
c0f2547e3b
9 muutettua tiedostoa jossa 339 lisäystä ja 705 poistoa
  1. 90 27
      main/demo.py
  2. 0 165
      main/download.py
  3. 7 1
      main/feishu_lib.py
  4. 0 334
      main/get_feeds.py
  5. 66 56
      main/hour_list.py
  6. 158 33
      main/person_list.py
  7. 3 3
      main/publish.py
  8. 0 83
      main/run.py
  9. 15 3
      main/run_person_list.py

+ 90 - 27
main/demo.py

@@ -3,34 +3,97 @@
 # @Time: 2022/5/16
 import datetime
 import time
+from datetime import timedelta
+import requests
+import urllib3
 
-# spreadsheetToken = ["shtcngRPoDYAi24x52j2nDuHMih",
-#                     "shtcnp4SaJt37q6OOOrYzPMjQkg",
-#                     "shtcn5YSWg91JfVGzj0SFZIRRPh",
-#                     "shtcnYxiyQ1wLklo1W5Kdqc9cGh"]
-# print(spreadsheetToken[0])
+proxies = {"http": None, "https": None}
 
-# time1 = datetime.datetime.now().strftime("%Y-%m-%d")
-# time2 = datetime.datetime.now().strftime("%Y")
-# time3 = datetime.datetime.now().strftime("%m")
-# time4 = datetime.datetime.now().strftime("%d")
-# print(type(time1))
-# print(type(time2))
-# print(time3)
-# print(time4)
-# yesterday = (datetime.date.today() + datetime.timedelta(days=-2)).strftime("%Y-%m-%d")
-# update_hour = datetime.datetime.now().strftime("%Y-%m-%d")
-# print(type(yesterday))
-# print(yesterday)
-# print(type(update_hour))
-# print(update_hour)
-# print(int("-1"))
-from main.feishu_lib import Feishu
 
-v_upload_time = Feishu.get_range_value("logs", "xiaoniangao", "ba0da4", "F3:F3")[0]
-print(v_upload_time)
-print(type(v_upload_time))
+class Demo:
+    # 查询视频详情的各项数据
+    @classmethod
+    def video_detail_info(cls, user_id, user_mid, video_id):
+        url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id"
+        headers = {
+            "x-b3-traceid": "bd267349bf41b",
+            "X-Token-Id": "86f6d7cc2b2b6870004df5d16c82aaf3-1185665701",
+            "uid": "8fde3c6c-c070-4379-bfc4-15c7e85139c9",
+            "content-type": "application/json",
+            "Accept-Encoding": "gzip,compress,br,deflate",
+            "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
+                          ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
+                          'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
+            "Referer": "https://servicewechat.com/wxd7911e4c177690e4/617/page-frame.html"
+        }
+        data = {
+            "play_src": "1",
+            "profile_id": int(user_id),
+            "profile_mid": int(user_mid),
+            "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/"
+                  "!400x400r/crop/400x400/interlace/1/format/jpg",
+            "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail"
+                    "/!80x80r/crop/80x80/interlace/1/format/jpg",
+            "share_width": 625,
+            "share_height": 500,
+            "no_comments": True,
+            "no_follow": True,
+            "vid": video_id,
+            "hot_l1_comment": True,
+            "token": "90747742180aeb22c0fe3a3c6a38f3d9",
+            "uid": "8fde3c6c-c070-4379-bfc4-15c7e85139c9",
+            "proj": "ma",
+            "wx_ver": "8.0.20",
+            "code_ver": "3.62.0",
+            "log_common_params": {
+                "e": [{
+                    "data": {
+                        "page": "dynamicSharePage"
+                    }
+                }],
+                "ext": {
+                    "brand": "iPhone",
+                    "device": "iPhone 11",
+                    "os": "iOS 14.7.1",
+                    "weixinver": "8.0.20",
+                    "srcver": "2.24.3",
+                    "net": "wifi",
+                    "scene": "1089"
+                },
+                "pj": "1",
+                "pf": "2",
+                "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29"
+            }
+        }
+        try:
+            urllib3.disable_warnings()
+            r = requests.post(headers=headers, url=url, json=data, proxies=proxies, verify=False)
+            video_title = r.json()["data"]["title"]
+            video_id = r.json()["data"]["vid"]
+            video_play_cnt = r.json()["data"]["play_pv"]
+            video_duration = int(r.json()["data"]["du"])/1000
+            video_url = r.json()["data"]["v_url"]
+            video_send_time = r.json()["data"]["t"]
+            print(f"video_title:{video_title}")
+            print(f"video_id:{video_id}")
+            print(f"video_play_cnt:{video_play_cnt}")
+            print(f"video_duration:{video_duration}")
+            print(f'video_send_time:{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(video_send_time)/1000))}')
+            print(f"video_url:{video_url}")
+        except Exception as e:
+            print(e)
 
-# v_time = int(time.mktime(time.strptime(v_upload_time, "%Y-%m-%d %H:%M:%S")))
-# print(v_time)
-# print(type(v_time))
+    # 时间
+    @classmethod
+    def times(cls):
+        before_yesterday = (datetime.date.today() + timedelta(days=-2)).strftime("%Y/%m/%d %H:%M:%S")
+        before_yesterday = time.strptime(before_yesterday, "%Y/%m/%d %H:%M:%S")
+        before_yesterday = int(time.mktime(before_yesterday))
+        print(before_yesterday)
+        print(type(before_yesterday))
+
+
+if __name__ == "__main__":
+    demo = Demo()
+    # demo.video_detail_info("44373353", "1161593420", "4572205769")
+    demo.times()

+ 0 - 165
main/download.py

@@ -1,165 +0,0 @@
-# -*- coding: utf-8 -*-
-# @Author: wangkun
-# @Time: 2022/5/12
-import time
-
-from main.common import Common
-from main.feishu_lib import Feishu
-from main.publish import Publish
-
-
-class Download:
-    # 已下载视频列表
-    download_video_list = []
-
-    # 下载规则
-    @staticmethod
-    def download_rule(d_duration, d_width, d_height, d_play_cnt, d_like_cnt, d_share_cnt):
-        """
-        下载视频的基本规则
-        :param d_duration: 时长
-        :param d_width: 宽
-        :param d_height: 高
-        :param d_play_cnt: 播放量
-        :param d_like_cnt: 点赞量
-        :param d_share_cnt: 分享量
-        :return: 满足规则,返回 True;反之,返回 False
-        """
-        if 600 >= int(float(d_duration)) >= 60:
-            if int(d_width) >= 0 or int(d_height) >= 0:
-                if int(d_play_cnt) >= 10000:
-                    if int(d_like_cnt) >= 0:
-                        if int(d_share_cnt) >= 0:
-                            return True
-                        else:
-                            return False
-                    else:
-                        return False
-                else:
-                    return False
-            return False
-        return False
-
-    # 下载 / 上传 视频
-    @classmethod
-    def download(cls, env):
-        """
-        1.从云文档中取视频:https://w42nne6hzg.feishu.cn/sheets/shtcngRPoDYAi24x52j2nDuHMih?sheet=S714lO
-        2.满足规则,则下载及上传
-        :param env: 测试环境:dev ; 正式环境:prod
-        """
-        try:
-            if len(Feishu.get_values_batch("S714lO")) == 1:
-                pass
-            else:
-                for i in range(len(Feishu.get_values_batch("S714lO"))):
-                    time.sleep(1)
-                    try:
-                        download_video_id = Feishu.get_values_batch("S714lO")[i + 1][1]
-                        download_video_play_cnt = Feishu.get_values_batch("S714lO")[i + 1][2]
-                        download_video_title = Feishu.get_values_batch("S714lO")[i + 1][3]
-                        download_video_duration = Feishu.get_values_batch("S714lO")[i + 1][4]
-                        download_video_comment_cnt = Feishu.get_values_batch("S714lO")[i + 1][5]
-                        download_video_like_cnt = Feishu.get_values_batch("S714lO")[i + 1][6]
-                        download_video_share_cnt = Feishu.get_values_batch("S714lO")[i + 1][7]
-                        download_video_resolution = Feishu.get_values_batch("S714lO")[i + 1][8]
-                        download_video_width = download_video_resolution.split("*")[0]
-                        download_video_height = download_video_resolution.split("*")[-1]
-                        download_video_send_time = Feishu.get_values_batch("S714lO")[i + 1][9]
-                        download_user_name = Feishu.get_values_batch("S714lO")[i + 1][10]
-                        download_head_url = Feishu.get_values_batch("S714lO")[i + 1][11]
-                        download_cover_url = Feishu.get_values_batch("S714lO")[i + 1][12]
-                        download_video_url = Feishu.get_values_batch("S714lO")[i + 1][13]
-                        download_video_session = Feishu.get_values_batch("S714lO")[i + 1][14]
-
-                        if int(time.time()) - int(download_video_send_time)/1000 > 259200:
-                            Common.logger().info("发布时间大于3天,删除该视频:{}", download_video_title)
-                            # 删除行或列,可选 ROWS、COLUMNS
-                            Feishu.dimension_range("S714lO", "ROWS", i + 2, i + 2)
-                        # 去重
-                        elif download_video_id in [j for m in Feishu.get_values_batch("onyBDH") for j in m]:
-                            Common.logger().info("视频已下载,删除该视频:{}", download_video_title)
-                            # 删除行或列,可选 ROWS、COLUMNS
-                            Feishu.dimension_range("S714lO", "ROWS", i + 2, i + 2)
-                        # 判断是否满足下载规则
-                        elif cls.download_rule(
-                                download_video_duration,
-                                download_video_width,
-                                download_video_height,
-                                download_video_play_cnt,
-                                download_video_like_cnt,
-                                download_video_share_cnt) is False:
-                            Common.logger().info("不满足下载规则,删除该视频:{}", download_video_title)
-                            # 删除行或列,可选 ROWS、COLUMNS
-                            Feishu.dimension_range("S714lO", "ROWS", i + 2, i + 2)
-                        else:
-                            Common.logger().info("开始下载视频:{}".format(download_video_title))
-                            # 下载封面
-                            Common.download_method(text="cover", d_name=download_video_title, d_url=download_cover_url)
-                            # 下载视频
-                            Common.download_method(text="video", d_name=download_video_title, d_url=download_video_url)
-                            # # 保存视频信息至 "./videos/{download_video_title}/info.txt"
-                            # with open("./videos/" + download_video_title + "/"
-                            #           + "info.txt", "a", encoding="UTF-8") as f_a:
-                            #     f_a.write(str(download_video_id) + "\n" +
-                            #               str(download_video_title) + "\n" +
-                            #               str(download_video_duration) + "\n" +
-                            #               str(download_video_play_cnt) + "\n" +
-                            #               str(download_video_comment_cnt) + "\n" +
-                            #               str(download_video_like_cnt) + "\n" +
-                            #               str(download_video_share_cnt) + "\n" +
-                            #               str(download_video_resolution) + "\n" +
-                            #               str(download_video_send_time) + "\n" +
-                            #               str(download_user_name) + "\n" +
-                            #               str(download_head_url) + "\n" +
-                            #               str(download_video_url) + "\n" +
-                            #               str(download_cover_url) + "\n" +
-                            #               str(download_video_session))
-                            # Common.logger().info("==========视频信息已保存至info.txt==========")
-
-                            # 添加视频 ID 到 list,用于统计当次下载总数
-                            cls.download_video_list.append(download_video_id)
-
-                            # # 上传视频
-                            # Common.logger().info("开始上传视频:{}".format(download_video_title))
-                            # Publish.upload_and_publish(env, "play")
-
-                            # 保存视频 ID 到云文档:https://w42nne6hzg.feishu.cn/sheets/shtcngRPoDYAi24x52j2nDuHMih?sheet=onyBDH
-                            Common.logger().info("保存视频ID至云文档:{}", download_video_title)
-                            # 视频ID工作表,插入首行
-                            Feishu.insert_columns("onyBDH", "ROWS", 1, 2)
-                            # 视频ID工作表,首行写入数据
-                            upload_time = int(time.time())
-                            time.sleep(1)
-                            Feishu.update_values("onyBDH",
-                                                 str(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(upload_time))),
-                                                 str(download_video_id),
-                                                 str(download_video_play_cnt),
-                                                 str(download_video_title),
-                                                 str(download_video_duration),
-                                                 str(download_video_comment_cnt),
-                                                 str(download_video_like_cnt),
-                                                 str(download_video_share_cnt),
-                                                 str(download_video_resolution),
-                                                 str(time.strftime("%Y-%m-%d %H:%M:%S",
-                                                                   time.localtime(
-                                                                       int(download_video_send_time)/1000))),
-                                                 str(download_user_name),
-                                                 str(download_head_url),
-                                                 str(download_cover_url),
-                                                 str(download_video_url),
-                                                 str(download_video_session))
-
-                            # 从云文档删除该视频信息:https://w42nne6hzg.feishu.cn/sheets/shtcngRPoDYAi24x52j2nDuHMih?sheet=S714lO
-                            Common.logger().info("从云文档删除该视频信息:{}", download_video_title)
-                            # 删除行或列,可选 ROWS、COLUMNS
-                            Feishu.dimension_range("S714lO", "ROWS", i + 2, i + 2)
-
-                    except Exception as e:
-                        Common.logger().error("视频 info 异常,删除该视频信息:{}", e)
-                        # 删除行或列,可选 ROWS、COLUMNS
-                        Feishu.dimension_range("S714lO", "ROWS", i + 2, i + 2)
-                    cls.download("prod")
-
-        except Exception as e:
-            Common.logger().error("获取视频数据异常:{}", e)

+ 7 - 1
main/feishu_lib.py

@@ -332,6 +332,12 @@ class Feishu:
 if __name__ == "__main__":
     feishu = Feishu()
 
+    print(feishu.get_range_value("person-log", "xiaoniangao", "dzcWHw", "B3:B3")[0])
+    print(feishu.get_range_value("person-log", "xiaoniangao", "dzcWHw", "B4:B4")[0])
+    print(feishu.get_range_value("person-log", "xiaoniangao", "dzcWHw", "C5:C5")[0][0]["link"])
+    print(feishu.get_range_value("person-log", "xiaoniangao", "dzcWHw", "B6:B6")[0])
+    print(feishu.get_range_value("person-log", "xiaoniangao", "dzcWHw", "B7:B7")[0])
+
     # # 获取飞书api token
     # feishu.get_token()
     # 获取表格元数据
@@ -350,7 +356,7 @@ if __name__ == "__main__":
     # print(int(feishu.get_range_value("xiaoniangao", "ba0da4", "G6:G6")[0].split(" ")[-1].split(":")[0]))
     # print(feishu.get_range_value("xiaoniangao", "ba0da4", "G6:G6")[0].split(" ")[0])
 
-    feishu.update_values("logs", "xiaoniangao", "ba0da4", "H4:H4", [["2022-05-18 21:14:27"]])
+    # feishu.update_values("logs", "xiaoniangao", "ba0da4", "H4:H4", [["2022-05-18 21:14:27"]])
 
     # 看一看+工作表,插入首行
     # print(feishu.insert_columns("k2rKkv", "COLUMNS", 6, 9))

+ 0 - 334
main/get_feeds.py

@@ -1,334 +0,0 @@
-# -*- coding: utf-8 -*-
-# @Author: wangkun
-# @Time: 2022/5/11
-import os
-import sys
-import time
-import requests
-import urllib3
-sys.path.append(os.getcwd())
-from main.common import Common
-from main.feishu_lib import Feishu
-
-proxies = {"http": None, "https": None}
-
-
-# 敏感词库
-def sensitive_words():
-    # 敏感词库列表
-    word_list = []
-    # 从云文档读取所有敏感词,添加到词库列表
-    lists = Feishu.get_values_batch("QQrfQ7")
-    for i in lists:
-        for j in i:
-            # 过滤空的单元格内容
-            if j is None:
-                pass
-            else:
-                word_list.append(j)
-    return word_list
-
-
-# 获取列表数据
-def get_feeds():
-    url = "https://kapi.xiaoniangao.cn/trends/get_recommend_trends"
-    headers = {
-        "x-b3-traceid": "17e832d1a42807",
-        "X-Token-Id": "4bff41a8c35f054fa915dc71b937ac70-1145266232",
-        "uid": "uid	250e6514-fd83-446c-a880-e274c7f17bce",
-        "content-type": "application/json",
-        "Accept-Encoding": "gzip,compress,br,deflate",
-        "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
-                      ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
-                      'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
-        "Referer": "https://servicewechat.com/wxd7911e4c177690e4/616/page-frame.html"
-    }
-    data = {
-        "log_params": {
-            "page": "discover_rec",
-            "common": {
-                "brand": "iPhone",
-                "device": "iPhone 11",
-                "os": "iOS 14.7.1",
-                "weixinver": "8.0.20",
-                "srcver": "2.24.2",
-                "net": "none"
-            }
-        },
-        "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/!750x500r/crop/750x500/interlace/1/format/jpg",
-        "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail/!80x80r/crop/80x80/interlace/1/format/jpg",
-        "share_width": 625,
-        "share_height": 500,
-        "ext": {
-            "fmid": 0,
-            "items": {
-                "15408539": {
-                    "type": "rec",
-                    "pd": 328.31,
-                    "ct": 1649248176494,
-                    "ut": 1649248509951
-                },
-                "36776414": {
-                    "type": "nice",
-                    "pd": 33.501,
-                    "ct": 1648893152909,
-                    "ut": 1648893189506
-                },
-                "39467179": {
-                    "type": "rec",
-                    "pd": 49.343,
-                    "ct": 1649247992882,
-                    "ut": 1649248043566
-                },
-                "40347940": {
-                    "type": "rec",
-                    "pd": 3.681,
-                    "ct": 1649248080042,
-                    "ut": 1649248084907
-                },
-                "42285576": {
-                    "type": "rec",
-                    "pd": 0.66,
-                    "ct": 1649248087683,
-                    "ut": 1649248089445
-                },
-                "42300668": {
-                    "type": "rec",
-                    "pd": 13.5,
-                    "ct": 1649248059189,
-                    "ut": 1649248074218
-                },
-                "42306954": {
-                    "type": "rec",
-                    "pd": 4.918,
-                    "ct": 1649248091376,
-                    "ut": 1649248097663
-                },
-                "42328061": {
-                    "type": "reflux",
-                    "pd": 4.001,
-                    "ct": 1649248510102,
-                    "ut": 1649248516806
-                },
-                "90004473051301": {
-                    "type": "my",
-                    "pd": 0,
-                    "ct": 1649247069688,
-                    "ut": 1649247069688
-                },
-                "80004478730156": {
-                    "type": "other",
-                    "pd": 153,
-                    "ct": 1649247850322,
-                    "ut": 1649247919263
-                }
-            }
-        },
-        "app": "xng",
-        "rec_scene": "discover_rec",
-        "log_common_params": {
-            "e": [{
-                "data": {
-                    "page": "discoverIndexPage",
-                    "topic": "recommend"
-                },
-                "ab": {}
-            }],
-            "ext": {
-                "brand": "iPhone",
-                "device": "iPhone 11",
-                "os": "iOS 14.7.1",
-                "weixinver": "8.0.20",
-                "srcver": "2.24.2",
-                "net": "wifi",
-                "scene": "1089"
-            },
-            "pj": "1",
-            "pf": "2",
-            "session_id": "cd944ac9-f35f-47ac-9aa4-2f354afec0e2"
-        },
-        "refresh": False,
-        "token": "132645b6e2b996aaad1713a557456816",
-        "uid": "250e6514-fd83-446c-a880-e274c7f17bce",
-        "proj": "ma",
-        "wx_ver": "8.0.20",
-        "code_ver": "3.61.0"
-    }
-
-    try:
-        urllib3.disable_warnings()
-        r = requests.post(url=url, headers=headers, json=data, proxies=proxies, verify=False)
-        if "data" not in r.json():
-            Common.logger().warning("获取视频feeds错误:{}", r.text)
-        elif "list" not in r.json()["data"]:
-            Common.logger().warning("获取视频feeds无数据,休眠10s:{}", r.json()["data"])
-        else:
-            # 视频列表数据
-            feeds = r.json()["data"]["list"]
-            for i in range(len(feeds)):
-                # 标题
-                if "title" in feeds[i]:
-                    video_title = feeds[i]["title"].strip().replace("\n", "")\
-                        .replace("/", "").replace("\r", "").replace("#", "")\
-                        .replace(".", "。").replace("\\", "").replace("&NBSP", "")\
-                        .replace(":", "").replace("*", "").replace("?", "") \
-                        .replace("?", "").replace('"', "").replace("<", "") \
-                        .replace(">", "").replace("|", "").replace(" ", "")
-                    Common.logger().info("标题:{}", video_title)
-                else:
-                    video_title = ""
-                    Common.logger().info("当前视频无标题:{}", video_title)
-
-                # 视频 ID
-                if "vid" in feeds[i]:
-                    video_id = feeds[i]["vid"]
-                    Common.logger().info("视频ID:{}", video_id)
-                else:
-                    video_id = ""
-                    Common.logger().info("当前视频无ID:{}", video_id)
-
-                # 播放量
-                if "play_pv" in feeds[i]:
-                    video_play_cnt = feeds[i]["play_pv"]
-                    Common.logger().info("视频播放量:{}", video_play_cnt)
-                else:
-                    video_play_cnt = ""
-                    Common.logger().info("当前视频无播放量:{}", video_play_cnt)
-
-                # 点赞量
-                if "favor" in feeds[i]:
-                    video_like_cnt = feeds[i]["favor"]["total"]
-                    Common.logger().info("视频点赞量:{}", video_like_cnt)
-                else:
-                    video_like_cnt = ""
-                    Common.logger().info("当前视频无点赞量:{}", video_like_cnt)
-
-                # 分享量
-                if "share" in feeds[i]:
-                    video_share_cnt = feeds[i]["share"]
-                    Common.logger().info("视频分享量:{}", video_share_cnt)
-                else:
-                    video_share_cnt = ""
-                    Common.logger().info("当前视频无分享量:{}", video_share_cnt)
-
-                # 评论量
-                if "comment_count" in feeds[i]:
-                    video_comment_cnt = feeds[i]["comment_count"]
-                    Common.logger().info("视频评论数:{}", video_comment_cnt)
-                else:
-                    video_comment_cnt = ""
-                    Common.logger().info("当前视频无评论:{}", video_comment_cnt)
-
-                # 时长
-                if "du" in feeds[i]:
-                    video_duration = int(feeds[i]["du"] / 1000)
-                    Common.logger().info("视频时长:{}秒", video_duration)
-                else:
-                    video_duration = ""
-                    Common.logger().info("当前视频无时长:{}", video_duration)
-
-                # 宽和高
-                if "w" or "h" in feeds[i]:
-                    video_width = feeds[i]["w"]
-                    video_height = feeds[i]["h"]
-                    Common.logger().info("视频宽高:{}*{}", video_width, video_height)
-                else:
-                    video_width = ""
-                    video_height = ""
-                    Common.logger().info("当前视频无宽高:{}{}", video_width, video_height)
-
-                # 发布时间
-                if "t" in feeds[i]:
-                    video_send_time = feeds[i]["t"]
-                    Common.logger().info(
-                        "视频发布时间:{}", time.strftime(
-                            "%Y-%m-%d %H:%M:%S", time.localtime(int(video_send_time) / 1000)))
-                else:
-                    video_send_time = ""
-                    Common.logger().info("当前视频无发布时间:{}", video_send_time)
-
-                # 用户名 / 头像
-                if "user" in feeds[i]:
-                    user_name = feeds[i]["user"]["nick"].strip().replace("\n", "")\
-                        .replace("/", "").replace("快手", "").replace(" ", "") \
-                        .replace(" ", "").replace("&NBSP", "").replace("\r", "")
-                    head_url = feeds[i]["user"]["hurl"]
-                    Common.logger().info("用户名:{}", user_name)
-                    Common.logger().info("用户头像:{}", head_url)
-                else:
-                    user_name = ""
-                    head_url = ""
-                    Common.logger().info("当前视频无用户名:{}", user_name)
-                    Common.logger().info("当前视频无用户头像:{}", head_url)
-
-                # 视频封面
-                if "url" in feeds[i]:
-                    cover_url = feeds[i]["url"]
-                    Common.logger().info("视频封面:{}", cover_url)
-                else:
-                    cover_url = ""
-                    Common.logger().info("当前视频无视频封面:{}", cover_url)
-
-                # 视频播放地址
-                if "v_url" in feeds[i]:
-                    video_url = feeds[i]["v_url"]
-                    Common.logger().info("播放地址:{}", video_url)
-                else:
-                    video_url = ""
-                    Common.logger().info("当前视频无播放地址:{}", video_url)
-
-                # 视频水印:0 无 1 有
-                if "v_ort" in feeds[i]:
-                    video_logo = feeds[i]["v_ort"]
-                else:
-                    video_logo = "1"
-
-                # 过滤无效视频
-                if video_title == "" or video_id == "" or video_duration == ""\
-                        or video_send_time == "" or user_name == "" or head_url == ""\
-                        or cover_url == "" or video_url == "":
-                    Common.logger().warning("无效视频")
-                # 过滤敏感词
-                elif any(word if word in video_title else False for word in sensitive_words()) is True:
-                    Common.logger().info("视频已中敏感词:{}".format(video_title))
-                # 过滤水印视频
-                elif str(video_logo) == "1" and feeds[i]["tpl_id"] != 0 and len(video_id) > 15:
-                    Common.logger().info("视频有水印:{}", video_title)
-                # 从云文档去重:https://w42nne6hzg.feishu.cn/sheets/shtcngRPoDYAi24x52j2nDuHMih?sheet=onyBDH
-                elif video_id in [j for i in Feishu.get_values_batch("onyBDH") for j in i]:
-                    Common.logger().info("该视频已下载:{}", video_title)
-                # 从 云文档 去重:https://w42nne6hzg.feishu.cn/sheets/shtcngRPoDYAi24x52j2nDuHMih?sheet=S714lO
-                elif video_id in [j for i in Feishu.get_values_batch("S714lO") for j in i]:
-                    Common.logger().info("该视频已在feeds中:{}", video_title)
-                else:
-                    Common.logger().info("该视频未下载,添加至feeds中:{}".format(video_title))
-                    # feeds工作表,插入首行
-                    Feishu.insert_columns("S714lO", "ROWS", 1, 2)
-
-                    # 获取当前时间
-                    get_feeds_time = int(time.time())
-                    # 看一看云文档,工作表 kanyikan_feeds 中写入数据
-                    time.sleep(1)
-                    Feishu.update_values("S714lO",
-                                         a1=str(get_feeds_time),
-                                         b1=str(video_id),
-                                         c1=str(video_play_cnt),
-                                         d1=str(video_title),
-                                         e1=str(video_duration),
-                                         f1=str(video_comment_cnt),
-                                         g1=str(video_like_cnt),
-                                         h1=str(video_share_cnt),
-                                         i1=str(video_width)+"*"+str(video_height),
-                                         j1=str(video_send_time),
-                                         k1=str(user_name),
-                                         l1=str(head_url),
-                                         m1=str(cover_url),
-                                         n1=str(video_url),
-                                         o1=str("132645b6e2b996aaad1713a557456816"))
-
-    except Exception as e:
-        Common.logger().error("获取视频列表异常:{}", e)
-
-
-if __name__ == "__main__":
-    get_feeds()

+ 66 - 56
main/hour_list.py

@@ -14,6 +14,12 @@ proxies = {"http": None, "https": None}
 
 
 class HourList:
+    hour_x_b3_traceid = Feishu.get_range_value("person-log", "xiaoniangao", "dzcWHw", "B3:B3")[0]
+    hour_x_token_id = Feishu.get_range_value("person-log", "xiaoniangao", "dzcWHw", "B4:B4")[0]
+    hour_referer = Feishu.get_range_value("person-log", "xiaoniangao", "dzcWHw", "B5:B5")[0][0]["link"]
+    hour_uid = Feishu.get_range_value("person-log", "xiaoniangao", "dzcWHw", "B6:B6")[0]
+    hour_token = Feishu.get_range_value("person-log", "xiaoniangao", "dzcWHw", "B7:B7")[0]
+
     # 过滤敏感词
     @classmethod
     def sensitive_words(cls):
@@ -41,9 +47,9 @@ class HourList:
                       "T", "U", "V", "W", "X", "Y", "Z"]
         return words_list
 
-    # 下载规则
+    # 基础门槛规则
     @staticmethod
-    def download_rule(d_duration, d_width, d_height, d_play_cnt, d_like_cnt, d_share_cnt):
+    def download_rule(d_duration, d_width, d_height, d_play_cnt, d_like_cnt, d_share_cnt, d_send_time):
         """
         下载视频的基本规则
         :param d_duration: 时长
@@ -52,14 +58,24 @@ class HourList:
         :param d_play_cnt: 播放量
         :param d_like_cnt: 点赞量
         :param d_share_cnt: 分享量
+        :param d_send_time: 发布时间
         :return: 满足规则,返回 True;反之,返回 False
         """
+        # 视频时长
         if 600 >= int(float(d_duration)) >= 60:
+            # 宽或高
             if int(d_width) >= 0 or int(d_height) >= 0:
-                if int(d_play_cnt) >= 0:
+                # 播放量
+                if int(d_play_cnt) >= 5000:
+                    # 点赞量
                     if int(d_like_cnt) >= 0:
+                        # 分享量
                         if int(d_share_cnt) >= 0:
-                            return True
+                            # 发布时间 <= 7 天
+                            if int(time.time()) - int(d_send_time)/1000 <= 604800:
+                                return True
+                            else:
+                                return False
                         else:
                             return False
                     else:
@@ -119,15 +135,15 @@ class HourList:
         """
         url = "https://kapi.xiaoniangao.cn/trends/get_recommend_trends"
         headers = {
-            "x-b3-traceid": "bd267349bf41b",
-            "X-Token-Id": "86f6d7cc2b2b6870004df5d16c82aaf3-1185665701",
-            "uid": "8fde3c6c-c070-4379-bfc4-15c7e85139c9",
+            "x-b3-traceid": cls.hour_x_b3_traceid,
+            "X-Token-Id": cls.hour_x_token_id,
+            "uid": cls.hour_uid,
             "content-type": "application/json",
             "Accept-Encoding": "gzip,compress,br,deflate",
             "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
                           ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
                           'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
-            "Referer": "https://servicewechat.com/wxd7911e4c177690e4/617/page-frame.html"
+            "Referer": cls.hour_referer
         }
         data = {
             "log_params": {
@@ -174,8 +190,8 @@ class HourList:
                 "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29"
             },
             "refresh": False,
-            "token": "90747742180aeb22c0fe3a3c6a38f3d9",
-            "uid": "8fde3c6c-c070-4379-bfc4-15c7e85139c9",
+            "token": cls.hour_token,
+            "uid": cls.hour_uid,
             "proj": "ma",
             "wx_ver": "8.0.20",
             "code_ver": "3.62.0"
@@ -314,21 +330,10 @@ class HourList:
                             or cover_url == "" or video_url == "":
                         Common.logger().warning("无效视频")
 
-                    # 判断发布时间是否 > 7天
-                    elif int(time.time()) - int(video_send_time) / 1000 > 604800:
-                        Common.logger().info("发布时间大于7天", video_title)
-
-                    # 判断播放量是否 > 5000
-                    elif int(video_play_cnt) < 5000:
-                        Common.logger().info("该视频7天内播放量<5000:{}", video_title)
-
-                    # 判断视频 ID 长度,不大于 13 位
-                    elif len(str(video_id)) > 13:
-                        Common.logger().info("视频ID长度大于13位:{}", video_id)
-
-                    # 过滤带字母的视频ID
-                    elif any(word if word in video_id else False for word in cls.sensitive_videoid_words()) is True:
-                        Common.logger().info("视频ID带字母:{}".format(video_id))
+                    elif cls.download_rule(
+                            video_duration, video_width, video_height, video_play_cnt,
+                            video_like_cnt, video_share_cnt, video_send_time) is False:
+                        Common.logger().info("不满足基础门槛规则")
 
                     # 过滤敏感词
                     elif any(word if word in video_title else False for word in cls.sensitive_words()) is True:
@@ -441,15 +446,15 @@ class HourList:
 
                         url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id"
                         headers = {
-                            "x-b3-traceid": "bd267349bf41b",
-                            "X-Token-Id": "86f6d7cc2b2b6870004df5d16c82aaf3-1185665701",
-                            "uid": "8fde3c6c-c070-4379-bfc4-15c7e85139c9",
+                            "x-b3-traceid": cls.hour_x_b3_traceid,
+                            "X-Token-Id": cls.hour_x_token_id,
+                            "uid": cls.hour_uid,
                             "content-type": "application/json",
                             "Accept-Encoding": "gzip,compress,br,deflate",
                             "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
                                           ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
                                           'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
-                            "Referer": "https://servicewechat.com/wxd7911e4c177690e4/617/page-frame.html"
+                            "Referer": cls.hour_referer
                         }
                         data = {
                             "play_src": "1",
@@ -465,8 +470,8 @@ class HourList:
                             "no_follow": True,
                             "vid": v_id,
                             "hot_l1_comment": True,
-                            "token": "90747742180aeb22c0fe3a3c6a38f3d9",
-                            "uid": "8fde3c6c-c070-4379-bfc4-15c7e85139c9",
+                            "token": cls.hour_token,
+                            "uid": cls.hour_uid,
                             "proj": "ma",
                             "wx_ver": "8.0.20",
                             "code_ver": "3.62.0",
@@ -794,15 +799,20 @@ class HourList:
                         # 判断视频 ID 长度,不大于 13 位
                         if len(str(v_id)) > 13:
                             Common.logger().info("视频ID长度大于13位:{}", v_id)
+
+                        # 判断视频时长:1-10min
                         elif int(v_duration) > 600 or int(v_duration) < 60:
                             Common.logger().info("视频时长不在 1-10分钟 之间")
+
                         # 过滤带字母的视频ID
                         elif any(word if word in v_id else False for word in cls.sensitive_videoid_words()) is True:
                             Common.logger().info("视频ID带字母:{}".format(v_id))
-                            # 从云文档中去重:https://w42nne6hzg.feishu.cn/sheets/shtcnYxiyQ1wLklo1W5Kdqc9cGh?sheet=yatRv2
+
+                        # 从云文档中去重:https://w42nne6hzg.feishu.cn/sheets/shtcnYxiyQ1wLklo1W5Kdqc9cGh?sheet=yatRv2
                         elif v_id in [j for i in Feishu.get_values_batch("logs", "xiaoniangao", "yatRv2") for j in i]:
                             Common.logger().info("该视频已下载:{}", v_title)
                             time.sleep(1)
+
                         # 上升榜判断逻辑,任意时间段上升量>=5000,连续两个时间段上升量>=2000
                         elif int(ten_cnt) >= 5000 or int(fifteen_cnt) >= 5000 or int(twenty_cnt) >= 5000:
                             Common.logger().info("10:00 or 15:00 or 20:00 数据上升量:{} or {} or {} >= 5000",
@@ -812,15 +822,15 @@ class HourList:
                             try:
                                 url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id"
                                 headers = {
-                                    "x-b3-traceid": "bd267349bf41b",
-                                    "X-Token-Id": "86f6d7cc2b2b6870004df5d16c82aaf3-1185665701",
-                                    "uid": "8fde3c6c-c070-4379-bfc4-15c7e85139c9",
+                                    "x-b3-traceid": cls.hour_x_b3_traceid,
+                                    "X-Token-Id": cls.hour_x_token_id,
+                                    "uid": cls.hour_uid,
                                     "content-type": "application/json",
                                     "Accept-Encoding": "gzip,compress,br,deflate",
                                     "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
                                                   ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
                                                   'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
-                                    "Referer": "https://servicewechat.com/wxd7911e4c177690e4/617/page-frame.html"
+                                    "Referer": cls.hour_referer
                                 }
                                 data = {
                                     "play_src": "1",
@@ -836,8 +846,8 @@ class HourList:
                                     "no_follow": True,
                                     "vid": v_id,
                                     "hot_l1_comment": True,
-                                    "token": "90747742180aeb22c0fe3a3c6a38f3d9",
-                                    "uid": "8fde3c6c-c070-4379-bfc4-15c7e85139c9",
+                                    "token": cls.hour_token,
+                                    "uid": cls.hour_uid,
                                     "proj": "ma",
                                     "wx_ver": "8.0.20",
                                     "code_ver": "3.62.0",
@@ -941,15 +951,15 @@ class HourList:
                             try:
                                 url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id"
                                 headers = {
-                                    "x-b3-traceid": "bd267349bf41b",
-                                    "X-Token-Id": "86f6d7cc2b2b6870004df5d16c82aaf3-1185665701",
-                                    "uid": "8fde3c6c-c070-4379-bfc4-15c7e85139c9",
+                                    "x-b3-traceid": cls.hour_x_b3_traceid,
+                                    "X-Token-Id": cls.hour_x_token_id,
+                                    "uid": cls.hour_uid,
                                     "content-type": "application/json",
                                     "Accept-Encoding": "gzip,compress,br,deflate",
                                     "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
                                                   ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
                                                   'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
-                                    "Referer": "https://servicewechat.com/wxd7911e4c177690e4/617/page-frame.html"
+                                    "Referer": cls.hour_referer
                                 }
                                 data = {
                                     "play_src": "1",
@@ -965,8 +975,8 @@ class HourList:
                                     "no_follow": True,
                                     "vid": v_id,
                                     "hot_l1_comment": True,
-                                    "token": "90747742180aeb22c0fe3a3c6a38f3d9",
-                                    "uid": "8fde3c6c-c070-4379-bfc4-15c7e85139c9",
+                                    "token": cls.hour_token,
+                                    "uid": cls.hour_uid,
                                     "proj": "ma",
                                     "wx_ver": "8.0.20",
                                     "code_ver": "3.62.0",
@@ -1070,15 +1080,15 @@ class HourList:
                             try:
                                 url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id"
                                 headers = {
-                                    "x-b3-traceid": "bd267349bf41b",
-                                    "X-Token-Id": "86f6d7cc2b2b6870004df5d16c82aaf3-1185665701",
-                                    "uid": "8fde3c6c-c070-4379-bfc4-15c7e85139c9",
+                                    "x-b3-traceid": cls.hour_x_b3_traceid,
+                                    "X-Token-Id": cls.hour_x_token_id,
+                                    "uid": cls.hour_uid,
                                     "content-type": "application/json",
                                     "Accept-Encoding": "gzip,compress,br,deflate",
                                     "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
                                                   ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
                                                   'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
-                                    "Referer": "https://servicewechat.com/wxd7911e4c177690e4/617/page-frame.html"
+                                    "Referer": cls.hour_referer
                                 }
                                 data = {
                                     "play_src": "1",
@@ -1094,8 +1104,8 @@ class HourList:
                                     "no_follow": True,
                                     "vid": v_id,
                                     "hot_l1_comment": True,
-                                    "token": "90747742180aeb22c0fe3a3c6a38f3d9",
-                                    "uid": "8fde3c6c-c070-4379-bfc4-15c7e85139c9",
+                                    "token": cls.hour_token,
+                                    "uid": cls.hour_uid,
                                     "proj": "ma",
                                     "wx_ver": "8.0.20",
                                     "code_ver": "3.62.0",
@@ -1200,15 +1210,15 @@ class HourList:
                             try:
                                 url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id"
                                 headers = {
-                                    "x-b3-traceid": "bd267349bf41b",
-                                    "X-Token-Id": "86f6d7cc2b2b6870004df5d16c82aaf3-1185665701",
-                                    "uid": "8fde3c6c-c070-4379-bfc4-15c7e85139c9",
+                                    "x-b3-traceid": cls.hour_x_b3_traceid,
+                                    "X-Token-Id": cls.hour_x_token_id,
+                                    "uid": cls.hour_uid,
                                     "content-type": "application/json",
                                     "Accept-Encoding": "gzip,compress,br,deflate",
                                     "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
                                                   ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
                                                   'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
-                                    "Referer": "https://servicewechat.com/wxd7911e4c177690e4/617/page-frame.html"
+                                    "Referer": cls.hour_referer
                                 }
                                 data = {
                                     "play_src": "1",
@@ -1224,8 +1234,8 @@ class HourList:
                                     "no_follow": True,
                                     "vid": v_id,
                                     "hot_l1_comment": True,
-                                    "token": "90747742180aeb22c0fe3a3c6a38f3d9",
-                                    "uid": "8fde3c6c-c070-4379-bfc4-15c7e85139c9",
+                                    "token": cls.hour_token,
+                                    "uid": cls.hour_uid,
                                     "proj": "ma",
                                     "wx_ver": "8.0.20",
                                     "code_ver": "3.62.0",

+ 158 - 33
main/person_list.py

@@ -15,6 +15,12 @@ class Person:
     # 翻页初始值
     next_t_list = [-1]
 
+    person_x_b3_traceid = Feishu.get_range_value("person-log", "xiaoniangao", "dzcWHw", "C3:C3")[0]
+    person_x_token_id = Feishu.get_range_value("person-log", "xiaoniangao", "dzcWHw", "C4:C4")[0]
+    person_referer = Feishu.get_range_value("person-log", "xiaoniangao", "dzcWHw", "C5:C5")[0][0]["link"]
+    person_uid = Feishu.get_range_value("person-log", "xiaoniangao", "dzcWHw", "C6:C6")[0]
+    person_token = Feishu.get_range_value("person-log", "xiaoniangao", "dzcWHw", "C7:C7")[0]
+
     # 过滤敏感词
     @classmethod
     def sensitive_words(cls):
@@ -31,9 +37,47 @@ class Person:
                     word_list.append(j)
         return word_list
 
-    # 获取用户列表
+    # 基础门槛规则
+    @staticmethod
+    def download_rule(d_duration, d_width, d_height, d_play_cnt, d_like_cnt, d_share_cnt, d_send_time):
+        """
+        下载视频的基本规则
+        :param d_duration: 时长
+        :param d_width: 宽
+        :param d_height: 高
+        :param d_play_cnt: 播放量
+        :param d_like_cnt: 点赞量
+        :param d_share_cnt: 分享量
+        :param d_send_time: 发布时间
+        :return: 满足规则,返回 True;反之,返回 False
+        """
+        # 视频时长
+        if 600 >= int(float(d_duration)) >= 60:
+            # 宽或高
+            if int(d_width) >= 0 or int(d_height) >= 0:
+                # 播放量
+                if int(d_play_cnt) >= 5000:
+                    # 点赞量
+                    if int(d_like_cnt) >= 0:
+                        # 分享量
+                        if int(d_share_cnt) >= 0:
+                            # 发布时间 <= 48 小时
+                            if int(time.time()) - int(d_send_time) / 1000 <= 172800:
+                                return True
+                            else:
+                                return False
+                        else:
+                            return False
+                    else:
+                        return False
+                else:
+                    return False
+            return False
+        return False
+
+    # 获取关注用户列表
     @classmethod
-    def person_list(cls):
+    def follow_person_list(cls):
         try:
             if len(Feishu.get_values_batch("person-logs", "xiaoniangao", "oNpThi")) == 1:
                 Common.person_logger().info("暂无定向爬取账号")
@@ -57,22 +101,48 @@ class Person:
         except Exception as e:
             Common.person_logger().error("获取用户列表异常:{}", e)
 
+    # 获取取消关注用户列表
+    @classmethod
+    def unfollow_person_list(cls):
+        try:
+            if len(Feishu.get_values_batch("person-logs", "xiaoniangao", "tuMNhn")) == 1:
+                Common.person_logger().info("暂无定向账号")
+            else:
+                unfollow_person_list = []
+                nick_list = []
+                for i in range(2, len(Feishu.get_values_batch("person-logs", "xiaoniangao", "tuMNhn")) + 1):
+                    time.sleep(0.5)
+                    profile_mid = Feishu.get_range_value(
+                        "person-logs", "xiaoniangao", "tuMNhn", "B" + str(i) + ":" + "B" + str(i))[0]
+                    time.sleep(0.5)
+                    nick = \
+                        Feishu.get_range_value("person-logs", "xiaoniangao", "tuMNhn",
+                                               "C" + str(i) + ":" + "C" + str(i))[0]
+                    nick_list.append(nick)
+                    unfollow_person_list.append(profile_mid)
+
+                Common.person_logger().info("取消关注用户列表:{}", nick_list)
+                return unfollow_person_list
+
+        except Exception as e:
+            Common.person_logger().error("获取用户列表异常:{}", e)
+
     # 关注列表中的用户
     @classmethod
     def sub_persons(cls):
-        profile_mids = cls.person_list()
+        profile_mids = cls.follow_person_list()
         for profile_mid in profile_mids:
             url = "https://api.xiaoniangao.cn/V1/account/sub_user"
             headers = {
-                "X-Mid": "1164637358",
-                "X-Token-Id": "af9c47bb6c942236ff35ee10d355f3b0-1164637358",
+                "x-b3-traceid": cls.person_x_b3_traceid,
+                "X-Token-Id": cls.person_x_token_id,
                 "content-type": "application/json",
-                "uuid": "3d460a1b-ab85-426b-bd80-62029acaa2c0",
+                "uuid": cls.person_uid,
                 "Accept-Encoding": "gzip,compress,br,deflate",
                 "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)"
                               " AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 "
                               "MicroMessenger/8.0.20(0x18001435) NetType/WIFI Language/zh_CN",
-                "Referer": "https://servicewechat.com/wxd7911e4c177690e4/617/page-frame.html"
+                "Referer": cls.person_referer
             }
             data = {
                 "visited_mid": int(profile_mid),
@@ -100,8 +170,8 @@ class Person:
                     "pf": "2",
                     "session_id": "d53b6125-942b-4ec1-8d22-f9451a35e9f9"
                 },
-                "token": "451273638af2c8bb90266bcfaf601a68",
-                "uid": "3d460a1b-ab85-426b-bd80-62029acaa2c0",
+                "token": cls.person_token,
+                "uid": cls.person_uid,
                 "proj": "ma",
                 "wx_ver": "8.0.20",
                 "code_ver": "3.62.0"
@@ -114,20 +184,76 @@ class Person:
             except Exception as e:
                 Common.person_logger().error("关注用户异常:{}", e)
 
+    # 取消关注
+    @classmethod
+    def unsub_persons(cls):
+        unsub_profile_mids = cls.unfollow_person_list()
+        for profile_mid in unsub_profile_mids:
+            url = "https://api.xiaoniangao.cn/V1/account/unsub_user"
+            headers = {
+                "x-b3-traceid": cls.person_x_b3_traceid,
+                "X-Token-Id": cls.person_x_token_id,
+                "content-type": "application/json",
+                "uuid": cls.person_uid,
+                "Accept-Encoding": "gzip,compress,br,deflate",
+                "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)"
+                              " AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 "
+                              "MicroMessenger/8.0.20(0x18001435) NetType/WIFI Language/zh_CN",
+                "Referer": cls.person_referer
+            }
+            data = {
+                "visited_mid": int(profile_mid),
+                "log_common_params": {
+                    "e": [{
+                        "data": {
+                            "page": "profilePage",
+                            "topic": "public",
+                            "type": "unfollow",
+                            "name": "user",
+                            "smid": str(profile_mid)
+                        },
+                        "ab": {}
+                    }],
+                    "ext": {
+                        "brand": "iPhone",
+                        "device": "iPhone 11",
+                        "os": "iOS 14.7.1",
+                        "weixinver": "8.0.20",
+                        "srcver": "2.24.4",
+                        "net": "wifi",
+                        "scene": "1089"
+                    },
+                    "pj": "1",
+                    "pf": "2",
+                    "session_id": "6a2959c7-3f98-411f-8bc9-8d2a8a5c6f16"
+                },
+                "token": cls.person_token,
+                "uid": cls.person_uid,
+                "proj": "ma",
+                "wx_ver": "8.0.20",
+                "code_ver": "3.64.1"}
+
+            try:
+                urllib3.disable_warnings()
+                r = requests.post(headers=headers, url=url, json=data, proxies=proxies, verify=False)
+                Common.person_logger().info("取消关注:{},{}", profile_mid, r)
+            except Exception as e:
+                Common.person_logger().error("取消关注异常:{}", e)
+
     # 从关注列表获取视频,并下载符合规则的视频,再进行上传
     @classmethod
     def download_from_sub(cls, endtime):
         url = "https://api.xiaoniangao.cn/album/get_user_trends"
         headers = {
-            "X-Mid": "1164637358",
-            "X-Token-Id": "af9c47bb6c942236ff35ee10d355f3b0-1164637358",
+            "x-b3-traceid": cls.person_x_b3_traceid,
+            "X-Token-Id": cls.person_x_token_id,
             "content-type": "application/json",
-            "uuid": "3d460a1b-ab85-426b-bd80-62029acaa2c0",
+            "uuid": cls.person_uid,
             "Accept-Encoding": "gzip,compress,br,deflate",
             "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)"
                           " AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 "
                           "MicroMessenger/8.0.20(0x18001435) NetType/WIFI Language/zh_CN",
-            "Referer": "https://servicewechat.com/wxd7911e4c177690e4/617/page-frame.html"
+            "Referer": cls.person_referer
         }
         data = {
             "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/!750x500r/crop/750x500/interlace/1/format/jpg",
@@ -136,8 +262,8 @@ class Person:
             "limit": 5,
             "share_width": 625,
             "share_height": 500,
-            "token": "451273638af2c8bb90266bcfaf601a68",
-            "uid": "3d460a1b-ab85-426b-bd80-62029acaa2c0",
+            "token": cls.person_token,
+            "uid": cls.person_uid,
             "proj": "ma",
             "wx_ver": "8.0.20",
             "code_ver": "3.62.0",
@@ -171,11 +297,11 @@ class Person:
             for i in range(len(feeds)):
                 # 标题
                 video_title = feeds[i]["title"].strip().replace("\n", "") \
-                            .replace("/", "").replace("\r", "").replace("#", "") \
-                            .replace(".", "。").replace("\\", "").replace("&NBSP", "") \
-                            .replace(":", "").replace("*", "").replace("?", "") \
-                            .replace("?", "").replace('"', "").replace("<", "") \
-                            .replace(">", "").replace("|", "").replace(" ", "")
+                    .replace("/", "").replace("\r", "").replace("#", "") \
+                    .replace(".", "。").replace("\\", "").replace("&NBSP", "") \
+                    .replace(":", "").replace("*", "").replace("?", "") \
+                    .replace("?", "").replace('"', "").replace("<", "") \
+                    .replace(">", "").replace("|", "").replace(" ", "")
                 Common.person_logger().info("标题:{}", video_title)
                 # 用户名
                 user_name = feeds[i]["user"]["nick"].strip().replace("\n", "") \
@@ -218,20 +344,17 @@ class Person:
                 # 过滤无效视频
                 if video_id == "" or video_url == "" or video_send_time == "":
                     Common.person_logger().info("无效视频")
-                # 判断发布时间:2022年5月18日以后发布
                 elif int(video_send_time) < endtime:
-                    Common.person_logger().info(
-                        "发布时间:{},在2022年5月18日之前",
-                        time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(video_send_time) / 1000)))
-                # 判断视频播放量大于1000
-                elif int(video_play_cnt) < 1000:
-                    Common.person_logger().info("视频:{},播放量:{}<1000", video_title, video_play_cnt)
+                    Common.person_logger().info("发布时间超过 48 小时")
+                elif cls.download_rule(
+                        video_duration, video_width, video_height, video_play_cnt,
+                        video_like_cnt, video_share_cnt, video_send_time) is False:
+                    Common.person_logger().info("不满足基础门槛规则")
                 # 过滤敏感词
                 elif any(word if word in video_title else False for word in cls.sensitive_words()) is True:
                     Common.person_logger().info("视频已中敏感词:{}".format(video_title))
                 # 从 云文档 去重:https://w42nne6hzg.feishu.cn/sheets/shtcnYxiyQ1wLklo1W5Kdqc9cGh?sheet=yatRv2
-                elif video_id in [j for i in Feishu.get_values_batch(
-                        "person-logs", "xiaoniangao", "yatRv2") for j in i]:
+                elif video_id in [j for i in Feishu.get_values_batch("person-logs", "xiaoniangao", "yatRv2") for j in i]:
                     Common.person_logger().info("该视频已下载:{}", video_title)
                 # 满足抓取规则
                 else:
@@ -252,7 +375,7 @@ class Person:
                                   str(video_comment_cnt) + "\n" +
                                   str(video_like_cnt) + "\n" +
                                   str(video_share_cnt) + "\n" +
-                                  str(video_width)+"*"+str(video_height) + "\n" +
+                                  str(video_width) + "*" + str(video_height) + "\n" +
                                   str(video_send_time) + "\n" +
                                   str(user_name) + "\n" +
                                   str(head_url) + "\n" +
@@ -283,8 +406,8 @@ class Person:
                                video_like_cnt,
                                video_share_cnt,
                                video_duration,
-                               str(video_width)+"*"+str(video_height),
-                               time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(video_send_time)/1000)),
+                               str(video_width) + "*" + str(video_height),
+                               time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(video_send_time) / 1000)),
                                user_name,
                                profile_id,
                                profile_mid,
@@ -302,4 +425,6 @@ if __name__ == "__main__":
     person = Person()
     # person.person_list()
     # person.download_person_videos()
-    person.sub_persons()
+    # person.sub_persons()
+    # print(person.unfollow_person_list())
+    person.unsub_persons()

+ 3 - 3
main/publish.py

@@ -33,9 +33,9 @@ class Publish:
         versionCode  版本 默认1
         :return:
         """
-        Common.logger().info('publish request data: {}'.format(request_data))
+        # Common.logger().info('publish request data: {}'.format(request_data))
         result = cls.request_post('https://videotest.yishihui.com/longvideoapi/crawler/video/send', request_data)
-        Common.logger().info('publish result: {}'.format(result))
+        # Common.logger().info('publish result: {}'.format(result))
         if result['code'] != 0:
             Common.logger().error('pushlish failure msg = {}'.format(result['msg']))
         else:
@@ -59,7 +59,7 @@ class Publish:
         :return:
         """
         result = cls.request_post('https://longvideoapi.piaoquantv.com/longvideoapi/crawler/video/send', request_data)
-        Common.logger().info('publish result: {}'.format(result))
+        # Common.logger().info('publish result: {}'.format(result))
         if result['code'] != 0:
             Common.logger().error('pushlish failure msg = {}'.format(result['msg']))
         else:

+ 0 - 83
main/run.py

@@ -1,83 +0,0 @@
-# -*- coding: utf-8 -*-
-# @Author: wangkun
-# @Time: 2022/5/12
-import datetime
-import os
-import random
-import sys
-import time
-sys.path.append(os.getcwd())
-from main.common import Common
-from main.download import Download
-from main.get_feeds import get_feeds
-from main.hour_list import HourList
-
-
-def xiaoniangao_prod_job():
-    """
-    执行正式环境脚本
-    """
-    while True:
-        # 当天下载及上传的视频数:150 条
-        if len(Download.download_video_list) >= 100:
-            Common.logger().info("已下载视频数:{}".format(len(Download.download_video_list)))
-            time.sleep(1800)
-        else:
-            Common.logger().info("开始抓取小年糕视频")
-            time.sleep(1)
-
-            # 获取视频列表
-            get_feeds()
-            # 下载视频,并上传
-            Download.download("prod")
-            # 随机睡眠1-3s
-            time.sleep(random.randint(1, 3))
-
-        # 删除冗余日志
-        Common.del_logs("logs")
-
-
-def main_prod():
-    """
-    正式环境主函数
-    """
-    while True:
-        while True:
-            main_prod_time = datetime.datetime.now()
-            if main_prod_time.hour >= 8:
-                xiaoniangao_prod_job()
-            else:
-                break
-
-
-def main_hour_list():
-    while True:
-        HourList.get_hour_list_feeds()
-        time.sleep(0.5)
-        hour_list_time = datetime.datetime.now()
-        if hour_list_time.hour == 10 and 5 >= hour_list_time.minute >= 0:
-            Common.logger().info("检查今日上升榜日期是否存在")
-            HourList.check_hour_list_data()
-            # Common.logger().info("开始清除空行")
-            # HourList.del_null_rows()
-            Common.logger().info("开始更新上升榜")
-            HourList.update_hour_list_data()
-        if hour_list_time.hour == 15 and 5 >= hour_list_time.minute >= 0:
-            Common.logger().info("检查今日上升榜日期是否存在")
-            HourList.check_hour_list_data()
-            # Common.logger().info("开始清除空行")
-            # HourList.del_null_rows()
-            Common.logger().info("开始更新上升榜")
-            HourList.update_hour_list_data()
-        if hour_list_time.hour == 20 and 5 >= hour_list_time.minute >= 0:
-            Common.logger().info("检查今日上升榜日期是否存在")
-            HourList.check_hour_list_data()
-            # Common.logger().info("开始清除空行")
-            # HourList.del_null_rows()
-            Common.logger().info("开始更新上升榜")
-            HourList.update_hour_list_data()
-
-
-if __name__ == "__main__":
-    main_prod()
-    # main_hour_list()

+ 15 - 3
main/run_person_list.py

@@ -2,7 +2,9 @@
 # @Author: wangkun
 # @Time: 2022/5/18
 import datetime
+from datetime import timedelta
 import os
+# import random
 import sys
 import time
 
@@ -16,9 +18,19 @@ def person_list_job():
         Common.person_logger().info("开始抓取小年糕关注榜")
         # 关注用户列表
         Person.sub_persons()
+        time.sleep(1)
+        # 取消关注用户
+        Person.unsub_persons()
+        time.sleep(1)
+
         while True:
+            # 前天 <class 'str'>  2022-04-13
+            before_yesterday = (datetime.date.today() + timedelta(days=-2)).strftime("%Y/%m/%d %H:%M:%S")
+            before_yesterday = time.strptime(before_yesterday, "%Y/%m/%d %H:%M:%S")
+            before_yesterday = int(time.mktime(before_yesterday))*1000
             # 任务结束时间:小于 2022年5月18日
-            endtime = 1652803200000
+            # endtime = 1652803200000
+            endtime = before_yesterday
             person_list_time = datetime.datetime.now()
 
             if Person.download_from_sub(endtime) >= endtime:
@@ -28,8 +40,8 @@ def person_list_job():
                 Person.next_t_list = [-1]
                 break
             else:
-                Common.person_logger().info("发布时间小于2022年5月18日,结束抓取任务")
-                time.sleep(3600)
+                Common.person_logger().info("发布时间大于48小时,结束抓取任务")
+                time.sleep(3)
                 Person.next_t_list = [-1]
                 break