""" @author: luojunhui """ import json import requests from applications.functions.common import MySQLServer def wx_search(keys): """ WeChat search :param keys: :return: """ sensitive_words = MySQLServer().select_sensitive_words() def sensitive_flag(s_words, ori_title): """ :param ori_title: :param s_words: :return: """ for word in s_words: if word in ori_title: return False return True url = "http://8.217.190.241:8888/crawler/wei_xin/keyword" payload = json.dumps({ "keyword": keys, "cursor": "0", "content_type": "video" }) headers = { 'Content-Type': 'application/json' } response = requests.request("POST", url, headers=headers, data=payload).json() if response['msg'] == '未知错误': return [] else: L = [] if response['data']: video_list = response['data']['data'] for video in video_list: try: video_info = video['items'][0] title = video_info['title'] duration_str = video_info['duration'] dr = int(duration_str.split(":")[0].strip()) + int(duration_str.split(":")[1].strip()) if sensitive_flag(sensitive_words, title) and dr <= 300: L.append(video_info) else: continue except: pass return L