def render_comment_detail(obj): if 'text' in obj: obj = _parse_comment_detail(obj['text']) output.succeed('{author}: {content} \n {pics}'.format(**obj)) elif 'errcode' in obj: output.error(obj['msg']) else: output.error('error unknow')
def render_comment_list(obj, download=False): if 'text' in obj: obj = _parse_comment_list(obj['text']) for comment in obj: output.echo( '------------------------------\n[{index}] {author} {date}:\n {content}\n{pics} \n [comment_id] {id} [oo] {oo} [xx] {xx} {tucao}\n' .format(**comment)) if comment['pics'] and download: download_pics(comment['pics']) elif 'errcode' in obj: output.error(obj['msg']) else: output.error('error unknow')
def post_tucao(author, email, content, comment_id): last_user = get_userinfo(USER_CONFIG) data = { 'content': content, 'comment_id': comment_id } data = _make_user_info(author, email, data, last_user) if 'author' not in data or 'email' not in data: output.error(f'author and email must set') sys.exit(0) r = start_request(JD_TUCAO, headers=make_dict(HEADERS, 'Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'), method='post', data=data) if 'code' in r and r['code'] == 0: output.succeed(f'tucao {r["msg"]}, [tucao_id] {r["data"]["comment_ID"]}, [author] {r["data"]["comment_author"]}') else: print(r)
def render_tucao_list(obj, hot_display=False, j=1): if 'code' in obj and obj['code'] == 0: if 'hot_tucao' in obj and hot_display == False: output.color_print('\nhot tucao list: \n', fg='red', bold=True) i = 1 for tucao in obj['hot_tucao']: output.color_print( '{}.---------------\n [tucao_id] {} [comment_id] {} [post_id] {}\n [author] {} [date] {} \n {} \n [oo] {} [xx] {}' .format(i, tucao['comment_ID'], tucao['comment_parent'], tucao['comment_post_ID'], tucao['comment_author'], tucao['comment_date'], tucao['comment_content'], tucao['vote_positive'], tucao['vote_negative']), fg='white', bold=True) i += 1 if 'tucao' in obj: if not hot_display: output.color_print('\nnormal tucao list: \n', fg='yellow', bold=True) for tucao in obj['tucao']: output.color_print( '{}.---------------\n [tucao_id] {} [comment_id] {} [post_id] {}\n [author] {} [date] {} \n {} \n [oo] {} [xx] {}' .format(j, tucao['comment_ID'], tucao['comment_parent'], tucao['comment_post_ID'], tucao['comment_author'], tucao['comment_date'], tucao['comment_content'], tucao['vote_positive'], tucao['vote_negative']), fg='white', bold=True) j += 1 if obj['has_next_page']: url = TUCAO_LIST.format( obj['tucao'][0]['comment_parent']) + '/n/{}'.format( obj['tucao'][-1]['comment_ID']) obj = start_request(url) render_tucao_list(obj, hot_display=True, j=j) elif 'errcode' in obj: output.error(obj['msg']) else: output.error('error unknow')
def post_comment(author, email, comment, category, post_id): data = {'comment': comment} last_user = get_userinfo(USER_CONFIG) data = _make_user_info(author, email, data, last_user) if 'author' not in data or 'email' not in data: output.error(f'author and email must set') sys.exit(0) if category: r = start_request(COMMENT_LIST.format(category)) comment_post_ID = parse_post_id(r['text']) else: if post_id == 0: output.error('post_id must be an integer not equal 0', bold=True) sys.exit(0) comment_post_ID = post_id data['comment_post_ID'] = comment_post_ID r = start_request(JD_COMMENT, headers=make_dict(HEADERS, 'Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'), method='post', data=data) if isinstance(r, int): output.succeed(f'post comment succeed, [comment_id] {r}') else: print(r)