async def fetch_dyn_raffle_status( user, doc_id: int, uid: int, post_time: int, describe: str) -> Optional[DynRaffleStatus]: json_rsp = await user.req_s(DynRaffleHandlerReq.fetch_dyn_raffle, user, doc_id) code = json_rsp['code'] if not code: print('check raffle_status', json_rsp) data = json_rsp['data'] dyn_id = data['business_id'] # 开奖时间 lottery_time = data['lottery_time'] # @人数 at_num = data['lottery_at_num'] # 关注 1 true feed_limit = data['lottery_feed_limit'] first_prize_cmt = data['first_prize_cmt'] second_prize_cmt = data.get('second_prize_cmt', '') third_prize_cmt = data.get('third_prize_cmt', '') # 需要邮寄???????存疑 # post = data['need_post'] dyn_raffle_status = DynRaffleStatus(dyn_id=dyn_id, doc_id=doc_id, describe=describe, uid=uid, post_time=post_time, lottery_time=lottery_time, at_num=at_num, feed_limit=feed_limit, prize_cmt_1st=first_prize_cmt, prize_cmt_2nd=second_prize_cmt, prize_cmt_3rd=third_prize_cmt) print('获取到的抽奖信息为', dyn_raffle_status) return dyn_raffle_status elif code == -9999: print(f'抽奖动态{doc_id}已经删除') return None
async def check_and_fetch_raffle(user, doc_id, handle_status=-1, feed_limit=False) -> tuple: json_rsp = await user.req_s(DynRaffleHandlerReq.is_dyn_raffle, user, doc_id) code = json_rsp['code'] print('_____________________________________') print('is_dyn_raffle:', doc_id, 'code:', code) if not code: data = json_rsp['data'] item = data['item'] str_ext = item['extension'] print(doc_id, str_ext) if str_ext: try: dict_ext = json.loads(str_ext.replace('\'', '')) except json.JSONDecodeError: print(f'dict_extension 解析失败,可能是b站api已知问题') if len(str_ext) != 1024: # TODO 可能还有doc_id=21426429 "extension":"{\"emoji_type\":1}{\"emoji_type\":1}" user.warn(f'动态抽奖{doc_id}dict_extension 解析失败', str_ext) return 1, None # 抽奖 不符合的可能{}或者lott_cfg为空或者其他一些 if 'lott_cfg' in dict_ext and dict_ext['lott_cfg']: lott_cfg_x = dict_ext['lott_cfg'] if isinstance(lott_cfg_x, dict): lott_cfg = lott_cfg_x elif isinstance(lott_cfg_x, str): lott_cfg = json.loads(lott_cfg_x) else: return -1, None print('lott_cfg', lott_cfg) if 'lottery_id' in lott_cfg: uid = data['user']['uid'] post_time = int(item['upload_timestamp']) describe = item['description'] else: return 1, None else: return 1, None else: return 1, None elif code == 110001: if 'user' not in json_rsp['data']: return 404, None return 1, None else: # 目前未发现其他code user.warn(f'互动抽奖初步查询 {json_rsp}') return -1, None json_rsp = await user.req_s(DynRaffleHandlerReq.fetch_dyn_raffle, user, doc_id) code = json_rsp['code'] if not code: # print('check raffle_status', json_rsp) data = json_rsp['data'] dyn_id = data['business_id'] # 开奖时间 lottery_time = data['lottery_time'] # @人数 at_num = data['lottery_at_num'] # 关注 1 true feed_limit = bool(data['lottery_feed_limit']) or feed_limit first_prize_cmt = data['first_prize_cmt'] second_prize_cmt = data.get('second_prize_cmt', '') third_prize_cmt = data.get('third_prize_cmt', '') first_prize = data['first_prize'] second_prize = data.get('second_prize', 0) third_prize = data.get('third_prize', 0) # 需要邮寄???????存疑 # post = data['need_post'] dyn_raffle_status = DynRaffleStatus(dyn_id=dyn_id, doc_id=doc_id, describe=describe, uid=uid, post_time=post_time, lottery_time=lottery_time, at_num=at_num, feed_limit=feed_limit, handle_status=handle_status, prize_cmt_1st=first_prize_cmt, prize_cmt_2nd=second_prize_cmt, prize_cmt_3rd=third_prize_cmt, prize_num_1st=first_prize, prize_num_2nd=second_prize, prize_num_3rd=third_prize) print('获取到的抽奖信息为', dyn_raffle_status) return 0, dyn_raffle_status elif code == -9999: print(f'抽奖动态{doc_id}已经删除') return 404, None user.warn(f'互动抽奖初步查询 {json_rsp}') return -1, None
async def check_and_fetch_raffle(user, doc_id, handle_status=-1, feed_limit=False) -> tuple: # monitor暴力搜索时候判断是否到达终点/删除 json_rsp = await user.req_s(DynRaffleHandlerReq.check_dyn_detail, user, doc_id) code = json_rsp['code'] if not code: item = json_rsp['data']['item'] uid = item['poster_uid'] post_time = int(item['upload_timestamp']) # 有时description不存在的 if 'description' not in item: return 1, None describe = item['description'] elif code == 110001: if 'user' not in json_rsp['data']: return 404, None return 1, None else: # 目前未发现其他code user.warn(f'互动抽奖初步查询 {json_rsp}') return -1, None json_rsp = await user.req_s(DynRaffleHandlerReq.fetch_dyn_raffle, user, doc_id) code = json_rsp['code'] print('_____________________________________') print('is_dyn_raffle:', doc_id, 'code:', code) if not code: # print('check raffle_status', json_rsp) data = json_rsp['data'] dyn_id = data['business_id'] # 开奖时间 lottery_time = data['lottery_time'] # @人数 at_num = data['lottery_at_num'] # 关注 1 true feed_limit = bool(data['lottery_feed_limit']) or feed_limit first_prize_cmt = data['first_prize_cmt'] second_prize_cmt = data.get('second_prize_cmt', '') third_prize_cmt = data.get('third_prize_cmt', '') first_prize = data['first_prize'] second_prize = data.get('second_prize', 0) third_prize = data.get('third_prize', 0) # 需要邮寄???????存疑 # post = data['need_post'] dyn_raffle_status = DynRaffleStatus(dyn_id=dyn_id, doc_id=doc_id, describe=describe, uid=uid, post_time=post_time, lottery_time=lottery_time, at_num=at_num, feed_limit=feed_limit, handle_status=handle_status, prize_cmt_1st=first_prize_cmt, prize_cmt_2nd=second_prize_cmt, prize_cmt_3rd=third_prize_cmt, prize_num_1st=first_prize, prize_num_2nd=second_prize, prize_num_3rd=third_prize) print('获取到的抽奖信息为', dyn_raffle_status) return 0, dyn_raffle_status elif code == -9999: print(f'抽奖动态{doc_id}已经删除或者非抽奖动态') return 1, None user.warn(f'互动抽奖初步查询 {json_rsp}') return -1, None
async def check_and_fetch_raffle(user, doc_id, handle_status=-1, feed_limit=False) -> tuple: json_rsp = await user.req_s(DynRaffleHandlerReq.is_dyn_raffle, user, doc_id) code = json_rsp['code'] print('_____________________________________') print('is_dyn_raffle:', doc_id, 'code:', code) if not code: data = json_rsp['data'] item = data['item'] str_ext = item['extension'] print(doc_id, str_ext) if str_ext: dict_ext = json.loads(str_ext.replace('\'', '')) # 抽奖 不符合的可能{}或者lott_cfg为空或者其他一些 if 'lott_cfg' in dict_ext and dict_ext['lott_cfg']: lott_cfg = json.loads(dict_ext['lott_cfg']) print('lott_cfg', lott_cfg) title = lott_cfg['title'] # 目前未发现其他title if title == '互动抽奖': uid = data['user']['uid'] post_time = int(item['upload_timestamp']) describe = item['description'] else: return 1, None else: return 1, None else: return 1, None elif code == 110001: return 404, None else: # 目前未发现其他code user.warn(f'互动抽奖初步查询 {json_rsp}') return -1, None json_rsp = await user.req_s(DynRaffleHandlerReq.fetch_dyn_raffle, user, doc_id) code = json_rsp['code'] if not code: # print('check raffle_status', json_rsp) data = json_rsp['data'] dyn_id = data['business_id'] # 开奖时间 lottery_time = data['lottery_time'] # @人数 at_num = data['lottery_at_num'] # 关注 1 true feed_limit = bool(data['lottery_feed_limit']) or feed_limit first_prize_cmt = data['first_prize_cmt'] second_prize_cmt = data.get('second_prize_cmt', '') third_prize_cmt = data.get('third_prize_cmt', '') first_prize = data['first_prize'] second_prize = data.get('second_prize', 0) third_prize = data.get('third_prize', 0) # 需要邮寄???????存疑 # post = data['need_post'] dyn_raffle_status = DynRaffleStatus(dyn_id=dyn_id, doc_id=doc_id, describe=describe, uid=uid, post_time=post_time, lottery_time=lottery_time, at_num=at_num, feed_limit=feed_limit, handle_status=handle_status, prize_cmt_1st=first_prize_cmt, prize_cmt_2nd=second_prize_cmt, prize_cmt_3rd=third_prize_cmt, prize_num_1st=first_prize, prize_num_2nd=second_prize, prize_num_3rd=third_prize) print('获取到的抽奖信息为', dyn_raffle_status) return 0, dyn_raffle_status elif code == -9999: print(f'抽奖动态{doc_id}已经删除') return 404, None user.warn(f'互动抽奖初步查询 {json_rsp}') return -1, None