Ejemplo n.º 1
0
                data['beReplied_user'] = None
                data['beReplied_content'] = None
                data['beReplied_like_count'] = None
                data['beReplied_comment_time'] = None
            print('{}\tget user:{} comment'.format(
                time.strftime("%Y-%m-%d %H:%M:%S",
                              time.localtime(time.time())), data['user']))
            yield data
    except Exception as e:
        print('get_comment_info() error,', str(e))
        data = {}
        data['result'] = 'error'
        yield data


if __name__ == '__main__':
    configs = {'host': '***', 'user': '******', 'password': '******', 'db': '***'}
    db = DbHelper()
    db.connenct(configs)

    video_id_list = db.find_today_video()
    for video_id in video_id_list:
        comment_api = 'https://jokeai.zongcaihao.com/douyin/v292/comment/list?aweme_id={}&cursor=0'.format(
            video_id['video_id'])
        print(comment_api)
        for comment_data in get_comment(comment_api):
            if comment_data['result'] == 'success':
                db.save_one_data_to_comment(comment_data)
            elif comment_data['result'] == 'error':
                continue
Ejemplo n.º 2
0
            for data in get_hot_comment(dict['resp']):
                data['song_id'] = dict['song_id']
                db.save_one_data_to_hot_comment(data)  # 存储热门评论
            for d in get_comment(dict['resp']):
                d['song_id'] = dict['song_id']
                db.save_one_data_to_comment(d)  # 存储最新评论
            queue.task_done()  # 标记该数据已从队列中取出
        except:
            print("queue is empty wait for a while")
            time.sleep(1)


if __name__ == '__main__':
    # start_time = time.time()
    db = DbHelper()
    db.connenct(const.DB_CONFIGS)

    put_thread_pool = ThreadPool(3)
    get_thread_pool = ThreadPool(3)
    queue = ThreadManager().Queue(
    )  # 线程池之间通信需要用Manager().Queue(),线程间通信用Queue()

    comment_url = 'https://music.163.com/weapi/v1/resource/comments/R_SO_4_{}?csrf_token='  # 评论接口
    random_str = create_random_str(16)
    params = get_params(const.FIRST_PARAM, const.FORTH_PARAM, random_str)
    encSecKey = get_encSecKey(random_str, const.SECOND_PARAM,
                              const.THIRD_PARAM)
    form_data = {'params': params, 'encSecKey': encSecKey}

    response = get_html(const.DAY_LIST_URL)
    links = []