Skip to content

Commit

Permalink
modify ban method
Browse files Browse the repository at this point in the history
  • Loading branch information
KIDJourney committed Mar 16, 2016
1 parent e2cfde0 commit 2dd26e4
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions src/lawman.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,31 +63,23 @@ def delete_post(self, delete_page_url):

return '成功删除' in delete_result.text

def ban_user(self, post_url, author, reason):
def ban_user(self, post, reason):
"""
Ban the author of post
:param post_url:
:param author:
:param post:
:param reason:
:return:
"""
post_id = get_post_id(post_url)
post_url = "http://tieba.baidu.com/p/{0}".format(post_id)
response = self.get_content(post_url)

tbs = self.tbs_re.search(response.text).group(1)
fid = self.fid_re.search(response.text).group(1)

data_field = response.find('div', {'class': 'l_post l_post_bright j_l_post clearfix '}).get('data-field')
json_object = json.loads(data_field)
pid = json_object['content']['post_id']
tbs = self.__get_tbs(post.get_url())
fid = post.fid
pid = post.pid

form_data = {'day': 1, 'fid': fid, 'tbs': tbs, 'ie': 'gbk', 'user_name[]': author, 'pid[]': pid,
'reason': 'Test'}
form_data = {'day': 1, 'fid': fid, 'tbs': tbs, 'ie': 'gbk', 'user_name[]': post.get_author(), 'pid[]': pid,
'reason': reason}

response = self.session_worker.post(self.ban_url, data=form_data)
response = self.session_worker.post(self.ban_url, data=form_data).json()

return response.text
return response['errno'] == 0

def __get_tbs(self, post_url):
"""
Expand Down

0 comments on commit 2dd26e4

Please sign in to comment.