Skip to content

Instantly share code, notes, and snippets.

@Kylmakalle
Last active November 18, 2017 16:00
Show Gist options
  • Save Kylmakalle/7d8c36671aebefd48969fabcd9a4415c to your computer and use it in GitHub Desktop.
Save Kylmakalle/7d8c36671aebefd48969fabcd9a4415c to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import requests
s = requests.session()
URL = 'https://2ch.hk/'
BOARD = 'test'
THREAD = '31942'
COMMENT = 'привет'
EMAIL = None
NAME = None
SUBJECT = None
def get_capthcha(thread, board):
if thread:
captcha = s.get(URL + 'api/captcha/2chaptcha/id?board={}&thread={}'.format(board, thread)).json()
else:
captcha = s.get(URL + 'api/captcha/2chaptcha/id?board={}'.format(board)).json()
return captcha
captcha = get_capthcha(THREAD, BOARD)
captcha_photo = s.get(URL + 'api/captcha/2chaptcha/image/{}'.format(captcha['id'])).url
print(captcha_photo)
captcha_answer = input('Капча: ')
while True:
captcha_check = s.get(URL + 'api/captcha/2chaptcha/check/{}?'.format(captcha['id']),
params={'value': captcha_answer}).json()
if captcha_check.get('error'):
print(captcha_check['description'])
captcha_answer = input('Капча: ')
else:
break
payload = {'json': 1, 'task': 'post', 'board': BOARD, 'thread': THREAD,
'comment': COMMENT,
'captcha_type': '2chaptcha',
'2chaptcha_id': captcha['id'], '2chaptcha_value': captcha_answer}
if EMAIL:
payload['email'] = EMAIL
if NAME:
payload['name'] = NAME
if SUBJECT:
payload['subject'] = SUBJECT
files = {
name: (None, str(value)) for name, value in payload.items()
}
post = s.post('https://2ch.hk/makaba/posting.fcgi', files=files)
result = post.json()
if result['Error']:
print(result['Reason'])
else:
print('Пост:', URL + BOARD + '/res/' + THREAD + '.html#' + str(result['Num']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment