|  | @@ -5,13 +5,11 @@ import sys
 | 
	
		
			
				|  |  |  import time
 | 
	
		
			
				|  |  |  from appium import webdriver
 | 
	
		
			
				|  |  |  from appium.webdriver.webdriver import WebDriver
 | 
	
		
			
				|  |  | -# from selenium.common import NoSuchElementException
 | 
	
		
			
				|  |  |  from selenium.common.exceptions import NoSuchElementException
 | 
	
		
			
				|  |  |  from selenium.webdriver.common.by import By
 | 
	
		
			
				|  |  |  sys.path.append(os.getcwd())
 | 
	
		
			
				|  |  | -# from crawler_shipinhao.main.common import Common
 | 
	
		
			
				|  |  | -# from crawler_shipinhao.main.feishu_lib import Feishu
 | 
	
		
			
				|  |  |  from main.common import Common
 | 
	
		
			
				|  |  | +from main.publish import Publish
 | 
	
		
			
				|  |  |  from main.feishu_lib import Feishu
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -56,7 +54,7 @@ class Recommend:
 | 
	
		
			
				|  |  |              cls.quit(log_type, driver)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          except Exception as e:
 | 
	
		
			
				|  |  | -            Common.logger(log_type).error('start_wechat异常', e)
 | 
	
		
			
				|  |  | +            Common.logger(log_type).error('start_wechat异常\n', e)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      # 退出 APP
 | 
	
		
			
				|  |  |      @classmethod
 | 
	
	
		
			
				|  | @@ -68,7 +66,7 @@ class Recommend:
 | 
	
		
			
				|  |  |      @staticmethod
 | 
	
		
			
				|  |  |      def download_rule(duration, like_cnt, share_cnt, favorite_cnt, comment_cnt):
 | 
	
		
			
				|  |  |          if int(duration) >= 10:
 | 
	
		
			
				|  |  | -            if int(like_cnt) >= 0:
 | 
	
		
			
				|  |  | +            if int(like_cnt) >= 1000:
 | 
	
		
			
				|  |  |                  if int(share_cnt) >= 0:
 | 
	
		
			
				|  |  |                      if int(favorite_cnt) >= 0:
 | 
	
		
			
				|  |  |                          if int(comment_cnt) >= 0:
 | 
	
	
		
			
				|  | @@ -254,12 +252,119 @@ class Recommend:
 | 
	
		
			
				|  |  |                              driver.swipe(500, 1500, 500, 500, 300)
 | 
	
		
			
				|  |  |                              break
 | 
	
		
			
				|  |  |          except Exception as e:
 | 
	
		
			
				|  |  | -            Common.logger(log_type).error('get_feeds异常', e)
 | 
	
		
			
				|  |  | +            Common.logger(log_type).error('get_feeds异常\n', e)
 | 
	
		
			
				|  |  |              driver.swipe(500, 1500, 500, 500, 300)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    # 下载 、上传
 | 
	
		
			
				|  |  | +    @classmethod
 | 
	
		
			
				|  |  | +    def download_publish(cls, log_type, env):
 | 
	
		
			
				|  |  | +        try:
 | 
	
		
			
				|  |  | +            recommend_feeds_sheet = Feishu.get_values_batch(log_type, 'shipinhao', 'FSDlBy')
 | 
	
		
			
				|  |  | +            for i in range(1, len(recommend_feeds_sheet)):
 | 
	
		
			
				|  |  | +                download_title = recommend_feeds_sheet[i][2].strip().replace('"', '') \
 | 
	
		
			
				|  |  | +                        .replace('“', '').replace('“', '…').replace("\n", "") \
 | 
	
		
			
				|  |  | +                        .replace("/", "").replace("\r", "").replace("#", "") \
 | 
	
		
			
				|  |  | +                        .replace(".", "。").replace("\\", "").replace("&NBSP", "") \
 | 
	
		
			
				|  |  | +                        .replace(":", "").replace("*", "").replace("?", "") \
 | 
	
		
			
				|  |  | +                        .replace("?", "").replace('"', "").replace("<", "") \
 | 
	
		
			
				|  |  | +                        .replace(">", "").replace("|", "").replace(" ", "")
 | 
	
		
			
				|  |  | +                download_duration = recommend_feeds_sheet[i][3]
 | 
	
		
			
				|  |  | +                download_like_cnt = recommend_feeds_sheet[i][4]
 | 
	
		
			
				|  |  | +                download_share_cnt = recommend_feeds_sheet[i][5]
 | 
	
		
			
				|  |  | +                download_favorite_cnt = recommend_feeds_sheet[i][6]
 | 
	
		
			
				|  |  | +                download_comment_cnt = recommend_feeds_sheet[i][7]
 | 
	
		
			
				|  |  | +                download_username = recommend_feeds_sheet[i][8]
 | 
	
		
			
				|  |  | +                download_head_url = recommend_feeds_sheet[i][9]
 | 
	
		
			
				|  |  | +                download_cover_url = recommend_feeds_sheet[i][10]
 | 
	
		
			
				|  |  | +                download_video_url = recommend_feeds_sheet[i][11]
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                Common.logger(log_type).info("download_title:{}", download_title)
 | 
	
		
			
				|  |  | +                Common.logger(log_type).info("download_username:{}", download_username)
 | 
	
		
			
				|  |  | +                Common.logger(log_type).info("download_video_url:{}", download_video_url)
 | 
	
		
			
				|  |  | +                # Common.logger(log_type).info("download_duration:{}", download_duration)
 | 
	
		
			
				|  |  | +                # Common.logger(log_type).info("download_like_cnt:{}", download_like_cnt)
 | 
	
		
			
				|  |  | +                # Common.logger(log_type).info("download_share_cnt:{}", download_share_cnt)
 | 
	
		
			
				|  |  | +                # Common.logger(log_type).info("download_favorite_cnt:{}", download_favorite_cnt)
 | 
	
		
			
				|  |  | +                # Common.logger(log_type).info("download_comment_cnt:{}", download_comment_cnt)
 | 
	
		
			
				|  |  | +                # Common.logger(log_type).info("download_head_url:{}", download_head_url)
 | 
	
		
			
				|  |  | +                # Common.logger(log_type).info("download_cover_url:{}\n", download_cover_url)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                if download_title is None or download_duration is None or download_video_url is None:
 | 
	
		
			
				|  |  | +                    Feishu.dimension_range(log_type, 'shipinhao', 'FSDlBy', 'ROWS', i+1, i+1)
 | 
	
		
			
				|  |  | +                    Common.logger(log_type).info('空行,删除成功\n')
 | 
	
		
			
				|  |  | +                    return
 | 
	
		
			
				|  |  | +                elif str(download_title) in [x for y in Feishu.get_values_batch(log_type, 'shipinhao', 'c77cf9') for x in y]:
 | 
	
		
			
				|  |  | +                    Feishu.dimension_range(log_type, 'shipinhao', 'FSDlBy', 'ROWS', i + 1, i + 1)
 | 
	
		
			
				|  |  | +                    Common.logger(log_type).info('视频已下载,删除成功\n')
 | 
	
		
			
				|  |  | +                    return
 | 
	
		
			
				|  |  | +                else:
 | 
	
		
			
				|  |  | +                    # 下载封面
 | 
	
		
			
				|  |  | +                    Common.download_method(log_type=log_type, text="cover",
 | 
	
		
			
				|  |  | +                                           d_name=str(download_title), d_url=str(download_cover_url))
 | 
	
		
			
				|  |  | +                    # 下载视频
 | 
	
		
			
				|  |  | +                    Common.download_method(log_type=log_type, text="video",
 | 
	
		
			
				|  |  | +                                           d_name=str(download_title), d_url=str(download_video_url))
 | 
	
		
			
				|  |  | +                    # 保存视频信息至 "./videos/{download_video_title}/info.txt"
 | 
	
		
			
				|  |  | +                    with open("./videos/" + download_title
 | 
	
		
			
				|  |  | +                              + "/" + "info.txt", "a", encoding="UTF-8") as f_a:
 | 
	
		
			
				|  |  | +                        f_a.write('shipinhao' + str(int(time.time())) + "\n" +
 | 
	
		
			
				|  |  | +                                  str(download_title) + "\n" +
 | 
	
		
			
				|  |  | +                                  str(download_duration) + "\n" +
 | 
	
		
			
				|  |  | +                                  str(download_favorite_cnt) + "\n" +
 | 
	
		
			
				|  |  | +                                  str(download_comment_cnt) + "\n" +
 | 
	
		
			
				|  |  | +                                  str(download_like_cnt) + "\n" +
 | 
	
		
			
				|  |  | +                                  str(download_share_cnt) + "\n" +
 | 
	
		
			
				|  |  | +                                  str(1920*1080) + "\n" +
 | 
	
		
			
				|  |  | +                                  str(int(time.time())) + "\n" +
 | 
	
		
			
				|  |  | +                                  str(download_username) + "\n" +
 | 
	
		
			
				|  |  | +                                  str(download_head_url) + "\n" +
 | 
	
		
			
				|  |  | +                                  str(download_video_url) + "\n" +
 | 
	
		
			
				|  |  | +                                  str(download_cover_url) + "\n" +
 | 
	
		
			
				|  |  | +                                  "shipinhao")
 | 
	
		
			
				|  |  | +                    Common.logger(log_type).info("==========视频信息已保存至info.txt==========")
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    Common.logger(log_type).info("开始上传视频:{}".format(download_title))
 | 
	
		
			
				|  |  | +                    our_video_id = Publish.upload_and_publish(log_type, env, "play")
 | 
	
		
			
				|  |  | +                    if env == 'dev':
 | 
	
		
			
				|  |  | +                        our_video_link = "https://testadmin.piaoquantv.com/cms/post-detail/" + str(our_video_id) + "/info"
 | 
	
		
			
				|  |  | +                    else:
 | 
	
		
			
				|  |  | +                        our_video_link = "https://admin.piaoquantv.com/cms/post-detail/" + str(our_video_id) + "/info"
 | 
	
		
			
				|  |  | +                    Common.logger(log_type).info("视频上传完成:{}", our_video_link)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    # 视频ID工作表,插入首行
 | 
	
		
			
				|  |  | +                    Feishu.insert_columns(log_type, "shipinhao", "c77cf9", "ROWS", 1, 2)
 | 
	
		
			
				|  |  | +                    # 视频ID工作表,首行写入数据
 | 
	
		
			
				|  |  | +                    upload_time = int(time.time())
 | 
	
		
			
				|  |  | +                    values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(upload_time)),
 | 
	
		
			
				|  |  | +                               "推荐榜",
 | 
	
		
			
				|  |  | +                               str(download_title),
 | 
	
		
			
				|  |  | +                               our_video_link,
 | 
	
		
			
				|  |  | +                               download_duration,
 | 
	
		
			
				|  |  | +                               download_like_cnt,
 | 
	
		
			
				|  |  | +                               download_share_cnt,
 | 
	
		
			
				|  |  | +                               download_favorite_cnt,
 | 
	
		
			
				|  |  | +                               download_comment_cnt,
 | 
	
		
			
				|  |  | +                               download_username,
 | 
	
		
			
				|  |  | +                               str(download_head_url),
 | 
	
		
			
				|  |  | +                               str(download_cover_url),
 | 
	
		
			
				|  |  | +                               str(download_video_url)]]
 | 
	
		
			
				|  |  | +                    time.sleep(1)
 | 
	
		
			
				|  |  | +                    Feishu.update_values(log_type, "shipinhao", "c77cf9", "F2:V2", values)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    # 删除行或列,可选 ROWS、COLUMNS
 | 
	
		
			
				|  |  | +                    time.sleep(1)
 | 
	
		
			
				|  |  | +                    Feishu.dimension_range(log_type, "shipinhao", "FSDlBy", "ROWS", i + 1, i + 1)
 | 
	
		
			
				|  |  | +                    Common.logger(log_type).info("下载/上传成功:{}\n", download_title)
 | 
	
		
			
				|  |  | +                    return
 | 
	
		
			
				|  |  | +        except Exception as e:
 | 
	
		
			
				|  |  | +            Feishu.dimension_range(log_type, "shipinhao", "FSDlBy", "ROWS", 2, 2)
 | 
	
		
			
				|  |  | +            Common.logger(log_type).error('download_publish异常,删除视频信息成功:{}\n', e)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  if __name__ == '__main__':
 | 
	
		
			
				|  |  | -    Recommend.start_wechat('recommend')
 | 
	
		
			
				|  |  | +    # Recommend.start_wechat('recommend')
 | 
	
		
			
				|  |  |      # print(Feishu.get_values_batch('log_type', 'shipinhao', 'FSDlBy')[1][11])
 | 
	
		
			
				|  |  | +    Recommend.download_publish('recommend', 'dev')
 | 
	
		
			
				|  |  | +    Publish.upload_and_publish('recommend', 'dev', "play")
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      pass
 |