Skip to content

Instantly share code, notes, and snippets.

@spookyahell
Last active December 20, 2018 17:53
Show Gist options
  • Select an option

  • Save spookyahell/65583bd933c97ee8a93147bb339475d8 to your computer and use it in GitHub Desktop.

Select an option

Save spookyahell/65583bd933c97ee8a93147bb339475d8 to your computer and use it in GitHub Desktop.
client object for 9kw.eu
from UA import firefox
from time import sleep
import requests
class nineKWclientException(Exception):
pass
class nineKWclient(object):
def __init__(self, APIKEY):
self.APIKEY = APIKEY
self.captcha_id = None
def send_captcha(self, file, type = 'reg', page_url = None):
if not type in ['reg','recaptchav2']:
raise nineKWclientException('This type is not (yet) available')
params = {'apikey':self.APIKEY,
'action':'usercaptchaupload',
'file-upload-01':file}
if type == 'recaptchav2':
if page_url is None:
raise nineKWclientException('page_url parameter required for this captcha type...')
params.update({'interactive':'1','oldsource':'recaptchav2','pageurl':page_url})
r = requests.get(f'https://www.9kw.eu/index.cgi', params = params, headers = firefox)
kw_captcha_id = r.text.strip()
self.captcha_id = kw_captcha_id
def recieve_answer(self):
if not self.captcha_id:
raise nineKWclientException('First you must send a captcha...')
CaptchaSuccess = False
while not CaptchaSuccess:
r = requests.get(f'https://www.9kw.eu/index.cgi',
params = {'apikey':self.APIKEY,
'action':'usercaptchacorrectdata',
'id':self.captcha_id,
'json':'1'})
o = r.json()
answer = o['answer']
if answer:
CaptchaSuccess = True
return True, answer
#~ else:
#~ print('Answer not ready yet, waiting 10 seconds...')
else:
if answer is None:
return False, 'Captcha failed; exiting, you are welcome to try again, sometimes it takes a few tries'
else:
print('Captcha not ready yet, trying again (in 10 seconds)')
sleep(10)
def send_status(self, is_ok = True):
if not self.captcha_id:
raise nineKWclientException('First you must send a captcha...')
params = {'apikey':self.APIKEY,
'action':'usercaptchacorrectback',
'id':self.captcha_id,
'correct':'1',
'json':'1'}
if not is_okay:
params.update({'correct':'2'})
r = requests.get(f'https://www.9kw.eu/index.cgi', params = params)
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment