|
@@ -12,6 +12,78 @@ from main.feishu_lib import Feishu
|
|
|
|
|
|
|
|
|
|
class Bot:
|
|
class Bot:
|
|
|
|
+ # # 获取各个爬虫的 feeds 表
|
|
|
|
+ # @classmethod
|
|
|
|
+ # def get_feeds_sheet(cls, log_type, crawler, sheet):
|
|
|
|
+ # try:
|
|
|
|
+ # if crawler == "kanyikan" and sheet == "recommend":
|
|
|
|
+ # feeds_sheet = Feishu.get_values_batch(log_type, "kanyikan", "SdCHOM")
|
|
|
|
+ # elif crawler == "kanyikan" and sheet == "moment":
|
|
|
|
+ # feeds_sheet = Feishu.get_values_batch(log_type, "kanyikan", "tGqZMX")
|
|
|
|
+ # elif crawler == "xiaoniangao" and sheet == "hour":
|
|
|
|
+ # feeds_sheet = Feishu.get_values_batch(log_type, "xiaoniangao", "ba0da4")
|
|
|
|
+ # elif crawler == "xiaoniangao" and sheet == "person":
|
|
|
|
+ # feeds_sheet = Feishu.get_values_batch(log_type, "xiaoniangao", "k6ldje")
|
|
|
|
+ # elif crawler == "music_album" and sheet == "recommend":
|
|
|
|
+ # feeds_sheet = Feishu.get_values_batch(log_type, "music_album", "69UxPo")
|
|
|
|
+ # elif crawler == "bszf" and sheet == "recommend":
|
|
|
|
+ # feeds_sheet = Feishu.get_values_batch(log_type, "bszf", "CcHgO7")
|
|
|
|
+ # elif crawler == "kuaishou" and sheet == "recommend":
|
|
|
|
+ # feeds_sheet = Feishu.get_values_batch(log_type, "kuaishou", "JK6npf")
|
|
|
|
+ # elif crawler == "kuaishou" and sheet == "follow":
|
|
|
|
+ # feeds_sheet = Feishu.get_values_batch(log_type, "kuaishou", "wW5cyb")
|
|
|
|
+ # elif crawler == "gzh" and sheet == "recommend":
|
|
|
|
+ # feeds_sheet = Feishu.get_values_batch(log_type, "gzh", "zWKFGb")
|
|
|
|
+ # elif crawler == "weishi" and sheet == "recommend":
|
|
|
|
+ # feeds_sheet = Feishu.get_values_batch(log_type, "weishi", "O7fCzr")
|
|
|
|
+ # else:
|
|
|
|
+ # feeds_sheet = "请输入{crawler}和{sheet}"
|
|
|
|
+ #
|
|
|
|
+ # return feeds_sheet
|
|
|
|
+ # except Exception as e:
|
|
|
|
+ # Common.logger(log_type).error("get_feeds_sheet异常:{}", e)
|
|
|
|
+ #
|
|
|
|
+ # # feeds_sheet表报警:连续 2 小时无数据
|
|
|
|
+ # @classmethod
|
|
|
|
+ # def rebot_feeds_sheet(cls, log_type, crawler, sheet):
|
|
|
|
+ # """
|
|
|
|
+ # 每隔一分钟获取一次表数据的数量:
|
|
|
|
+ # 1.中途有数据时,退出此次监控
|
|
|
|
+ # 2.连续2小时无数据时,触发机器人报警
|
|
|
|
+ # """
|
|
|
|
+ # # kanyikan_recommend_sheet = Feishu.get_values_batch(log_type, "kanyikan", "SdCHOM")
|
|
|
|
+ # # kanyikan_moment_sheet = Feishu.get_values_batch(log_type, "kanyikan", "tGqZMX")
|
|
|
|
+ # # xiaoniangao_hour_sheet = Feishu.get_values_batch(log_type, "xiaoniangao", "ba0da4")
|
|
|
|
+ # # xiaoniangao_person_sheet = Feishu.get_values_batch(log_type, "xiaoniangao", "k6ldje")
|
|
|
|
+ # # music_album_recommend_sheet = Feishu.get_values_batch(log_type, "music_album", "69UxPo")
|
|
|
|
+ # # bszf_recommend_sheet = Feishu.get_values_batch(log_type, "bszf", "CcHgO7")
|
|
|
|
+ # # kuaishou_recommend_sheet = Feishu.get_values_batch(log_type, "kuaishou", "JK6npf")
|
|
|
|
+ # # kuaishou_follow_sheet = Feishu.get_values_batch(log_type, "kuaishou", "wW5cyb")
|
|
|
|
+ # # gzh_recommend_sheet = Feishu.get_values_batch(log_type, "gzh", "zWKFGb")
|
|
|
|
+ #
|
|
|
|
+ # for i in range(120):
|
|
|
|
+ # if len(cls.get_feeds_sheet(log_type, crawler, sheet)) > 1:
|
|
|
|
+ # break
|
|
|
|
+ # else:
|
|
|
|
+ # time.sleep(60)
|
|
|
|
+ # if i == 119 and crawler == "kanyikan" and sheet == "recommend":
|
|
|
|
+ # Feishu.bot(log_type, "kanyikan", "看一看推荐榜表,已经 2 小时无数据了😤")
|
|
|
|
+ # elif i == 119 and crawler == "kanyikan" and sheet == "moment":
|
|
|
|
+ # Feishu.bot(log_type, "kanyikan", "看一看朋友圈表,已经 2 小时无数据了😤")
|
|
|
|
+ # elif i == 119 and crawler == "xiaoniangao" and sheet == "person":
|
|
|
|
+ # Feishu.bot(log_type, "xiaoniangao", "小年糕用户主页表,已经 2 小时无数据了😤")
|
|
|
|
+ # elif i == 119 and crawler == "music_album" \
|
|
|
|
+ # and sheet == "recommend" and datetime.datetime.now().hour < 13:
|
|
|
|
+ # Feishu.bot(log_type, "music_album", "音乐相册推荐表,已经 2 小时无数据了😤")
|
|
|
|
+ # elif i == 119 and crawler == "bszf" and sheet == "recommend" and datetime.datetime.now().hour < 13:
|
|
|
|
+ # Feishu.bot(log_type, "bszf", "本山祝福推荐表,已经 2 小时无数据了😤")
|
|
|
|
+ # elif i == 119 and crawler == "kuaishou" and sheet == "recommend":
|
|
|
|
+ # Feishu.bot(log_type, "kuaishou", "快手推荐表,已经 2 小时无数据了😤")
|
|
|
|
+ # elif i == 119 and crawler == "kuaishou" and sheet == "follow":
|
|
|
|
+ # Feishu.bot(log_type, "kuaishou", "快手关注表,已经 2 小时无数据了😤")
|
|
|
|
+ # elif i == 119 and crawler == "gzh" and sheet == "recommend":
|
|
|
|
+ # Feishu.bot(log_type, "gzh", "公众号推荐表,已经 2 小时无数据了😤")
|
|
|
|
+
|
|
# 获取各个爬虫表最新一条抓取时间
|
|
# 获取各个爬虫表最新一条抓取时间
|
|
@classmethod
|
|
@classmethod
|
|
def get_first_time(cls, log_type, crawler):
|
|
def get_first_time(cls, log_type, crawler):
|
|
@@ -32,6 +104,17 @@ class Bot:
|
|
first_download_time = sheet[1][5]
|
|
first_download_time = sheet[1][5]
|
|
first_download_time = int(time.mktime(time.strptime(first_download_time, "%Y/%m/%d %H:%M:%S")))
|
|
first_download_time = int(time.mktime(time.strptime(first_download_time, "%Y/%m/%d %H:%M:%S")))
|
|
|
|
|
|
|
|
+ elif crawler == 'xigua_video':
|
|
|
|
+ sheet = Feishu.get_values_batch(log_type, "xigua", "e075e9")
|
|
|
|
+ # 已下载表,最新一条视频抓取时间
|
|
|
|
+ first_download_time = sheet[1][5]
|
|
|
|
+ first_download_time = int(time.mktime(time.strptime(first_download_time, "%Y/%m/%d %H:%M:%S")))
|
|
|
|
+ elif crawler == 'xigua_little_video':
|
|
|
|
+ sheet = Feishu.get_values_batch(log_type, "xigua", "hDSDnv")
|
|
|
|
+ # 已下载表,最新一条视频抓取时间
|
|
|
|
+ first_download_time = sheet[1][5]
|
|
|
|
+ first_download_time = int(time.mktime(time.strptime(first_download_time, "%Y/%m/%d %H:%M:%S")))
|
|
|
|
+
|
|
elif crawler == "kanyikan":
|
|
elif crawler == "kanyikan":
|
|
sheet = Feishu.get_values_batch(log_type, "kanyikan", "20ce0c")
|
|
sheet = Feishu.get_values_batch(log_type, "kanyikan", "20ce0c")
|
|
# 已下载表,最新一条视频抓取时间
|
|
# 已下载表,最新一条视频抓取时间
|
|
@@ -90,78 +173,6 @@ class Bot:
|
|
except Exception as e:
|
|
except Exception as e:
|
|
Common.logger(log_type).error("get_first_time异常:{}\n", e)
|
|
Common.logger(log_type).error("get_first_time异常:{}\n", e)
|
|
|
|
|
|
- # 获取各个爬虫的 feeds 表
|
|
|
|
- @classmethod
|
|
|
|
- def get_feeds_sheet(cls, log_type, crawler, sheet):
|
|
|
|
- try:
|
|
|
|
- if crawler == "kanyikan" and sheet == "recommend":
|
|
|
|
- feeds_sheet = Feishu.get_values_batch(log_type, "kanyikan", "SdCHOM")
|
|
|
|
- elif crawler == "kanyikan" and sheet == "moment":
|
|
|
|
- feeds_sheet = Feishu.get_values_batch(log_type, "kanyikan", "tGqZMX")
|
|
|
|
- elif crawler == "xiaoniangao" and sheet == "hour":
|
|
|
|
- feeds_sheet = Feishu.get_values_batch(log_type, "xiaoniangao", "ba0da4")
|
|
|
|
- elif crawler == "xiaoniangao" and sheet == "person":
|
|
|
|
- feeds_sheet = Feishu.get_values_batch(log_type, "xiaoniangao", "k6ldje")
|
|
|
|
- elif crawler == "music_album" and sheet == "recommend":
|
|
|
|
- feeds_sheet = Feishu.get_values_batch(log_type, "music_album", "69UxPo")
|
|
|
|
- elif crawler == "bszf" and sheet == "recommend":
|
|
|
|
- feeds_sheet = Feishu.get_values_batch(log_type, "bszf", "CcHgO7")
|
|
|
|
- elif crawler == "kuaishou" and sheet == "recommend":
|
|
|
|
- feeds_sheet = Feishu.get_values_batch(log_type, "kuaishou", "JK6npf")
|
|
|
|
- elif crawler == "kuaishou" and sheet == "follow":
|
|
|
|
- feeds_sheet = Feishu.get_values_batch(log_type, "kuaishou", "wW5cyb")
|
|
|
|
- elif crawler == "gzh" and sheet == "recommend":
|
|
|
|
- feeds_sheet = Feishu.get_values_batch(log_type, "gzh", "zWKFGb")
|
|
|
|
- elif crawler == "weishi" and sheet == "recommend":
|
|
|
|
- feeds_sheet = Feishu.get_values_batch(log_type, "weishi", "O7fCzr")
|
|
|
|
- else:
|
|
|
|
- feeds_sheet = "请输入{crawler}和{sheet}"
|
|
|
|
-
|
|
|
|
- return feeds_sheet
|
|
|
|
- except Exception as e:
|
|
|
|
- Common.logger(log_type).error("get_feeds_sheet异常:{}", e)
|
|
|
|
-
|
|
|
|
- # feeds_sheet表报警:连续 2 小时无数据
|
|
|
|
- @classmethod
|
|
|
|
- def rebot_feeds_sheet(cls, log_type, crawler, sheet):
|
|
|
|
- """
|
|
|
|
- 每隔一分钟获取一次表数据的数量:
|
|
|
|
- 1.中途有数据时,退出此次监控
|
|
|
|
- 2.连续2小时无数据时,触发机器人报警
|
|
|
|
- """
|
|
|
|
- # kanyikan_recommend_sheet = Feishu.get_values_batch(log_type, "kanyikan", "SdCHOM")
|
|
|
|
- # kanyikan_moment_sheet = Feishu.get_values_batch(log_type, "kanyikan", "tGqZMX")
|
|
|
|
- # xiaoniangao_hour_sheet = Feishu.get_values_batch(log_type, "xiaoniangao", "ba0da4")
|
|
|
|
- # xiaoniangao_person_sheet = Feishu.get_values_batch(log_type, "xiaoniangao", "k6ldje")
|
|
|
|
- # music_album_recommend_sheet = Feishu.get_values_batch(log_type, "music_album", "69UxPo")
|
|
|
|
- # bszf_recommend_sheet = Feishu.get_values_batch(log_type, "bszf", "CcHgO7")
|
|
|
|
- # kuaishou_recommend_sheet = Feishu.get_values_batch(log_type, "kuaishou", "JK6npf")
|
|
|
|
- # kuaishou_follow_sheet = Feishu.get_values_batch(log_type, "kuaishou", "wW5cyb")
|
|
|
|
- # gzh_recommend_sheet = Feishu.get_values_batch(log_type, "gzh", "zWKFGb")
|
|
|
|
-
|
|
|
|
- for i in range(120):
|
|
|
|
- if len(cls.get_feeds_sheet(log_type, crawler, sheet)) > 1:
|
|
|
|
- break
|
|
|
|
- else:
|
|
|
|
- time.sleep(60)
|
|
|
|
- if i == 119 and crawler == "kanyikan" and sheet == "recommend":
|
|
|
|
- Feishu.bot(log_type, "kanyikan", "看一看推荐榜表,已经 2 小时无数据了😤")
|
|
|
|
- elif i == 119 and crawler == "kanyikan" and sheet == "moment":
|
|
|
|
- Feishu.bot(log_type, "kanyikan", "看一看朋友圈表,已经 2 小时无数据了😤")
|
|
|
|
- elif i == 119 and crawler == "xiaoniangao" and sheet == "person":
|
|
|
|
- Feishu.bot(log_type, "xiaoniangao", "小年糕用户主页表,已经 2 小时无数据了😤")
|
|
|
|
- elif i == 119 and crawler == "music_album" \
|
|
|
|
- and sheet == "recommend" and datetime.datetime.now().hour < 13:
|
|
|
|
- Feishu.bot(log_type, "music_album", "音乐相册推荐表,已经 2 小时无数据了😤")
|
|
|
|
- elif i == 119 and crawler == "bszf" and sheet == "recommend" and datetime.datetime.now().hour < 13:
|
|
|
|
- Feishu.bot(log_type, "bszf", "本山祝福推荐表,已经 2 小时无数据了😤")
|
|
|
|
- elif i == 119 and crawler == "kuaishou" and sheet == "recommend":
|
|
|
|
- Feishu.bot(log_type, "kuaishou", "快手推荐表,已经 2 小时无数据了😤")
|
|
|
|
- elif i == 119 and crawler == "kuaishou" and sheet == "follow":
|
|
|
|
- Feishu.bot(log_type, "kuaishou", "快手关注表,已经 2 小时无数据了😤")
|
|
|
|
- elif i == 119 and crawler == "gzh" and sheet == "recommend":
|
|
|
|
- Feishu.bot(log_type, "gzh", "公众号推荐表,已经 2 小时无数据了😤")
|
|
|
|
-
|
|
|
|
# 触发机器人报警:超过24小时没有新入库的视频
|
|
# 触发机器人报警:超过24小时没有新入库的视频
|
|
@classmethod
|
|
@classmethod
|
|
def robot_download_sheet(cls, log_type, crawler, duration):
|
|
def robot_download_sheet(cls, log_type, crawler, duration):
|
|
@@ -188,6 +199,16 @@ class Bot:
|
|
Feishu.bot(log_type, crawler, "小年糕_播放量_已下载表,超过24小时没有新视频入库了😤")
|
|
Feishu.bot(log_type, crawler, "小年糕_播放量_已下载表,超过24小时没有新视频入库了😤")
|
|
Common.logger(log_type).warning("小年糕_播放量_已下载表,超过24小时没有新视频入库了😤\n")
|
|
Common.logger(log_type).warning("小年糕_播放量_已下载表,超过24小时没有新视频入库了😤\n")
|
|
|
|
|
|
|
|
+ # 西瓜视频
|
|
|
|
+ elif crawler == "xigua_video" and (
|
|
|
|
+ int(time.time()) - cls.get_first_time(log_type, crawler) > int(duration)):
|
|
|
|
+ Feishu.bot(log_type, crawler, "西瓜视频_用户主页_已下载表,超过24小时没有新视频入库了😤")
|
|
|
|
+ Common.logger(log_type).warning("西瓜视频_用户主页_已下载表,超过24小时没有新视频入库了😤\n")
|
|
|
|
+ elif crawler == "xigua_little_video" and (
|
|
|
|
+ int(time.time()) - cls.get_first_time(log_type, crawler) > int(duration)):
|
|
|
|
+ Feishu.bot(log_type, crawler, "西瓜视频_小视频_已下载表,超过24小时没有新视频入库了😤")
|
|
|
|
+ Common.logger(log_type).warning("西瓜视频_小视频_已下载表,超过24小时没有新视频入库了😤\n")
|
|
|
|
+
|
|
# 音乐相册爬虫报警
|
|
# 音乐相册爬虫报警
|
|
elif crawler == "music_album" and (
|
|
elif crawler == "music_album" and (
|
|
int(time.time()) - cls.get_first_time(log_type, crawler) > int(duration)):
|
|
int(time.time()) - cls.get_first_time(log_type, crawler) > int(duration)):
|
|
@@ -247,6 +268,10 @@ class Bot:
|
|
Bot.robot_download_sheet("bot", "xiaoniangao_person", duration)
|
|
Bot.robot_download_sheet("bot", "xiaoniangao_person", duration)
|
|
Bot.robot_download_sheet("bot", "xiaoniangao_play", duration)
|
|
Bot.robot_download_sheet("bot", "xiaoniangao_play", duration)
|
|
|
|
|
|
|
|
+ Common.logger("bot").info("监控西瓜视频已下载表")
|
|
|
|
+ Bot.robot_download_sheet("bot", "xigua_video", duration)
|
|
|
|
+ # Bot.robot_download_sheet("bot", "xigua_little_video", duration)
|
|
|
|
+
|
|
Common.logger("bot").info("监控本山祝福已下载表")
|
|
Common.logger("bot").info("监控本山祝福已下载表")
|
|
Bot.robot_download_sheet("bot", "bszf", duration)
|
|
Bot.robot_download_sheet("bot", "bszf", duration)
|
|
|
|
|
|
@@ -276,5 +301,7 @@ class Bot:
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if __name__ == "__main__":
|
|
- # Bot.robot_download_sheet("bot", "gzh", 10)
|
|
|
|
|
|
+ # Bot.robot_download_sheet("bot", "xigua_video", 1)
|
|
Bot.main()
|
|
Bot.main()
|
|
|
|
+
|
|
|
|
+ pass
|