Exemple #1
0
def set_rating(request):
    ret = {'status': True, 'error': None, 'data': None}
    try:
        vod_id = request.GET.get('vod_id')
        douban_id = request.GET.get('douban_id')
        if douban_id:  # 如果查找到豆瓣id
            ret['data'] = douban_id
            if type(douban_id) == list:
                ret['status'] = False
                ret['error'] = '存在多个数据'
            else:
                rating = GetPageData.getRating(douban_id)
                print(vod_id, douban_id, rating, end='')
                DBHandler.dump_douban_id(vod_id, douban_id)
                DBHandler.dump_rating(vod_id, rating)
                print('保存成功[douban]')
        else:  # 未查找到豆瓣id
            ret['status'] = False
            test_net = GetPageData.findID('爱情公寓2', '2011')
            if test_net is None:  # 网络异常
                ret['error'] = '地址被限制,请稍后重试'
            else:
                ret['error'] = '无豆瓣id数据'
    except Exception as e:
        print(e)
        ret['status'] = False
        ret['error'] = e
    finally:
        return HttpResponse(json.dumps(ret))
Exemple #2
0
def remove_douban_data(request):
    ret = {'status': True, 'error': None, 'data': None}
    try:
        vod_id = request.GET.get('vod_id', None)
        if not vod_id:
            ret['status'] = False
            return
        DBHandler.dump_douban_id(vod_id, None)
        DBHandler.dump_rating(vod_id, None)
        ret['data'] = "已成功删除豆瓣数据"
    except Exception as e:
        print(e)
        ret['status'] = False
        ret['error'] = e
    finally:
        return HttpResponse(json.dumps(ret))
Exemple #3
0
def get_douban_rating(request):
    res_status = False
    flag = True
    timeout = 0
    try:
        print('————————开始获取豆瓣id数据————————')
        # data_list = DBHandler.load_type_data(
        #     **{'vod_cid': '1', 'no_douban_id': True})    # 获取所有电影
        data_list = DBHandler.load_type_data(**{
            'vod_cid': '2',
            'no_douban_id': True
        })  # 获取所有电视剧
        none_list = DBHandler.redis_loadlist('douban_none_list')
        none_list2 = DBHandler.redis_loadlist('douban_none_list2')
        print('无豆瓣id的视频总数:%s' % len(data_list))
        print('无匹配视频总数:%s' % len(none_list))
        print('重复数据的视频总数:%s' % len(none_list2))
        # while flag:
        # print(bytes('75519',encoding='utf-8') not in none_list and bytes('75519',encoding='utf-8') not in none_list2)
        # return HttpResponse(none_list)
        for item in data_list:
            admin_flag = DBHandler.redis_load('admin_flag')
            if admin_flag == b'0':
                print('管理员终止')
                break
            b_id = bytes(item['vod_id'], encoding='utf-8')
            # 不存在豆瓣id,则查找id
            if item['vod_douban_id'] is None and (b_id not in none_list
                                                  and b_id not in none_list2):
                # print(item['vod_douban_id'],item['vod_rating'])
                i = 0
                while i < 2:
                    douban_id = GetPageData.findID(item['vod_name'],
                                                   item['vod_year'])
                    if douban_id:  # 如果查找到豆瓣id
                        timeout = 0
                        if type(douban_id) == list:
                            print(item['vod_name'], '匹配到多个豆瓣id数据,存入列表2',
                                  douban_id)
                            if b_id not in none_list2:
                                none_list2.append(b_id)
                        else:
                            DBHandler.dump_douban_id(item['vod_id'], douban_id)
                            print(item['vod_name'], douban_id, end=' ')
                            rating = GetPageData.getRating(douban_id)
                            if rating:
                                print(rating, end='')
                                DBHandler.dump_rating(item['vod_id'], rating)
                            print('保存成功[douban]')
                        # 防止账号被封,随机延迟
                        # time.sleep(1 + float(random.randint(40, 100)) / 20)
                        time.sleep(0.5)
                        break
                    else:  # 未查找到豆瓣id
                        i += 1
                        # if i ==1:
                        #     print(item['vod_name'])
                        continue
                        # test_net = GetPageData.findID('爱情公寓2', '2011')
                        # if test_net is None:    # 网络异常
                        # print('----------地址被限制,稍后重试----------')
                        #     if none_list:
                        #         DBHandler.redis_dumplist(
                        #             'douban_none_list', none_list)
                        #         none_list = []
                        #         print('none_list 暂存')
                        #     if none_list2:
                        #         DBHandler.redis_dumplist(
                        #             'douban_none_list2', none_list2)
                        #         none_list2 = []
                        #         print('none_list2 暂存')
                        #     # time.sleep(180)
                        #     timeout += 1
                        #     # if timeout == 5:
                        #     #     print('连续五次失败,等待30分钟')
                        #     #     time.sleep(1800)
                        #     #     print('----------重新启动查找------------')
                        #     #     continue
                        #     # elif timeout >= 10:
                        #     #     print('-----连续十次失败,等待1小时-----')
                        #     #     time.sleep(3600)
                        #     #     timeout = 0
                        #     #     continue
                        # else:
                        #     print(item['vod_name'], '无豆瓣id数据,存入列表')
                        #     if b_id not in none_list:
                        #         none_list.append(b_id)
        res_status = True
    except Exception as e:
        print('get_douban_rating exception:', e)
        print(traceback.print_exc())
        res_status = 'get_douban_rating exception:%s' % e
    finally:
        if none_list:
            DBHandler.redis_dumplist('douban_none_list', none_list)
        if none_list2:
            DBHandler.redis_dumplist('douban_none_list2', none_list2)
        DBHandler.redis_dump('admin_flag', '1')
        print('————————豆瓣id获取完毕————————')
        return HttpResponse(res_status)