xiaoniangao_follow.py 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. # -*- coding: utf-8 -*-
  2. # @Author: wangkun
  3. # @Time: 2023/3/13
  4. import json
  5. import os
  6. import random
  7. import shutil
  8. import sys
  9. import time
  10. import requests
  11. import urllib3
  12. sys.path.append(os.getcwd())
  13. from common.common import Common
  14. from common.scheduling_db import MysqlHelper
  15. from common.publish import Publish
  16. from common.feishu import Feishu
  17. from common.public import filter_word
  18. proxies = {"http": None, "https": None}
  19. class XiaoniangaoFollow:
  20. platform = "小年糕"
  21. # 小程序个人主页视频列表翻页参数
  22. next_t = None
  23. # 基础门槛规则
  24. @staticmethod
  25. def download_rule(video_dict):
  26. """
  27. 下载视频的基本规则
  28. :param video_dict: 视频信息,字典格式
  29. :return: 满足规则,返回 True;反之,返回 False
  30. """
  31. # 视频时长
  32. if int(float(video_dict['duration'])) >= 40:
  33. # 宽或高
  34. if int(video_dict['video_width']) >= 0 or int(video_dict['video_height']) >= 0:
  35. # 播放量
  36. if int(video_dict['play_cnt']) >= 500:
  37. # 分享量
  38. if int(video_dict['share_cnt']) >= 0:
  39. return True
  40. else:
  41. return False
  42. else:
  43. return False
  44. else:
  45. return False
  46. else:
  47. return False
  48. # 从云文档获取关注用户列表
  49. @classmethod
  50. def get_users(cls):
  51. # follow_sheet = Feishu.get_values_batch("follow", "xiaoniangao", "oNpThi")
  52. # user_list = []
  53. # for i in range(1, len(follow_sheet)):
  54. # profile_id = follow_sheet[i][0]
  55. # profile_mid = follow_sheet[i][1]
  56. # user_name = follow_sheet[i][2]
  57. # user_dict = {
  58. # "profile_id": str(profile_id),
  59. # "profile_mid": str(profile_mid),
  60. # "user_name": user_name,
  61. # }
  62. # user_list.append(user_dict)
  63. # print(len(user_list))
  64. # print(user_list)
  65. user_list = [{'profile_id': '43549964', 'profile_mid': '116311065', 'user_name': '青峰明月老人'}, {'profile_id': '43486474', 'profile_mid': '1113556014', 'user_name': '好人一生平安'}, {'profile_id': '43590330', 'profile_mid': '192501730', 'user_name': '风轻云淡'}, {'profile_id': '43559741', 'profile_mid': '90261331', 'user_name': '歌一曲'}, {'profile_id': '43785654', 'profile_mid': '104703232', 'user_name': '涧欣'}, {'profile_id': '44211463', 'profile_mid': '1149063512', 'user_name': '美食分享'}, {'profile_id': '46661040', 'profile_mid': '293457861', 'user_name': '阿妞'}, {'profile_id': '46731019', 'profile_mid': '1059483000', 'user_name': '早睡早起锻炼身体'}, {'profile_id': '46644244', 'profile_mid': '609255292', 'user_name': '雨太漫长'}, {'profile_id': '46553912', 'profile_mid': '1160417287', 'user_name': '葛锡琴'}, {'profile_id': '46802824', 'profile_mid': '1157645694', 'user_name': '留白'}, {'profile_id': '46795509', 'profile_mid': '1161593368', 'user_name': '绒花漫舞'}, {'profile_id': '46837469', 'profile_mid': '1160417275', 'user_name': '苏超灵'}, {'profile_id': '46830553', 'profile_mid': '1160417336', 'user_name': '山里红'}, {'profile_id': '50541284', 'profile_mid': '1210725734', 'user_name': '语琴'}, {'profile_id': '50541428', 'profile_mid': '1222976096', 'user_name': '血性娘子'}, {'profile_id': '50364411', 'profile_mid': '1192924729', 'user_name': '好运莲莲'}, {'profile_id': '50499182', 'profile_mid': '329676836', 'user_name': '花好月圆'}, {'profile_id': '50449938', 'profile_mid': '341183833', 'user_name': '花开富贵'}, {'profile_id': '50199770', 'profile_mid': '1166029432', 'user_name': '兰花草1'}, {'profile_id': '50299362', 'profile_mid': '1013092427', 'user_name': '感悟人生'}, {'profile_id': '50539176', 'profile_mid': '1203033756', 'user_name': '风之别鹤'}, {'profile_id': '50541092', 'profile_mid': '1237693278', 'user_name': '莲心'}, {'profile_id': '50523015', 'profile_mid': '260159327', 'user_name': '微笑😊123'}, {'profile_id': '50216970', 'profile_mid': '1219153129', 'user_name': '秋夕'}, {'profile_id': '50286181', 'profile_mid': '1113733998', 'user_name': '上善若水'}, {'profile_id': '50505135', 'profile_mid': '185546', 'user_name': '秋水揽星河'}, {'profile_id': '50555007', 'profile_mid': '1113739184', 'user_name': '淡墨青衫'}, {'profile_id': '50500343', 'profile_mid': '1072539904', 'user_name': '微笑向明天'}, {'profile_id': '50628735', 'profile_mid': '1142824266', 'user_name': '清爽'}, {'profile_id': '50580367', 'profile_mid': '26055443', 'user_name': '玉儿Syy'}, {'profile_id': '50585024', 'profile_mid': '1105334217', 'user_name': '老树开花🌸'}, {'profile_id': '50380683', 'profile_mid': '63682047', 'user_name': '海王岛浩哥'}, {'profile_id': '46386724', 'profile_mid': '271535337', 'user_name': '雪梅'}, {'profile_id': '50636398', 'profile_mid': '237071458', 'user_name': '看花人'}, {'profile_id': '50624991', 'profile_mid': '1202244309', 'user_name': '无关风月'}, {'profile_id': '50561528', 'profile_mid': '1134790664', 'user_name': '老有所乐'}, {'profile_id': '50612235', 'profile_mid': '1162974507', 'user_name': '花素千昔'}, {'profile_id': '50933310', 'profile_mid': '1237661365', 'user_name': '淡淡浅香'}, {'profile_id': '50492961', 'profile_mid': '1160417339', 'user_name': '胡淑华'}, {'profile_id': '49965729', 'profile_mid': '1160417117', 'user_name': '百姓生活'}, {'profile_id': '50928693', 'profile_mid': '1163097085', 'user_name': '多福'}, {'profile_id': '50819153', 'profile_mid': '224365299', 'user_name': '欢天喜地'}, {'profile_id': '51510752', 'profile_mid': '1160417314', 'user_name': '郝建兵'}, {'profile_id': '51470002', 'profile_mid': '631317964', 'user_name': '九牛二虎'}, {'profile_id': '51466430', 'profile_mid': '177806025', 'user_name': '越来越好'}, {'profile_id': '51480157', 'profile_mid': '1000526700', 'user_name': '光伯伯'}, {'profile_id': '51396620', 'profile_mid': '1160417243', 'user_name': '亚萍'}, {'profile_id': '51538137', 'profile_mid': '154002316', 'user_name': 'hua jean-pierre 許遵訓'}, {'profile_id': '51533676', 'profile_mid': '197908577', 'user_name': '萍水相逢'}, {'profile_id': '51488254', 'profile_mid': '153685063', 'user_name': '英勇'}, {'profile_id': '51425929', 'profile_mid': '1161593426', 'user_name': '百年字号'}, {'profile_id': '51514370', 'profile_mid': '1198361106', 'user_name': '品味人生'}, {'profile_id': '51405010', 'profile_mid': '1161593390', 'user_name': '低调生活'}, {'profile_id': '51535995', 'profile_mid': '690938173', 'user_name': '世界风'}, {'profile_id': '51468900', 'profile_mid': '1242534599', 'user_name': '人生如茶'}, {'profile_id': '51489772', 'profile_mid': '269038284', 'user_name': '韵律'}, {'profile_id': '51377241', 'profile_mid': '194287386', 'user_name': '霹雳雷天发'}, {'profile_id': '51538527', 'profile_mid': '1064479786', 'user_name': '鑫'}, {'profile_id': '51365161', 'profile_mid': '1161593351', 'user_name': '黄金三十分'}, {'profile_id': '51527297', 'profile_mid': '1163011474', 'user_name': '指日东升'}, {'profile_id': '51356555', 'profile_mid': '76036942', 'user_name': '利剑'}, {'profile_id': '51382702', 'profile_mid': '1160417349', 'user_name': '丽丽'}, {'profile_id': '51536925', 'profile_mid': '1160417133', 'user_name': '福海'}, {'profile_id': '51525148', 'profile_mid': '1160417333', 'user_name': '君子兰'}, {'profile_id': '51530896', 'profile_mid': '1162996019', 'user_name': '你好,朋友'}, {'profile_id': '51532418', 'profile_mid': '1162998153', 'user_name': '旭日东升'}, {'profile_id': '51329950', 'profile_mid': '285062559', 'user_name': '阿静'}, {'profile_id': '51512535', 'profile_mid': '114981390', 'user_name': '泽南'}, {'profile_id': '51480066', 'profile_mid': '1160417334', 'user_name': '克平'}, {'profile_id': '51520908', 'profile_mid': '1161593408', 'user_name': '永生'}, {'profile_id': '51496944', 'profile_mid': '1160417145', 'user_name': '一生快乐'}, {'profile_id': '51511833', 'profile_mid': '1105154277', 'user_name': '老周.物流全国.'}, {'profile_id': '51515937', 'profile_mid': '1178673137', 'user_name': '风起风落'}, {'profile_id': '51539903', 'profile_mid': '1175023459', 'user_name': '花开福贵 &吉祥'}, {'profile_id': '51394812', 'profile_mid': '1160417173', 'user_name': '尔东'}, {'profile_id': '51512298', 'profile_mid': '22171304', 'user_name': '张杰真'}, {'profile_id': '51472642', 'profile_mid': '175855074', 'user_name': '张顺淑'}, {'profile_id': '51548416', 'profile_mid': '1116847111', 'user_name': '沁水百合'}, {'profile_id': '51456595', 'profile_mid': '1075862992', 'user_name': '永保青春'}, {'profile_id': '51502433', 'profile_mid': '1162980250', 'user_name': '午夜想念'}, {'profile_id': '51495781', 'profile_mid': '1162961480', 'user_name': '快乐每一天'}, {'profile_id': '51527180', 'profile_mid': '1161593427', 'user_name': '彩云追月'}, {'profile_id': '51537082', 'profile_mid': '1163005063', 'user_name': '峥嵘岁月'}, {'profile_id': '51510904', 'profile_mid': '64295407', 'user_name': '文文'}, {'profile_id': '51497047', 'profile_mid': '59349938', 'user_name': '老马识途'}, {'profile_id': '51544604', 'profile_mid': '1160417260', 'user_name': '星'}, {'profile_id': '51411909', 'profile_mid': '801020924', 'user_name': '相思鸟'}, {'profile_id': '51525860', 'profile_mid': '1160417222', 'user_name': '老来得福'}, {'profile_id': '51540902', 'profile_mid': '1163003217', 'user_name': '银发中年'}, {'profile_id': '51526760', 'profile_mid': '295640510', 'user_name': '阿中'}, {'profile_id': '51529247', 'profile_mid': '674650199', 'user_name': '张恩培'}, {'profile_id': '51540032', 'profile_mid': '18103420', 'user_name': '吴希孟'}, {'profile_id': '51491818', 'profile_mid': '1162991035', 'user_name': '幸福每一天'}, {'profile_id': '51539843', 'profile_mid': '210721352', 'user_name': '掉地人参果'}, {'profile_id': '51521237', 'profile_mid': '1160417237', 'user_name': '山野村夫'}, {'profile_id': '51531438', 'profile_mid': '103235841', 'user_name': '开心'}, {'profile_id': '51528239', 'profile_mid': '1160417288', 'user_name': '戴玉亭'}, {'profile_id': '51542817', 'profile_mid': '126121769', 'user_name': '芳芳'}, {'profile_id': '51541108', 'profile_mid': '287637208', 'user_name': '心无旁骛'}, {'profile_id': '51462517', 'profile_mid': '247008734', 'user_name': '华'}, {'profile_id': '51543209', 'profile_mid': '1214482340', 'user_name': '丽'}, {'profile_id': '51509548', 'profile_mid': '1162977406', 'user_name': '绚丽多彩'}, {'profile_id': '51536733', 'profile_mid': '1161593366', 'user_name': '夕阳红'}, {'profile_id': '51519407', 'profile_mid': '1122750580', 'user_name': '幸福满堂'}, {'profile_id': '51459413', 'profile_mid': '348958961', 'user_name': '段平清'}, {'profile_id': '51487820', 'profile_mid': '605290310', 'user_name': '青青'}, {'profile_id': '51469080', 'profile_mid': '131475097', 'user_name': '手宝'}, {'profile_id': '51426171', 'profile_mid': '196597807', 'user_name': '妙'}, {'profile_id': '51470293', 'profile_mid': '78386273', 'user_name': '芳草'}, {'profile_id': '51505305', 'profile_mid': '172977522', 'user_name': '伟星'}, {'profile_id': '51541167', 'profile_mid': '1100776170', 'user_name': '闪电⚡️'}, {'profile_id': '51391450', 'profile_mid': '982518039', 'user_name': '吕梁'}, {'profile_id': '51529786', 'profile_mid': '168833501', 'user_name': ':shen. ser'}, {'profile_id': '51416422', 'profile_mid': '376557509', 'user_name': '于孝震'}, {'profile_id': '51342944', 'profile_mid': '556796156', 'user_name': '☀吉祥☀'}, {'profile_id': '51536144', 'profile_mid': '1162956349', 'user_name': '凤舞九天'}, {'profile_id': '51533164', 'profile_mid': '153787914', 'user_name': '红梅'}, {'profile_id': '51450974', 'profile_mid': '20396528', 'user_name': '学友'}, {'profile_id': '51512622', 'profile_mid': '35883962', 'user_name': '珎珎'}, {'profile_id': '51525737', 'profile_mid': '69546032', 'user_name': '欣然'}, {'profile_id': '51414093', 'profile_mid': '1154645646', 'user_name': '老中医'}, {'profile_id': '51372351', 'profile_mid': '154481426', 'user_name': '寻花'}, {'profile_id': '51511869', 'profile_mid': '1162958849', 'user_name': '保持微笑'}, {'profile_id': '51367397', 'profile_mid': '173682337', 'user_name': '莲'}, {'profile_id': '51494361', 'profile_mid': '1161593403', 'user_name': '红叶'}, {'profile_id': '51352260', 'profile_mid': '31040287', 'user_name': '52部队'}, {'profile_id': '51430672', 'profile_mid': '69886497', 'user_name': '张俊宽'}, {'profile_id': '51440076', 'profile_mid': '1186145367', 'user_name': '金光'}, {'profile_id': '51431733', 'profile_mid': '112830331', 'user_name': '幸福安康'}, {'profile_id': '51466969', 'profile_mid': '131962346', 'user_name': '丹桂'}, {'profile_id': '51515739', 'profile_mid': '1162950925', 'user_name': '烈火'}, {'profile_id': '51465625', 'profile_mid': '913804992', 'user_name': '荷塘月色'}, {'profile_id': '51508736', 'profile_mid': '30955754', 'user_name': '硕'}, {'profile_id': '51488704', 'profile_mid': '1160417201', 'user_name': '伴迪伴你'}, {'profile_id': '51514871', 'profile_mid': '1161593379', 'user_name': '心无界'}, {'profile_id': '51517906', 'profile_mid': '1160417268', 'user_name': '宏蕴'}, {'profile_id': '51517169', 'profile_mid': '1163601308', 'user_name': '今日祝福'}, {'profile_id': '51382334', 'profile_mid': '1177277385', 'user_name': '丝花'}, {'profile_id': '51606330', 'profile_mid': '912444460', 'user_name': 'pan'}, {'profile_id': '51574573', 'profile_mid': '18628461', 'user_name': '镇华'}, {'profile_id': '51576665', 'profile_mid': '238020228', 'user_name': '杏子'}, {'profile_id': '51577353', 'profile_mid': '746152129', 'user_name': '南極'}, {'profile_id': '51619591', 'profile_mid': '169107521', 'user_name': '天南海北'}, {'profile_id': '51558453', 'profile_mid': '37660529', 'user_name': '歌哥'}, {'profile_id': '51565261', 'profile_mid': '7455950', 'user_name': '东北人'}, {'profile_id': '51549436', 'profile_mid': '173754665', 'user_name': '68《电波》'}, {'profile_id': '51596064', 'profile_mid': '334594004', 'user_name': '许 霞 客'}, {'profile_id': '51562005', 'profile_mid': '124746031', 'user_name': '新毛笔'}, {'profile_id': '51558760', 'profile_mid': '201200932', 'user_name': '岁月静好'}, {'profile_id': '51534579', 'profile_mid': '5369941', 'user_name': '泾渭分明'}, {'profile_id': '51587605', 'profile_mid': '800143421', 'user_name': '渡我'}, {'profile_id': '51541987', 'profile_mid': '156490323', 'user_name': '三国'}, {'profile_id': '51555616', 'profile_mid': '1160417130', 'user_name': '华山论剑'}, {'profile_id': '51471936', 'profile_mid': '246878924', 'user_name': '孙木木'}, {'profile_id': '51596587', 'profile_mid': '330013250', 'user_name': 'Chungen Ju'}, {'profile_id': '51535749', 'profile_mid': '258896502', 'user_name': '小飞象'}, {'profile_id': '51526063', 'profile_mid': '1160417175', 'user_name': '小段段'}, {'profile_id': '51596980', 'profile_mid': '256733182', 'user_name': '崇正庚'}, {'profile_id': '51475303', 'profile_mid': '130126439', 'user_name': '夕阳余晖'}, {'profile_id': '51579715', 'profile_mid': '1163008965', 'user_name': '大漠驼铃'}, {'profile_id': '51517955', 'profile_mid': '297080453', 'user_name': '蓝天白云'}, {'profile_id': '51579777', 'profile_mid': '146924331', 'user_name': '成绩'}, {'profile_id': '51587711', 'profile_mid': '167255646', 'user_name': '指尖芭蕾'}, {'profile_id': '51574471', 'profile_mid': '193552533', 'user_name': '老战士'}, {'profile_id': '51582228', 'profile_mid': '1161593389', 'user_name': '匆匆人生'}, {'profile_id': '51580109', 'profile_mid': '1162954764', 'user_name': '花开有福'}, {'profile_id': '51576191', 'profile_mid': '583250197', 'user_name': '明月'}, {'profile_id': '51424809', 'profile_mid': '1160417162', 'user_name': '冬雪'}, {'profile_id': '51507365', 'profile_mid': '1160417170', 'user_name': '金鑫'}, {'profile_id': '51504566', 'profile_mid': '1160417277', 'user_name': '熊先生'}, {'profile_id': '51478499', 'profile_mid': '1236785994', 'user_name': '奉祥'}, {'profile_id': '51557117', 'profile_mid': '208885032', 'user_name': '善解人意'}, {'profile_id': '51475483', 'profile_mid': '183839316', 'user_name': 'horse'}, {'profile_id': '51558699', 'profile_mid': '812582794', 'user_name': '김학선'}, {'profile_id': '51543823', 'profile_mid': '1160417172', 'user_name': '日出'}, {'profile_id': '51547046', 'profile_mid': '1160417150', 'user_name': '祥哥'}, {'profile_id': '51569091', 'profile_mid': '162704496', 'user_name': '崔德珍'}, {'profile_id': '51538585', 'profile_mid': '201393573', 'user_name': '李裕年'}, {'profile_id': '51511316', 'profile_mid': '9863172', 'user_name': '红绫'}, {'profile_id': '51517359', 'profile_mid': '428192018', 'user_name': '荷月'}, {'profile_id': '51481801', 'profile_mid': '814090755', 'user_name': '聊歌'}, {'profile_id': '51487330', 'profile_mid': '145093442', 'user_name': '郑明国'}, {'profile_id': '51538353', 'profile_mid': '1216082', 'user_name': '连玩'}, {'profile_id': '51573284', 'profile_mid': '262696881', 'user_name': '远'}, {'profile_id': '51490939', 'profile_mid': '1160417343', 'user_name': '五彩缤纷'}, {'profile_id': '51528852', 'profile_mid': '1160417280', 'user_name': '亚~丽'}, {'profile_id': '51573486', 'profile_mid': '555866418', 'user_name': '荣'}, {'profile_id': '51573150', 'profile_mid': '195922263', 'user_name': '思思'}, {'profile_id': '51536141', 'profile_mid': '2324632', 'user_name': '淡'}, {'profile_id': '51573400', 'profile_mid': '85984018', 'user_name': '石头哥'}, {'profile_id': '51530358', 'profile_mid': '1160417230', 'user_name': '娟'}, {'profile_id': '51423634', 'profile_mid': '1160417366', 'user_name': '洁洁'}, {'profile_id': '51415095', 'profile_mid': '276227387', 'user_name': '十月'}, {'profile_id': '51472794', 'profile_mid': '110333218', 'user_name': '罗月泉'}, {'profile_id': '51434083', 'profile_mid': '16503153', 'user_name': '蓝天白云阳光'}, {'profile_id': '51362428', 'profile_mid': '23276114', 'user_name': '智勇'}, {'profile_id': '51562348', 'profile_mid': '23771415', 'user_name': '老自在'}, {'profile_id': '51527231', 'profile_mid': '32290307', 'user_name': '子龙zyg'}, {'profile_id': '51520025', 'profile_mid': '29017863', 'user_name': '长平'}, {'profile_id': '51567095', 'profile_mid': '410251493', 'user_name': '周小编'}, {'profile_id': '51554155', 'profile_mid': '50262268', 'user_name': 'ㄙ力'}, {'profile_id': '51484880', 'profile_mid': '288147906', 'user_name': '凝雪'}, {'profile_id': '51528645', 'profile_mid': '40442332', 'user_name': '我的'}, {'profile_id': '51546110', 'profile_mid': '1160417236', 'user_name': '黄二'}, {'profile_id': '51396591', 'profile_mid': '164230145', 'user_name': '中国的🇨🇳 中'}, {'profile_id': '51564853', 'profile_mid': '43574864', 'user_name': '韦爵爷(韦全盛广州)'}, {'profile_id': '51534462', 'profile_mid': '1195094786', 'user_name': '福如东海'}, {'profile_id': '51548364', 'profile_mid': '41260451', 'user_name': '长寿村ccr1226'}, {'profile_id': '51674661', 'profile_mid': '1087239508', 'user_name': '颖'}, {'profile_id': '50498574', 'profile_mid': '227251181', 'user_name': '樱花红陌上'}, {'profile_id': '50998070', 'profile_mid': '45812341', 'user_name': '宇宙龙'}, {'profile_id': '51517051', 'profile_mid': '33975007', 'user_name': '懋忍者'}, {'profile_id': '50888222', 'profile_mid': '173572675', 'user_name': '余系立'}, {'profile_id': '50773751', 'profile_mid': '1005247', 'user_name': '长乐'}, {'profile_id': '50469333', 'profile_mid': '177860827', 'user_name': '毛映星'}, {'profile_id': '50625670', 'profile_mid': '16866802', 'user_name': '阿文哥'}, {'profile_id': '50530771', 'profile_mid': '132022633', 'user_name': '德兰'}, {'profile_id': '50521985', 'profile_mid': '6903156', 'user_name': '艺丹'}, {'profile_id': '50396968', 'profile_mid': '174184693', 'user_name': '情痴🌴❤️🇨🇳'}, {'profile_id': '50581740', 'profile_mid': '1204204129', 'user_name': '小宝爷爷'}, {'profile_id': '50852888', 'profile_mid': '1163041645', 'user_name': '每一步'}, {'profile_id': '50028439', 'profile_mid': '23642257', 'user_name': '江花剑语'}, {'profile_id': '49754934', 'profile_mid': '1160417204', 'user_name': '一抹微笑'}, {'profile_id': '51723400', 'profile_mid': '330013250', 'user_name': 'ChungenJu'}, {'profile_id': '51305568', 'profile_mid': '1162964081', 'user_name': '老楊开心就好'}, {'profile_id': '51360033', 'profile_mid': '51019095', 'user_name': 'C.Q.P.@&&&'}, {'profile_id': '51271108', 'profile_mid': '54610872', 'user_name': '马到成功'}, {'profile_id': '51311725', 'profile_mid': '69968880', 'user_name': '李全华'}, {'profile_id': '51238277', 'profile_mid': '1160417206', 'user_name': '暖心'}, {'profile_id': '51298601', 'profile_mid': '263815315', 'user_name': '陳坤雄'}, {'profile_id': '51302449', 'profile_mid': '1160417312', 'user_name': '淡泊宁静'}, {'profile_id': '51288732', 'profile_mid': '252962481', 'user_name': '盛文奶奶'}, {'profile_id': '51257079', 'profile_mid': '168108669', 'user_name': '钱文广'}, {'profile_id': '51282915', 'profile_mid': '113343785', 'user_name': '愉悦'}, {'profile_id': '51280015', 'profile_mid': '47771735', 'user_name': '陈国庆'}, {'profile_id': '51216073', 'profile_mid': '1157498248', 'user_name': '天高云淡'}, {'profile_id': '51212926', 'profile_mid': '278762839', 'user_name': '荷韵舞美'}, {'profile_id': '51214452', 'profile_mid': '1160417372', 'user_name': '璐瑶'}, {'profile_id': '51163788', 'profile_mid': '1160417318', 'user_name': '篮精灵'}, {'profile_id': '51217967', 'profile_mid': '302013472', 'user_name': '吴三毛'}, {'profile_id': '51219006', 'profile_mid': '161458173', 'user_name': '李访友'}, {'profile_id': '51116485', 'profile_mid': '142203818', 'user_name': ' 杨安京'}, {'profile_id': '51067925', 'profile_mid': '19503805', 'user_name': '青青原上草'}, {'profile_id': '51188086', 'profile_mid': '1161593430', 'user_name': '夏天'}, {'profile_id': '51091181', 'profile_mid': '176707411', 'user_name': '西北'}, {'profile_id': '51088671', 'profile_mid': '23164486', 'user_name': '田玉明'}, {'profile_id': '51103793', 'profile_mid': '34536244', 'user_name': '相信自己'}, {'profile_id': '51088014', 'profile_mid': '367757852', 'user_name': '益山益水'}, {'profile_id': '51103201', 'profile_mid': '923964638', 'user_name': '有缘相遇'}, {'profile_id': '51056808', 'profile_mid': '33526326', 'user_name': '李庆铉'}, {'profile_id': '51093916', 'profile_mid': '1160417214', 'user_name': '欣欣向上'}, {'profile_id': '51189345', 'profile_mid': '352851214', 'user_name': '好好,爱自己'}, {'profile_id': '51182723', 'profile_mid': '208242501', 'user_name': '凤芝'}, {'profile_id': '51159963', 'profile_mid': '1131244601', 'user_name': '幸福千年金胡'}, {'profile_id': '51186142', 'profile_mid': '124883413', 'user_name': 'yh'}, {'profile_id': '51167553', 'profile_mid': '1004195', 'user_name': '心明'}, {'profile_id': '51059900', 'profile_mid': '1087239508', 'user_name': '冬日暖阳'}, {'profile_id': '51102452', 'profile_mid': '230841899', 'user_name': '保钢'}, {'profile_id': '51120636', 'profile_mid': '53241722', 'user_name': '董淑莲'}, {'profile_id': '51022148', 'profile_mid': '59136015', 'user_name': '夕阳佳雁'}, {'profile_id': '51054327', 'profile_mid': '341707195', 'user_name': '燕琴'}, {'profile_id': '51094909', 'profile_mid': '848442892', 'user_name': '鱼粮'}, {'profile_id': '51090133', 'profile_mid': '90787272', 'user_name': 'JIN QI FENG'}]
  66. return user_list
  67. # 获取个人主页视频
  68. @classmethod
  69. def get_videoList(cls, log_type, crawler, strategy, p_mid, oss_endpoint, env):
  70. try:
  71. while True:
  72. url = "https://api.xiaoniangao.cn/profile/list_album"
  73. headers = {
  74. # "X-Mid": str(cls.follow_x_mid),
  75. "X-Mid": '1fb47aa7a860d9',
  76. # "X-Token-Id": str(cls.follow_x_token_id),
  77. "X-Token-Id": '9f2cb91f9952c107ecb73642083e1dec-1145266232',
  78. "content-type": "application/json",
  79. # "uuid": str(cls.follow_uid),
  80. "uuid": 'f40c2e7c-3cfb-4804-b513-608c0280268c',
  81. "Accept-Encoding": "gzip,compress,br,deflate",
  82. "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)"
  83. " AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 "
  84. "MicroMessenger/8.0.20(0x18001435) NetType/WIFI Language/zh_CN",
  85. # "Referer": str(cls.follow_referer)
  86. "Referer": 'https://servicewechat.com/wxd7911e4c177690e4/654/page-frame.html'
  87. }
  88. json_text = {
  89. "visited_mid": str(p_mid),
  90. "start_t": cls.next_t,
  91. "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/!690x385r/crop/690x385/interlace/1/format/jpg",
  92. "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail/!120x120r/crop/120x120/interlace/1/format/jpg",
  93. "limit": 20,
  94. # "token": str(cls.follow_token),
  95. "token": '54e4c603f7bf3dc009c86b49ed91be36',
  96. # "uid": str(cls.follow_uid),
  97. "uid": 'f40c2e7c-3cfb-4804-b513-608c0280268c',
  98. "proj": "ma",
  99. "wx_ver": "8.0.23",
  100. "code_ver": "3.68.0",
  101. "log_common_params": {
  102. "e": [{
  103. "data": {
  104. "page": "profilePage",
  105. "topic": "public"
  106. }
  107. }],
  108. "ext": {
  109. "brand": "iPhone",
  110. "device": "iPhone 11",
  111. "os": "iOS 14.7.1",
  112. "weixinver": "8.0.23",
  113. "srcver": "2.24.7",
  114. "net": "wifi",
  115. "scene": "1089"
  116. },
  117. "pj": "1",
  118. "pf": "2",
  119. "session_id": "7468cf52-00ea-432e-8505-6ea3ad7ec164"
  120. }
  121. }
  122. urllib3.disable_warnings()
  123. r = requests.post(url=url, headers=headers, json=json_text, proxies=proxies, verify=False)
  124. if 'data' not in r.text or r.status_code != 200:
  125. Common.logger(log_type, crawler).info(f"get_videoList:{r.text}\n")
  126. cls.next_t = None
  127. return
  128. elif 'list' not in r.json()['data']:
  129. Common.logger(log_type, crawler).info(f"get_videoList:{r.json()}\n")
  130. cls.next_t = None
  131. return
  132. elif len(r.json()['data']['list']) == 0:
  133. Common.logger(log_type, crawler).info(f"没有更多数据啦~\n")
  134. cls.next_t = None
  135. return
  136. else:
  137. cls.next_t = r.json()["data"]["next_t"]
  138. feeds = r.json()["data"]["list"]
  139. for i in range(len(feeds)):
  140. # 标题,表情随机加在片头、片尾,或替代句子中间的标点符号
  141. char_sheet = Feishu.get_values_batch("hour", "xiaoniangao", "BhlbST")
  142. expression_list = []
  143. char_list = []
  144. for q in range(len(char_sheet)):
  145. if char_sheet[q][0] is not None:
  146. expression_list.append(char_sheet[q][0])
  147. if char_sheet[q][1] is not None:
  148. char_list.append(char_sheet[q][1])
  149. befor_video_title = feeds[i]["title"].strip().replace("\n", "") \
  150. .replace("/", "").replace("\r", "").replace("#", "") \
  151. .replace(".", "。").replace("\\", "").replace("&NBSP", "") \
  152. .replace(":", "").replace("*", "").replace("?", "") \
  153. .replace("?", "").replace('"', "").replace("<", "") \
  154. .replace(">", "").replace("|", "").replace(" ", "")
  155. expression = random.choice(expression_list)
  156. expression_title_list = [expression + befor_video_title, befor_video_title + expression]
  157. # 标题,表情随机加在片头
  158. title_list1 = random.choice(expression_title_list)
  159. # 标题,表情随机加在片尾
  160. title_list2 = befor_video_title + random.choice(char_list)
  161. # # 替代句子中间的标点符号
  162. # title_list3 = befor_video_title.replace(
  163. # ",", random.choice(expression_list)).replace(",", random.choice(expression_list))
  164. title_list4 = [title_list1, title_list2]
  165. video_title = random.choice(title_list4)
  166. # 用户名
  167. user_name = feeds[i]["album_user"]["nick"].strip().replace("\n", "") \
  168. .replace("/", "").replace("快手", "").replace(" ", "") \
  169. .replace(" ", "").replace("&NBSP", "").replace("\r", "")
  170. # 视频 ID
  171. if "vid" in feeds[i]:
  172. video_id = feeds[i]["vid"]
  173. else:
  174. video_id = 0
  175. # 播放量
  176. if "play_pv" in feeds[i]:
  177. video_play_cnt = feeds[i]["play_pv"]
  178. else:
  179. video_play_cnt = 0
  180. # 点赞
  181. if "total" in feeds[i]["favor"]:
  182. video_like_cnt = feeds[i]["favor"]["total"]
  183. else:
  184. video_like_cnt = 0
  185. # 评论数
  186. if "comment_count" in feeds[i]:
  187. video_comment_cnt = feeds[i]["comment_count"]
  188. else:
  189. video_comment_cnt = 0
  190. # 分享
  191. if "share" in feeds[i]:
  192. video_share_cnt = feeds[i]["share"]
  193. else:
  194. video_share_cnt = 0
  195. # 时长
  196. if "du" in feeds[i]:
  197. video_duration = int(feeds[i]["du"] / 1000)
  198. else:
  199. video_duration = 0
  200. # 发布时间
  201. if "t" in feeds[i]:
  202. publish_time_stamp = int(feeds[i]["t"] / 1000)
  203. else:
  204. publish_time_stamp = 0
  205. publish_time_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(publish_time_stamp))
  206. # 宽和高
  207. if "w" in feeds[i] or "h" in feeds[i]:
  208. video_width = feeds[i]["w"]
  209. video_height = feeds[i]["h"]
  210. else:
  211. video_width = 0
  212. video_height = 0
  213. # 头像
  214. if "hurl" in feeds[i]["album_user"]:
  215. head_url = feeds[i]["album_user"]["hurl"]
  216. else:
  217. head_url = 0
  218. # 用户 ID
  219. if "id" in feeds[i]:
  220. profile_id = feeds[i]["id"]
  221. else:
  222. profile_id = 0
  223. # 用户 mid
  224. if "mid" in feeds[i]:
  225. profile_mid = feeds[i]["mid"]
  226. else:
  227. profile_mid = 0
  228. # 封面
  229. if "url" in feeds[i]:
  230. cover_url = feeds[i]["url"]
  231. else:
  232. cover_url = 0
  233. # 视频播放地址
  234. if "v_url" in feeds[i]:
  235. video_url = feeds[i]["v_url"]
  236. else:
  237. video_url = 0
  238. # 过滤无效视频
  239. if video_id == 0 \
  240. or video_title == 0 \
  241. or publish_time_stamp == 0 \
  242. or video_duration == 0 \
  243. or video_url == 0:
  244. Common.logger(log_type, crawler).info("无效视频\n")
  245. elif int(time.time()) - publish_time_stamp > 3600 * 24 * 3:
  246. Common.logger(log_type, crawler).info(f"发布时间超过3天:{publish_time_str}\n")
  247. cls.next_t = None
  248. return
  249. else:
  250. video_dict = {
  251. "video_id": video_id,
  252. "video_title": video_title,
  253. "duration": video_duration,
  254. "play_cnt": video_play_cnt,
  255. "like_cnt": video_like_cnt,
  256. "comment_cnt": video_comment_cnt,
  257. "share_cnt": video_share_cnt,
  258. "user_name": user_name,
  259. "publish_time_stamp": publish_time_stamp,
  260. "publish_time_str": publish_time_str,
  261. "video_width": video_width,
  262. "video_height": video_height,
  263. "avatar_url": head_url,
  264. "profile_id": profile_id,
  265. "profile_mid": profile_mid,
  266. "cover_url": cover_url,
  267. "video_url": video_url,
  268. "session": f"xiaoniangao-follow-{int(time.time())}"
  269. }
  270. for k, v in video_dict.items():
  271. Common.logger(log_type, crawler).info(f"{k}:{v}")
  272. cls.download_publish(log_type=log_type,
  273. crawler=crawler,
  274. strategy=strategy,
  275. video_dict=video_dict,
  276. oss_endpoint=oss_endpoint,
  277. env=env)
  278. except Exception as error:
  279. Common.logger(log_type, crawler).error(f"获取个人主页视频异常:{error}\n")
  280. @classmethod
  281. def repeat_video(cls, log_type, crawler, video_id, env):
  282. sql = f""" select * from crawler_video where platform="小年糕" and out_video_id="{video_id}"; """
  283. repeat_video = MysqlHelper.get_values(log_type, crawler, sql, env)
  284. return len(repeat_video)
  285. # 下载/上传
  286. @classmethod
  287. def download_publish(cls, log_type, crawler, strategy, video_dict, oss_endpoint, env):
  288. try:
  289. if cls.download_rule(video_dict) is False:
  290. Common.logger(log_type, crawler).info("不满足基础门槛\n")
  291. elif cls.repeat_video(log_type, crawler, video_dict['video_id'], env) != 0:
  292. Common.logger(log_type, crawler).info('视频已下载\n')
  293. elif any(str(word) if str(word) in video_dict['video_title'] else False for word in filter_word(log_type, crawler, "小年糕", env)) is True:
  294. Common.logger(log_type, crawler).info("视频已中过滤词\n")
  295. else:
  296. # 下载封面
  297. Common.download_method(log_type=log_type, crawler=crawler, text="cover",
  298. title=video_dict["video_title"], url=video_dict["cover_url"])
  299. # 下载视频
  300. Common.download_method(log_type=log_type, crawler=crawler, text="video",
  301. title=video_dict["video_title"], url=video_dict["video_url"])
  302. # 保存视频信息至 "./videos/{download_video_title}/info.txt"
  303. Common.save_video_info(log_type=log_type, crawler=crawler, video_dict=video_dict)
  304. # 上传视频
  305. Common.logger(log_type, crawler).info("开始上传视频...")
  306. our_video_id = Publish.upload_and_publish(log_type=log_type,
  307. crawler=crawler,
  308. strategy=strategy,
  309. our_uid="follow",
  310. env=env,
  311. oss_endpoint=oss_endpoint)
  312. if env == "dev":
  313. our_video_link = f"https://testadmin.piaoquantv.com/cms/post-detail/{our_video_id}/info"
  314. else:
  315. our_video_link = f"https://admin.piaoquantv.com/cms/post-detail/{our_video_id}/info"
  316. Common.logger(log_type, crawler).info("视频上传完成")
  317. if our_video_id is None:
  318. # 删除视频文件夹
  319. shutil.rmtree(f"./{crawler}/videos/{video_dict['video_title']}")
  320. return
  321. # 视频信息保存数据库
  322. rule_dict = {
  323. "duration": {"min": 40, "max": 100000000},
  324. "play_cnt": {"min": 500}
  325. }
  326. insert_sql = f""" insert into crawler_video(video_id,
  327. out_user_id,
  328. platform,
  329. strategy,
  330. out_video_id,
  331. video_title,
  332. cover_url,
  333. video_url,
  334. duration,
  335. publish_time,
  336. play_cnt,
  337. crawler_rule,
  338. width,
  339. height)
  340. values({our_video_id},
  341. "{video_dict['profile_id']}",
  342. "{cls.platform}",
  343. "定向爬虫策略",
  344. "{video_dict['video_id']}",
  345. "{video_dict['video_title']}",
  346. "{video_dict['cover_url']}",
  347. "{video_dict['video_url']}",
  348. {int(video_dict['duration'])},
  349. "{video_dict['publish_time_str']}",
  350. {int(video_dict['play_cnt'])},
  351. '{json.dumps(rule_dict)}',
  352. {int(video_dict['video_width'])},
  353. {int(video_dict['video_height'])}) """
  354. Common.logger(log_type, crawler).info(f"insert_sql:{insert_sql}")
  355. MysqlHelper.update_values(log_type, crawler, insert_sql, env)
  356. Common.logger(log_type, crawler).info('视频信息插入数据库成功!')
  357. # 视频写入飞书
  358. Feishu.insert_columns(log_type, crawler, "Wu0CeL", "ROWS", 1, 2)
  359. # 视频ID工作表,首行写入数据
  360. upload_time = int(time.time())
  361. values = [[time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(upload_time)),
  362. "用户主页",
  363. str(video_dict['video_id']),
  364. str(video_dict['video_title']),
  365. our_video_link,
  366. video_dict['play_cnt'],
  367. video_dict['comment_cnt'],
  368. video_dict['like_cnt'],
  369. video_dict['share_cnt'],
  370. video_dict['duration'],
  371. f"{video_dict['video_width']}*{video_dict['video_height']}",
  372. str(video_dict['publish_time_str']),
  373. str(video_dict['user_name']),
  374. str(video_dict['profile_id']),
  375. str(video_dict['profile_mid']),
  376. str(video_dict['avatar_url']),
  377. str(video_dict['cover_url']),
  378. str(video_dict['video_url'])]]
  379. time.sleep(1)
  380. Feishu.update_values(log_type, crawler, "Wu0CeL", "F2:Z2", values)
  381. Common.logger(log_type, crawler).info('视频信息写入飞书成功\n')
  382. except Exception as e:
  383. Common.logger(log_type, crawler).error("下载/上传异常:{}", e)
  384. # 获取所有关注列表的用户视频
  385. @classmethod
  386. def get_follow_videos(cls, log_type, crawler, strategy, oss_endpoint, env):
  387. try:
  388. # 已关注的用户列表 mids
  389. user_list = cls.get_users()
  390. for user in user_list:
  391. user_name = user['user_name']
  392. profile_mid = user['profile_mid']
  393. Common.logger(log_type, crawler).info(f"获取 {user_name} 主页视频")
  394. cls.get_videoList(log_type=log_type,
  395. crawler=crawler,
  396. strategy=strategy,
  397. p_mid=profile_mid,
  398. oss_endpoint=oss_endpoint,
  399. env=env)
  400. cls.next_t = None
  401. time.sleep(1)
  402. except Exception as e:
  403. Common.logger(log_type, crawler).error(f"get_follow_videos:{e}\n")
  404. if __name__ == "__main__":
  405. # print(XiaoniangaoFollow.repeat_video("follow", "xiaoniangao", "4919087666", "prod", "aliyun"))
  406. # print(XiaoniangaoFollow.repeat_video("follow", "xiaoniangao", "4919087666", "dev"))
  407. XiaoniangaoFollow.get_users()
  408. pass