# -*- coding: utf-8 -*-
import urllib2
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers
USERNAME = ''
PASSWORD = ''
# Decaptcher HTTP API URL
SERVICE_URL = 'http://decaptcher.com/poster/'
# Decaptcher Constants
ERROR_OK = 0
ERROR_GENERAL = -1
ERROR_STATUS = -2
ERROR_NET_ERROR = -3
ERROR_TEXT_SIZE = -4
ERROR_OVERLOAD = -5
ERROR_BALANCE = -6
ERROR_TIMEOUT = -7
ERROR_UNKNOWN = -200
TIMEOUT_DEFAULT = 0
TIMEOUT_LONG = 1
TIMEOUT_30SECONDS = 2
TIMEOUT_60SECONDS = 3
TIMEOUT_90SECONDS = 4
TYPE_UNSPECIFIED = 0
STATUS_INIT = 1
STATUS_LOGIN = 2
STATUS_HASH = 3
STATUS_PICTURE = 4
register_openers()
def solve(path):
extra = {
'pict' : open(path, 'rb'),
'pict_to' : '0',
'pict_type' : '0'
}
out = _call('picture2', extra)
out = out.split('|')
return out
def bad(major_id, minor_id):
extra = {'major_id' : major_id, 'minor_id' : minor_id}
out = _call('picture_bad2', extra)
out = out.split('|')
return out
def balance():
return _call('balance')
def _call(function, extra = {}):
data = {
'function': function,
'username': USERNAME,
'password': PASSWORD
}
data.update(extra)
datagen, headers = multipart_encode(data)
request = urllib2.Request(SERVICE_URL, datagen, headers)
content = urllib2.urlopen(request).read()
return content