def _get_key(ci_t, gall_name_en, password, post_num): """key를 얻습니다.""" SESSION.headers['X-Requested-With'] = 'XMLHttpRequest' data = dict(ci_t=ci_t, password=password, id=gall_name_en, no=post_num) con = SESSION.post(url=URL.DELETE_POST2, data=data) key = con.text.split('||')[1] return key
def _submit(gall_name_en, ci_t, r_key, block_key, subject, password, name, memo): """글을 작성합니다.""" url = 'http://gall.dcinside.com/forms/article_submit' data = dict( upload_status='N', id=gall_name_en, ci_t=ci_t, subject=subject, password=password, r_key=r_key, name=name, memo=memo, block_key=block_key, vid='', isMovie='', campus=0, ipt_movieCompType='', wiki_tag='', sijosae='tlwhtorororRl' ) SESSION.headers['Referer'] = URL.POST_CREATE.format( gall_name_en=gall_name_en) return SESSION.post(url, data=data)
def main(post, name, password, text): """글에 댓글을 작성합니다.""" data = _make_comment_data(post, name, password, text) SESSION.headers['Referer'] = _get_comment_referrer_url(post) SESSION.headers['X-Requested-With'] = 'XMLHttpRequest' # Post comment r = SESSION.post(url=URL.COMMENT_SUBMIT, data=data) # Post comment count data = dict(ci_t=post['ci_t'], id=post['gall_name'], no=post['post_num']) SESSION.post(url=URL.COMMENT_COUNT, data=data) # Post view count data['comment_page'] = 1 SESSION.post(url=URL.COMMENT_VIEW, data=data) return r
def _delete_post_step3(key, gall_name_en, post_num): del SESSION.headers['X-Requested-With'] full_delete_url = URL.DELETE_POST3.format(gall_name=gall_name_en, post_num=post_num, key=key) con = SESSION.get(full_delete_url) ci_t = _parse_ci_t(con.text) return ci_t
def main(gall_name_en, post_num): """글을 읽습니다.""" url = URL.POST_READ.format(gall_name_en=gall_name_en, post_num=post_num) r = SESSION.get(url) html = r.text # raise error if post is deleted deleted_msg = '/error/deleted/{}'.format(gall_name_en) if deleted_msg in html: raise PostDoesNotExistError('Post does not exist.') return post_parser(html, gall_name_en, post_num)
def _get_block_key(block_key, ci_t, r_key, gall_name_en): """block_key를 얻습니다.""" while 1: url = 'http://gall.dcinside.com/block/block/' SESSION.headers['X-Requested-With'] = 'XMLHttpRequest' SESSION.cookies['dcgame_top'] = 'Y' data = dict(ci_t=ci_t, id=gall_name_en, block_key=block_key) con = SESSION.post(url, data=data) if con.text != '': return con.text # 너무 빠르게 하면 값을 반환 안 해서 잠깐 쉼 time.sleep(0.5)
def upvote(gall_name_en, post_num, ci_t): """글을 개념글 추천을 합니다.""" SESSION.headers['X-Requested-With'] = 'XMLHttpRequest' SESSION.headers['Referer'] = URL.POST_VOTE_UP SESSION.cookies[gall_name_en + str(post_num) + '_Firstcheck'] = 'Y' data = dict(ci_t=ci_t, id=gall_name_en, no=post_num, recommend=0, vote='vote', user_id='') return SESSION.post(url=URL.POST_VOTE_UP, data=data)
def main(post, gall_name_en, comment_num, password): """댓글을 삭제합니다.""" data = dict(ci_t=post['ci_t'], no=post['post_num'], id=gall_name_en, p_no=post['post_num'], re_no=comment_num, orgin_no=0, password=password, best_orgin='', check_7=post['check_7']) SESSION.headers['X-Requested-With'] = 'XMLHttpRequest' return SESSION.post(url=URL.COMMENT_DELETE_SUBMIT, data=data)
def _yield_comment_html(post, cmt_all=True): """글 댓글들의 html을 yield합니다.""" if cmt_all: max_pages = post['total_pages'] else: max_pages = 1 for page in range(1, max_pages + 1): data = dict(ci_t=post['ci_t'], id=post['gall_name'], no=post['post_num'], comment_page=page) SESSION.headers['X-Requested-With'] = 'XMLHttpRequest' r = SESSION.post(url=URL.COMMENT_VIEW, data=data).text yield r
def _get_ci_t(gall_name_en, post_num): """csrf_token을 얻습니다.""" delete_url = URL.DELETE_POST1.format(gall_name=gall_name_en, post_num=post_num) con = SESSION.get(delete_url) return _parse_ci_t(con.text)
def _delete_post_step4(ci_t, key, gall_name_en, post_num): SESSION.headers['X-Requested-With'] = 'XMLHttpRequest' data = dict(ci_t=ci_t, key=key, id=gall_name_en, no=post_num) return SESSION.post(url=URL.DELETE_POST4, data=data)
def get_html(url): return SESSION.get(url).text
def _get_html(gall_name_en): """글 작성 페이지의 html을 얻습니다.""" url = URL.POST_CREATE.format(gall_name_en=gall_name_en) return SESSION.get(url).text