Update simpleTest to latest API and solve before answering
Signed-off-by: hrj <harshad.rj@gmail.com>
This commit is contained in:
parent
d3a2c6fa35
commit
433621f046
|
@ -1,12 +1,8 @@
|
|||
import http.client
|
||||
import json
|
||||
import subprocess
|
||||
|
||||
conn = http.client.HTTPConnection('localhost', 8888)
|
||||
conn.request("GET", "/v1/token?email=test")
|
||||
response = conn.getresponse()
|
||||
responseStr = response.read()
|
||||
user = json.loads(responseStr)
|
||||
token = user["token"]
|
||||
|
||||
params = """{
|
||||
"level": "medium",
|
||||
|
@ -15,13 +11,25 @@ params = """{
|
|||
}"""
|
||||
|
||||
def getCaptcha():
|
||||
conn.request("POST", "/v1/captcha", body=params, headers={'access-token': user["token"]})
|
||||
conn.request("POST", "/v1/captcha", body=params)
|
||||
response = conn.getresponse()
|
||||
|
||||
if response:
|
||||
responseStr = response.read()
|
||||
return json.loads(responseStr)
|
||||
|
||||
def getAndSolve(idStr):
|
||||
conn.request("GET", "/v1/media?id=" + idStr)
|
||||
response = conn.getresponse()
|
||||
|
||||
if response:
|
||||
responseBytes = response.read()
|
||||
with open("captcha.png", "wb") as f:
|
||||
f.write(responseBytes)
|
||||
ocrResult = subprocess.Popen("gocr captcha.png", shell=True, stdout=subprocess.PIPE)
|
||||
ocrAnswer = ocrResult.stdout.readlines()[0].strip().decode()
|
||||
return ocrAnswer
|
||||
|
||||
def postAnswer(captchaId, ans):
|
||||
reply = {"answer": ans, "id" : captchaId}
|
||||
conn.request("POST", "/v1/answer", json.dumps(reply))
|
||||
|
@ -33,6 +41,6 @@ def postAnswer(captchaId, ans):
|
|||
|
||||
for i in range(0, 10000):
|
||||
captcha = getCaptcha()
|
||||
#print(captcha)
|
||||
captchaId = captcha["id"]
|
||||
print(i, postAnswer(captchaId, "xyz"))
|
||||
ans = getAndSolve(captchaId)
|
||||
print(i, postAnswer(captchaId, ans))
|
||||
|
|
Loading…
Reference in New Issue