소스 검색

update gongzhonghao

wangkun 2 년 전
부모
커밋
4d7abb8dd8

+ 14 - 9
gongzhonghao/gongzhonghao_follow/gongzhonghao_follow.py

@@ -73,7 +73,11 @@ class GongzhonghaoFollow:
                     continue
                 token = sheet[0][1]
                 cookie = sheet[1][1]
-                token_dict = {'token': token, 'cookie': cookie}
+                gzh_name = sheet[2][1]
+                gzh_time = sheet[3][1]
+                token_dict = {'token': token, 'cookie': cookie, 'gzh_name': gzh_name, 'gzh_time': gzh_time}
+                print(type(token_dict['gzh_time']))
+                print(token_dict['gzh_time'])
                 return token_dict
             except Exception as e:
                 Common.logger(log_type, crawler).error(f"get_cookie_token异常:{e}\n")
@@ -120,21 +124,21 @@ class GongzhonghaoFollow:
                     Common.logger(log_type, crawler).info(f"status_code:{r.status_code}")
                     Common.logger(log_type, crawler).warning(f"get_fakeid:{r.text}\n")
                     if 20 >= datetime.datetime.now().hour >= 10:
-                        Feishu.bot(log_type, crawler, "token_1过期啦,请扫码更换token\nhttps://mp.weixin.qq.com/")
+                        Feishu.bot(log_type, crawler, f"token_1:{token_dict['gzh_name']}\n更换日期:{token_dict['gzh_time']}\n过期啦,请扫码更换token\nhttps://mp.weixin.qq.com/")
                     time.sleep(60 * 10)
                     continue
                 if r.json()["base_resp"]["err_msg"] == "freq control":
                     Common.logger(log_type, crawler).info(f"status_code:{r.status_code}")
                     Common.logger(log_type, crawler).warning(f"get_fakeid:{r.text}\n")
                     if 20 >= datetime.datetime.now().hour >= 10:
-                        Feishu.bot(log_type, crawler, "公众号_1频控啦,请扫码更换其他公众号token\nhttps://mp.weixin.qq.com/")
+                        Feishu.bot(log_type, crawler, f"公众号_1:{token_dict['gzh_name']}\n更换日期:{token_dict['gzh_time']}\n频控啦,请扫码更换其他公众号token\nhttps://mp.weixin.qq.com/")
                     time.sleep(60 * 10)
                     continue
                 if "list" not in r.json() or len(r.json()["list"]) == 0:
                     Common.logger(log_type, crawler).info(f"status_code:{r.status_code}")
                     Common.logger(log_type, crawler).warning(f"get_gzh_url:{r.text}\n")
-                    if 21 >= datetime.datetime.now().hour >= 10:
-                        Feishu.bot(log_type, crawler, "公众号_1频控啦,请扫码更换其他公众号token\nhttps://mp.weixin.qq.com/")
+                    if 20 >= datetime.datetime.now().hour >= 10:
+                        Feishu.bot(log_type, crawler, f"公众号_1:{token_dict['gzh_name']}\n更换日期:{token_dict['gzh_time']}\n频控啦,请扫码更换其他公众号token\nhttps://mp.weixin.qq.com/")
                     time.sleep(60 * 10)
                     continue
 
@@ -244,21 +248,21 @@ class GongzhonghaoFollow:
                     Common.logger(log_type, crawler).info(f"status_code:{r.status_code}")
                     Common.logger(log_type, crawler).info(f"get_videoList:{r.text}\n")
                     if 20 >= datetime.datetime.now().hour >= 10:
-                        Feishu.bot(log_type, crawler, "token_1过期啦,请扫码更换token\nhttps://mp.weixin.qq.com/")
+                        Feishu.bot(log_type, crawler, f"token_1:{token_dict['gzh_name']}\n更换日期:{token_dict['gzh_time']}\n过期啦,请扫码更换token\nhttps://mp.weixin.qq.com/")
                     time.sleep(60 * 10)
                     continue
                 if r.json()["base_resp"]["err_msg"] == "freq control":
                     Common.logger(log_type, crawler).info(f"status_code:{r.status_code}")
                     Common.logger(log_type, crawler).warning(f"get_gzh_url:{r.text}\n")
                     if 20 >= datetime.datetime.now().hour >= 10:
-                        Feishu.bot(log_type, crawler,"公众号_1频控啦,请扫码更换其他公众号token\nhttps://mp.weixin.qq.com/")
+                        Feishu.bot(log_type, crawler,f"公众号_1:{token_dict['gzh_name']}\n更换日期:{token_dict['gzh_time']}\n频控啦,请扫码更换其他公众号token\nhttps://mp.weixin.qq.com/")
                     time.sleep(60 * 10)
                     continue
                 if 'app_msg_list' not in r.json():
                     Common.logger(log_type, crawler).info(f"status_code:{r.status_code}")
                     Common.logger(log_type, crawler).warning(f"get_gzh_url:{r.text}\n")
                     if 20 >= datetime.datetime.now().hour >= 10:
-                        Feishu.bot(log_type, crawler, "公众号_1频控啦,请扫码更换其他公众号token\nhttps://mp.weixin.qq.com/")
+                        Feishu.bot(log_type, crawler, f"公众号_1:{token_dict['gzh_name']}\n更换日期:{token_dict['gzh_time']}\n频控啦,请扫码更换其他公众号token\nhttps://mp.weixin.qq.com/")
                     time.sleep(60 * 10)
                     continue
                 if len(r.json()['app_msg_list']) == 0:
@@ -507,7 +511,8 @@ class GongzhonghaoFollow:
 
 
 if __name__ == "__main__":
-    GongzhonghaoFollow.get_users()
+    GongzhonghaoFollow.get_token(log_type="follow", crawler="gongzhonghao")
+    # GongzhonghaoFollow.get_users()
     # GongzhonghaoFollow.get_videoList(log_type="follow",
     #                                  crawler="gongzhonghao",
     #                                  user="香音难忘",

+ 19 - 17
gongzhonghao/gongzhonghao_follow/gongzhonghao_follow_2.py

@@ -73,7 +73,9 @@ class GongzhonghaoFollow2:
                     continue
                 token = sheet[0][1]
                 cookie = sheet[1][1]
-                token_dict = {'token': token, 'cookie': cookie}
+                gzh_name = sheet[2][1]
+                gzh_time = sheet[3][1]
+                token_dict = {'token': token, 'cookie': cookie, 'gzh_name': gzh_name, 'gzh_time': gzh_time}
                 return token_dict
             except Exception as e:
                 Common.logger(log_type, crawler).error(f"get_cookie_token异常:{e}\n")
@@ -118,22 +120,22 @@ class GongzhonghaoFollow2:
                 if r.json()["base_resp"]["err_msg"] == "invalid session":
                     Common.logger(log_type, crawler).info(f"status_code:{r.status_code}")
                     Common.logger(log_type, crawler).warning(f"get_fakeid:{r.text}\n")
-                    if 21 >= datetime.datetime.now().hour >= 10:
-                        Feishu.bot(log_type, crawler, "token_2过期啦,请扫码更换token\nhttps://mp.weixin.qq.com/")
+                    if 20 >= datetime.datetime.now().hour >= 10:
+                        Feishu.bot(log_type, crawler, f"token_2:{token_dict['gzh_name']}\n更换日期:{token_dict['gzh_time']}\n过期啦,请扫码更换token\nhttps://mp.weixin.qq.com/")
                     time.sleep(60 * 10)
                     continue
                 if r.json()["base_resp"]["err_msg"] == "freq control":
                     Common.logger(log_type, crawler).info(f"status_code:{r.status_code}")
                     Common.logger(log_type, crawler).warning(f"get_fakeid:{r.text}\n")
-                    if 21 >= datetime.datetime.now().hour >= 10:
-                        Feishu.bot(log_type, crawler, "公众号_2频控啦,请扫码更换其他公众号token\nhttps://mp.weixin.qq.com/")
+                    if 20 >= datetime.datetime.now().hour >= 10:
+                        Feishu.bot(log_type, crawler, f"公众号_2:{token_dict['gzh_name']}\n更换日期:{token_dict['gzh_time']}\n频控啦,请扫码更换其他公众号token\nhttps://mp.weixin.qq.com/")
                     time.sleep(60 * 10)
                     continue
                 if "list" not in r.json() or len(r.json()["list"]) == 0:
                     Common.logger(log_type, crawler).info(f"status_code:{r.status_code}")
                     Common.logger(log_type, crawler).warning(f"get_fakeid:{r.text}\n")
-                    if 21 >= datetime.datetime.now().hour >= 10:
-                        Feishu.bot(log_type, crawler, "公众号_2频控啦,请扫码更换其他公众号token\nhttps://mp.weixin.qq.com/")
+                    if 20 >= datetime.datetime.now().hour >= 10:
+                        Feishu.bot(log_type, crawler, f"公众号_2:{token_dict['gzh_name']}\n更换日期:{token_dict['gzh_time']}\n频控啦,请扫码更换其他公众号token\nhttps://mp.weixin.qq.com/")
                     time.sleep(60 * 10)
                     continue
                 fakeid = r.json()["list"][int(index) - 1]["fakeid"]
@@ -241,22 +243,22 @@ class GongzhonghaoFollow2:
                 if r.json()["base_resp"]["err_msg"] == "invalid session":
                     Common.logger(log_type, crawler).info(f"status_code:{r.status_code}")
                     Common.logger(log_type, crawler).info(f"response:{r.text}")
-                    if 21 >= datetime.datetime.now().hour >= 10:
-                        Feishu.bot(log_type, crawler, "token_2过期啦,请扫码更换token\nhttps://mp.weixin.qq.com/")
+                    if 20 >= datetime.datetime.now().hour >= 10:
+                        Feishu.bot(log_type, crawler, f"token_2:{token_dict['gzh_name']}\n更换日期:{token_dict['gzh_time']}\n过期啦,请扫码更换token\nhttps://mp.weixin.qq.com/")
                     time.sleep(60 * 10)
                     continue
                 if r.json()["base_resp"]["err_msg"] == "freq control":
                     Common.logger(log_type, crawler).info(f"status_code:{r.status_code}")
                     Common.logger(log_type, crawler).warning(f"get_gzh_url:{r.text}\n")
-                    if 21 >= datetime.datetime.now().hour >= 10:
-                        Feishu.bot(log_type, crawler, "公众号_2频控啦,请扫码更换其他公众号token\nhttps://mp.weixin.qq.com/")
+                    if 20 >= datetime.datetime.now().hour >= 10:
+                        Feishu.bot(log_type, crawler, f"公众号_2:{token_dict['gzh_name']}\n更换日期:{token_dict['gzh_time']}\n频控啦,请扫码更换其他公众号token\nhttps://mp.weixin.qq.com/")
                     time.sleep(60 * 10)
                     continue
                 if 'app_msg_list' not in r.json():
                     Common.logger(log_type, crawler).info(f"status_code:{r.status_code}")
                     Common.logger(log_type, crawler).warning(f"get_gzh_url:{r.text}\n")
-                    if 21 >= datetime.datetime.now().hour >= 10:
-                        Feishu.bot(log_type, crawler, "公众号_2频控啦,请扫码更换其他公众号token\nhttps://mp.weixin.qq.com/")
+                    if 20 >= datetime.datetime.now().hour >= 10:
+                        Feishu.bot(log_type, crawler, f"公众号_2:{token_dict['gzh_name']}\n更换日期:{token_dict['gzh_time']}\n频控啦,请扫码更换其他公众号token\nhttps://mp.weixin.qq.com/")
                     time.sleep(60 * 10)
                     continue
                 if len(r.json()['app_msg_list']) == 0:
@@ -328,8 +330,8 @@ class GongzhonghaoFollow2:
                             return
                         cls.download_publish(log_type, crawler, video_dict, oss_endpoint, env)
 
-                    Common.logger(log_type, crawler).info('随机休眠 0-60 秒\n')
-                    time.sleep(random.randint(0, 60))
+                    Common.logger(log_type, crawler).info('随机休眠 60-60*3 秒\n')
+                    time.sleep(random.randint(60, 60*3))
         except Exception as e:
             Common.logger(log_type, crawler).error(f"get_videoList异常:{e}\n")
 
@@ -498,8 +500,8 @@ class GongzhonghaoFollow2:
                 Common.logger(log_type, crawler).info(f'获取 {user_name} 公众号视频\n')
                 cls.get_videoList(log_type, crawler, user_name, index, oss_endpoint, env)
                 cls.begin = 0
-                Common.logger(log_type, crawler).info('随机休眠 0-60 秒\n')
-                time.sleep(random.randint(0, 60))
+                Common.logger(log_type, crawler).info('随机休眠 60-60*3 秒\n')
+                time.sleep(random.randint(60, 60*3))
         except Exception as e:
             Common.logger(log_type, crawler).info(f'get_all_videos异常:{e}\n')
 

+ 21 - 19
gongzhonghao/gongzhonghao_follow/gongzhonghao_follow_3.py

@@ -26,7 +26,7 @@ from common.publish import Publish
 from common.scheduling_db import MysqlHelper
 
 
-class GongzhonghaoFollow2:
+class GongzhonghaoFollow3:
     # 翻页参数
     begin = 0
     platform = "公众号"
@@ -73,7 +73,9 @@ class GongzhonghaoFollow2:
                     continue
                 token = sheet[0][1]
                 cookie = sheet[1][1]
-                token_dict = {'token': token, 'cookie': cookie}
+                gzh_name = sheet[2][1]
+                gzh_time = sheet[3][1]
+                token_dict = {'token': token, 'cookie': cookie, 'gzh_name': gzh_name, 'gzh_time': gzh_time}
                 return token_dict
             except Exception as e:
                 Common.logger(log_type, crawler).error(f"get_cookie_token异常:{e}\n")
@@ -118,22 +120,22 @@ class GongzhonghaoFollow2:
                 if r.json()["base_resp"]["err_msg"] == "invalid session":
                     Common.logger(log_type, crawler).info(f"status_code:{r.status_code}")
                     Common.logger(log_type, crawler).warning(f"get_fakeid:{r.text}\n")
-                    if 21 >= datetime.datetime.now().hour >= 10:
-                        Feishu.bot(log_type, crawler, "token_2过期啦,请扫码更换token\nhttps://mp.weixin.qq.com/")
+                    if 20 >= datetime.datetime.now().hour >= 10:
+                        Feishu.bot(log_type, crawler, f"token_3:{token_dict['gzh_name']}\n更换日期:{token_dict['gzh_time']}\n过期啦,请扫码更换token\nhttps://mp.weixin.qq.com/")
                     time.sleep(60 * 10)
                     continue
                 if r.json()["base_resp"]["err_msg"] == "freq control":
                     Common.logger(log_type, crawler).info(f"status_code:{r.status_code}")
                     Common.logger(log_type, crawler).warning(f"get_fakeid:{r.text}\n")
-                    if 21 >= datetime.datetime.now().hour >= 10:
-                        Feishu.bot(log_type, crawler, "公众号_2频控啦,请扫码更换其他公众号token\nhttps://mp.weixin.qq.com/")
+                    if 20 >= datetime.datetime.now().hour >= 10:
+                        Feishu.bot(log_type, crawler, f"公众号_3:{token_dict['gzh_name']}\n更换日期:{token_dict['gzh_time']}\n频控啦,请扫码更换其他公众号token\nhttps://mp.weixin.qq.com/")
                     time.sleep(60 * 10)
                     continue
                 if "list" not in r.json() or len(r.json()["list"]) == 0:
                     Common.logger(log_type, crawler).info(f"status_code:{r.status_code}")
                     Common.logger(log_type, crawler).warning(f"get_fakeid:{r.text}\n")
-                    if 21 >= datetime.datetime.now().hour >= 10:
-                        Feishu.bot(log_type, crawler, "公众号_2频控啦,请扫码更换其他公众号token\nhttps://mp.weixin.qq.com/")
+                    if 20 >= datetime.datetime.now().hour >= 10:
+                        Feishu.bot(log_type, crawler, f"公众号_3:{token_dict['gzh_name']}\n更换日期:{token_dict['gzh_time']}\n频控啦,请扫码更换其他公众号token\nhttps://mp.weixin.qq.com/")
                     time.sleep(60 * 10)
                     continue
                 fakeid = r.json()["list"][int(index) - 1]["fakeid"]
@@ -241,22 +243,22 @@ class GongzhonghaoFollow2:
                 if r.json()["base_resp"]["err_msg"] == "invalid session":
                     Common.logger(log_type, crawler).info(f"status_code:{r.status_code}")
                     Common.logger(log_type, crawler).info(f"get_videoList:{r.text}\n")
-                    if 21 >= datetime.datetime.now().hour >= 10:
-                        Feishu.bot(log_type, crawler, "token_2过期啦,请扫码更换token\nhttps://mp.weixin.qq.com/")
+                    if 20 >= datetime.datetime.now().hour >= 10:
+                        Feishu.bot(log_type, crawler, f"token_3:{token_dict['gzh_name']}\n更换日期:{token_dict['gzh_time']}\n过期啦,请扫码更换token\nhttps://mp.weixin.qq.com/")
                     time.sleep(60 * 10)
                     continue
                 if r.json()["base_resp"]["err_msg"] == "freq control":
                     Common.logger(log_type, crawler).info(f"status_code:{r.status_code}")
                     Common.logger(log_type, crawler).warning(f"get_videoList:{r.text}\n")
-                    if 21 >= datetime.datetime.now().hour >= 10:
-                        Feishu.bot(log_type, crawler, "公众号_2频控啦,请扫码更换其他公众号token\nhttps://mp.weixin.qq.com/")
+                    if 20 >= datetime.datetime.now().hour >= 10:
+                        Feishu.bot(log_type, crawler, f"公众号_3:{token_dict['gzh_name']}\n更换日期:{token_dict['gzh_time']}\n频控啦,请扫码更换其他公众号token\nhttps://mp.weixin.qq.com/")
                     time.sleep(60 * 10)
                     continue
                 if 'app_msg_list' not in r.json():
                     Common.logger(log_type, crawler).info(f"status_code:{r.status_code}")
                     Common.logger(log_type, crawler).warning(f"get_videoList:{r.text}\n")
-                    if 21 >= datetime.datetime.now().hour >= 10:
-                        Feishu.bot(log_type, crawler, "公众号_2频控啦,请扫码更换其他公众号token\nhttps://mp.weixin.qq.com/")
+                    if 20 >= datetime.datetime.now().hour >= 10:
+                        Feishu.bot(log_type, crawler, f"公众号_3:{token_dict['gzh_name']}\n更换日期:{token_dict['gzh_time']}\n频控啦,请扫码更换其他公众号token\nhttps://mp.weixin.qq.com/")
                     time.sleep(60 * 10)
                     continue
                 if len(r.json()['app_msg_list']) == 0:
@@ -328,8 +330,8 @@ class GongzhonghaoFollow2:
                             return
                         cls.download_publish(log_type, crawler, video_dict, oss_endpoint, env)
 
-                    Common.logger(log_type, crawler).info('随机休眠 0-60 秒\n')
-                    time.sleep(random.randint(0, 60))
+                    Common.logger(log_type, crawler).info('随机休眠 60-60*3 秒\n')
+                    time.sleep(random.randint(60, 60*3))
         except Exception as e:
             Common.logger(log_type, crawler).error("get_videoList异常:{}\n", e)
 
@@ -498,14 +500,14 @@ class GongzhonghaoFollow2:
                 Common.logger(log_type, crawler).info(f'获取 {user_name} 公众号视频\n')
                 cls.get_videoList(log_type, crawler, user_name, index, oss_endpoint, env)
                 cls.begin = 0
-                Common.logger(log_type, crawler).info('随机休眠 0-60 秒\n')
-                time.sleep(random.randint(0, 60))
+                Common.logger(log_type, crawler).info('随机休眠 60-60*3 秒\n')
+                time.sleep(random.randint(60, 60*3))
         except Exception as e:
             Common.logger(log_type, crawler).info(f'get_all_videos异常:{e}\n')
 
 
 if __name__ == "__main__":
-    GongzhonghaoFollow2.get_users()
+    GongzhonghaoFollow3.get_users()
     # GongzhonghaoFollow.get_users()
     # GongzhonghaoFollow.get_videoList(log_type="follow",
     #                                  crawler="gongzhonghao",

+ 15 - 18
gongzhonghao/gongzhonghao_main/run_gongzhonghao_follow.py

@@ -4,7 +4,6 @@
 import argparse
 import os
 import sys
-import time
 sys.path.append(os.getcwd())
 from common.common import Common
 from gongzhonghao.gongzhonghao_follow.gongzhonghao_follow import GongzhonghaoFollow
@@ -13,23 +12,21 @@ from gongzhonghao.gongzhonghao_follow.gongzhonghao_follow import GongzhonghaoFol
 class Main:
     @classmethod
     def main(cls, log_type, crawler, env):
-        while True:
-            try:
-                if env == "dev":
-                    oss_endpoint = "out"
-                else:
-                    oss_endpoint = "inner"
-                Common.logger(log_type, crawler).info('开始抓取公众号视频\n')
-                GongzhonghaoFollow.get_all_videos(log_type=log_type,
-                                                  crawler=crawler,
-                                                  oss_endpoint=oss_endpoint,
-                                                  env=env)
-                Common.del_logs(log_type, crawler)
-                GongzhonghaoFollow.begin = 0
-                Common.logger(log_type, crawler).info('休眠 8 小时\n')
-                time.sleep(3600*8)
-            except Exception as e:
-                Common.logger(log_type, crawler).info(f"公众号抓取异常:{e}\n")
+        try:
+            if env == "dev":
+                oss_endpoint = "out"
+            else:
+                oss_endpoint = "inner"
+            Common.logger(log_type, crawler).info('开始抓取公众号视频\n')
+            GongzhonghaoFollow.get_all_videos(log_type=log_type,
+                                              crawler=crawler,
+                                              oss_endpoint=oss_endpoint,
+                                              env=env)
+            Common.del_logs(log_type, crawler)
+            GongzhonghaoFollow.begin = 0
+            Common.logger(log_type, crawler).info('公众号抓取一轮完毕\n')
+        except Exception as e:
+            Common.logger(log_type, crawler).info(f"公众号抓取异常:{e}\n")
 
 
 if __name__ == '__main__':

+ 15 - 18
gongzhonghao/gongzhonghao_main/run_gongzhonghao_follow_2.py

@@ -4,7 +4,6 @@
 import argparse
 import os
 import sys
-import time
 sys.path.append(os.getcwd())
 from common.common import Common
 from gongzhonghao.gongzhonghao_follow.gongzhonghao_follow_2 import GongzhonghaoFollow2
@@ -13,23 +12,21 @@ from gongzhonghao.gongzhonghao_follow.gongzhonghao_follow_2 import GongzhonghaoF
 class Main:
     @classmethod
     def main(cls, log_type, crawler, env):
-        while True:
-            try:
-                if env == "dev":
-                    oss_endpoint = "out"
-                else:
-                    oss_endpoint = "inner"
-                Common.logger(log_type, crawler).info('开始抓取公众号视频\n')
-                GongzhonghaoFollow2.get_all_videos(log_type=log_type,
-                                                   crawler=crawler,
-                                                   oss_endpoint=oss_endpoint,
-                                                   env=env)
-                Common.del_logs(log_type, crawler)
-                GongzhonghaoFollow2.begin = 0
-                Common.logger(log_type, crawler).info('休眠 8 小时\n')
-                time.sleep(3600*8)
-            except Exception as e:
-                Common.logger(log_type, crawler).info(f"公众号抓取异常:{e}\n")
+        try:
+            if env == "dev":
+                oss_endpoint = "out"
+            else:
+                oss_endpoint = "inner"
+            Common.logger(log_type, crawler).info('开始抓取公众号视频\n')
+            GongzhonghaoFollow2.get_all_videos(log_type=log_type,
+                                               crawler=crawler,
+                                               oss_endpoint=oss_endpoint,
+                                               env=env)
+            Common.del_logs(log_type, crawler)
+            GongzhonghaoFollow2.begin = 0
+            Common.logger(log_type, crawler).info('公众号抓取一轮完毕\n')
+        except Exception as e:
+            Common.logger(log_type, crawler).info(f"公众号抓取异常:{e}\n")
 
 
 if __name__ == '__main__':

+ 40 - 0
gongzhonghao/gongzhonghao_main/run_gongzhonghao_follow_3.py

@@ -0,0 +1,40 @@
+# -*- coding: utf-8 -*-
+# @Author: wangkun
+# @Time: 2023/3/28
+import argparse
+import os
+import sys
+sys.path.append(os.getcwd())
+from common.common import Common
+from gongzhonghao.gongzhonghao_follow.gongzhonghao_follow_3 import GongzhonghaoFollow3
+
+
+class Main:
+    @classmethod
+    def main(cls, log_type, crawler, env):
+        try:
+            if env == "dev":
+                oss_endpoint = "out"
+            else:
+                oss_endpoint = "inner"
+            Common.logger(log_type, crawler).info('开始抓取公众号视频\n')
+            GongzhonghaoFollow3.get_all_videos(log_type=log_type,
+                                               crawler=crawler,
+                                               oss_endpoint=oss_endpoint,
+                                               env=env)
+            Common.del_logs(log_type, crawler)
+            GongzhonghaoFollow3.begin = 0
+            Common.logger(log_type, crawler).info('公众号抓取一轮完毕\n')
+        except Exception as e:
+            Common.logger(log_type, crawler).info(f"公众号抓取异常:{e}\n")
+
+
+if __name__ == '__main__':
+    parser = argparse.ArgumentParser()  ## 新建参数解释器对象
+    parser.add_argument('--log_type', type=str)  ## 添加参数,注明参数类型
+    parser.add_argument('--crawler')  ## 添加参数
+    parser.add_argument('--env')  ## 添加参数
+    args = parser.parse_args()  ### 参数赋值,也可以通过终端赋值
+    Main.main(log_type=args.log_type,
+              crawler=args.crawler,
+              env=args.env)

+ 21 - 22
main/process.sh

@@ -17,11 +17,11 @@ else
   log_path=${piaoquan_crawler_dir}main/main_logs/process-$(date +%Y-%m-%d).log
 fi
 
-echo "$(date "+%Y-%m-%d %H:%M:%S") 开始监测爬虫进程状态\n" >> ${log_path}
+echo "$(date "+%Y-%m-%d %H:%M:%S") 开始监测爬虫进程状态" >> ${log_path}
 
 echo "$(date "+%Y-%m-%d %H:%M:%S") 更新环境变量..." >> ${log_path}
 cd ~ && source /etc/profile
-echo "$(date "+%Y-%m-%d %H:%M:%S") 更新环境变量完成!\n" >> ${log_path}
+echo "$(date "+%Y-%m-%d %H:%M:%S") 更新环境变量完成!" >> ${log_path}
 
 # 公众号爬虫策略
 echo "$(date "+%Y-%m-%d %H:%M:%S") 正在监测 公众号爬虫策略1-40个账号 进程状态" >> ${log_path}
@@ -33,9 +33,9 @@ if [ "$?" -eq 1 ];then
   else
     cd ${piaoquan_crawler_dir} && /usr/bin/sh /data5/piaoquan_crawler/main/scheduling_main.sh ./gongzhonghao/gongzhonghao_main/run_gongzhonghao_follow.py --log_type="follow" --crawler="gongzhonghao" --env="prod"  gongzhonghao/nohup-follow.log
   fi
-  echo "$(date "+%Y-%m-%d %H:%M:%S") 重启完成!\n" >> ${log_path}
+  echo "$(date "+%Y-%m-%d %H:%M:%S") 重启完成!" >> ${log_path}
 else
-  echo "$(date "+%Y-%m-%d %H:%M:%S") 公众号爬虫策略1-40个账号 进程状态正常\n" >> ${log_path}
+  echo "$(date "+%Y-%m-%d %H:%M:%S") 公众号爬虫策略1-40个账号 进程状态正常" >> ${log_path}
 fi
 
 echo "$(date "+%Y-%m-%d %H:%M:%S") 正在监测 公众号爬虫策略41-81个账号 进程状态" >> ${log_path}
@@ -47,9 +47,9 @@ if [ "$?" -eq 1 ];then
   else
     cd ${piaoquan_crawler_dir} && /usr/bin/sh /data5/piaoquan_crawler/main/scheduling_main.sh ./gongzhonghao/gongzhonghao_main/run_gongzhonghao_follow_2.py --log_type="follow-2" --crawler="gongzhonghao" --env="prod"  gongzhonghao/nohup-follow-2.log
   fi
-  echo "$(date "+%Y-%m-%d %H:%M:%S") 重启完成!\n" >> ${log_path}
+  echo "$(date "+%Y-%m-%d %H:%M:%S") 重启完成!" >> ${log_path}
 else
-  echo "$(date "+%Y-%m-%d %H:%M:%S") 公众号爬虫策略41-81个账号 进程状态正常\n" >> ${log_path}
+  echo "$(date "+%Y-%m-%d %H:%M:%S") 公众号爬虫策略41-81个账号 进程状态正常" >> ${log_path}
 fi
 
 echo "$(date "+%Y-%m-%d %H:%M:%S") 正在监测 公众号爬虫策略81-121个账号 进程状态" >> ${log_path}
@@ -61,12 +61,11 @@ if [ "$?" -eq 1 ];then
   else
     cd ${piaoquan_crawler_dir} && /usr/bin/sh /data5/piaoquan_crawler/main/scheduling_main.sh ./gongzhonghao/gongzhonghao_main/run_gongzhonghao_follow_3.py --log_type="follow-3" --crawler="gongzhonghao" --env="prod"  gongzhonghao/nohup-follow-3.log
   fi
-  echo "$(date "+%Y-%m-%d %H:%M:%S") 重启完成!\n" >> ${log_path}
+  echo "$(date "+%Y-%m-%d %H:%M:%S") 重启完成!" >> ${log_path}
 else
-  echo "$(date "+%Y-%m-%d %H:%M:%S") 公众号爬虫策略81-121个账号 进程状态正常\n" >> ${log_path}
+  echo "$(date "+%Y-%m-%d %H:%M:%S") 公众号爬虫策略81-121个账号 进程状态正常" >> ${log_path}
 fi
 
-
 # 小年糕定向爬虫策略
 echo "$(date "+%Y-%m-%d %H:%M:%S") 正在监测 小年糕定向爬虫策略 进程状态" >> ${log_path}
 ps -ef | grep "run_xiaoniangao_follow.py" | grep -v "grep"
@@ -77,9 +76,9 @@ if [ "$?" -eq 1 ];then
   else
     cd ${piaoquan_crawler_dir} && /usr/bin/sh /data5/piaoquan_crawler/main/scheduling_main.sh ./xiaoniangao/xiaoniangao_main/run_xiaoniangao_follow.py --log_type="follow" --crawler="xiaoniangao" --env="prod"  xiaoniangao/nohup-follow.log
   fi
-  echo "$(date "+%Y-%m-%d %H:%M:%S") 重启完成!\n" >> ${log_path}
+  echo "$(date "+%Y-%m-%d %H:%M:%S") 重启完成!" >> ${log_path}
 else
-  echo "$(date "+%Y-%m-%d %H:%M:%S") 小年糕定向爬虫策略 进程状态正常\n" >> ${log_path}
+  echo "$(date "+%Y-%m-%d %H:%M:%S") 小年糕定向爬虫策略 进程状态正常" >> ${log_path}
 fi
 
 # 小年糕小时榜爬虫策略
@@ -92,9 +91,9 @@ if [ "$?" -eq 1 ];then
   else
     cd ${piaoquan_crawler_dir} && /usr/bin/sh /data5/piaoquan_crawler/main/scheduling_main.sh ./xiaoniangao/xiaoniangao_main/run_xiaoniangao_hour.py --log_type="hour" --crawler="xiaoniangao" --env="prod" xiaoniangao/nohup-hour.log
   fi
-  echo "$(date "+%Y-%m-%d %H:%M:%S") 重启完成!\n" >> ${log_path}
+  echo "$(date "+%Y-%m-%d %H:%M:%S") 重启完成!" >> ${log_path}
 else
-  echo "$(date "+%Y-%m-%d %H:%M:%S") 小年糕小时榜爬虫策略 进程状态正常\n" >> ${log_path}
+  echo "$(date "+%Y-%m-%d %H:%M:%S") 小年糕小时榜爬虫策略 进程状态正常" >> ${log_path}
 fi
 
 # 播放量榜爬虫策略
@@ -107,9 +106,9 @@ if [ "$?" -eq 1 ];then
   else
     cd ${piaoquan_crawler_dir} && /usr/bin/sh /data5/piaoquan_crawler/main/scheduling_main.sh ./xiaoniangao/xiaoniangao_main/run_xiaoniangao_play.py --log_type="play" --crawler="xiaoniangao" --env="prod" xiaoniangao/nohup-play.log
   fi
-  echo "$(date "+%Y-%m-%d %H:%M:%S") 重启完成!\n" >> ${log_path}
+  echo "$(date "+%Y-%m-%d %H:%M:%S") 重启完成!" >> ${log_path}
 else
-  echo "$(date "+%Y-%m-%d %H:%M:%S") 播放量榜爬虫策略 进程状态正常\n" >> ${log_path}
+  echo "$(date "+%Y-%m-%d %H:%M:%S") 播放量榜爬虫策略 进程状态正常" >> ${log_path}
 fi
 
 # 快手定向爬虫策略
@@ -122,9 +121,9 @@ if [ "$?" -eq 1 ];then
   else
     cd ${piaoquan_crawler_dir} && /usr/bin/sh ./main/main.sh ./kuaishou/kuaishou_main/run_kuaishou_follow.py --log_type="follow" --crawler="kuaishou" --strategy="定向爬虫策略" --oss_endpoint="inner" --env="prod" --machine="aliyun" kuaishou/follow.log
   fi
-  echo "$(date "+%Y-%m-%d %H:%M:%S") 重启完成!\n" >> ${log_path}
+  echo "$(date "+%Y-%m-%d %H:%M:%S") 重启完成!" >> ${log_path}
 else
-  echo "$(date "+%Y-%m-%d %H:%M:%S") 快手定向爬虫策略 进程状态正常\n" >> ${log_path}
+  echo "$(date "+%Y-%m-%d %H:%M:%S") 快手定向爬虫策略 进程状态正常" >> ${log_path}
 fi
 
 # 西瓜定向爬虫策略
@@ -137,9 +136,9 @@ if [ "$?" -eq 1 ];then
   else
     cd ${piaoquan_crawler_dir} && /usr/bin/sh ./main/main.sh ./xigua/xigua_main/run_xigua_follow.py --log_type="follow" --crawler="xigua" --strategy="定向爬虫策略" --oss_endpoint="inner" --env="prod" --machine="aliyun" xigua/follow.log
   fi
-  echo "$(date "+%Y-%m-%d %H:%M:%S") 重启完成!\n" >> ${log_path}
+  echo "$(date "+%Y-%m-%d %H:%M:%S") 重启完成!" >> ${log_path}
 else
-  echo "$(date "+%Y-%m-%d %H:%M:%S") 西瓜定向爬虫策略 进程状态正常\n" >> ${log_path}
+  echo "$(date "+%Y-%m-%d %H:%M:%S") 西瓜定向爬虫策略 进程状态正常" >> ${log_path}
 fi
 
 
@@ -153,14 +152,14 @@ if [ "$?" -eq 1 ];then
   else
     cd ${piaoquan_crawler_dir} && /usr/bin/sh ./main/main.sh ./youtube/youtube_main/run_youtube_follow.py --log_type="follow" --crawler="youtube" --strategy="定向爬虫策略" --oss_endpoint="hk" --env="prod" --machine="aliyun_hk" youtube/follow.log
   fi
-  echo "$(date "+%Y-%m-%d %H:%M:%S") 重启完成!\n" >> ${log_path}
+  echo "$(date "+%Y-%m-%d %H:%M:%S") 重启完成!" >> ${log_path}
 else
-  echo "$(date "+%Y-%m-%d %H:%M:%S") youtube定向爬虫策略 进程状态正常\n" >> ${log_path}
+  echo "$(date "+%Y-%m-%d %H:%M:%S") youtube定向爬虫策略 进程状态正常" >> ${log_path}
 fi
 
 
 # 删除日志
 echo "$(date "+%Y-%m-%d %H:%M:%S") 开始清理 5 天前的日志文件" >> ${log_path}
 find ${piaoquan_crawler_dir}main/main_logs/ -mtime +5 -name "*.log" -exec rm -rf {} \;
-echo "$(date "+%Y-%m-%d %H:%M:%S") 日志文件清理完毕\n" >> ${log_path}
+echo "$(date "+%Y-%m-%d %H:%M:%S") 日志文件清理完毕" >> ${log_path}
 exit 0