Open 313ctric opened 3 years ago
The only comment I would have is we could utilize the interval
returned by the API call in the same way the web interface does instead of waiting the maximum amount of time. It would mean more web requests, but a possibly shorter wait time. @JohnHammond do you have an opinion either way here?
This code waits for it to solve by requesting every poll_interval
until it returns last
(finished flag) as 1
or we take too long.
It is about 0.5-1 second(s) faster, and in testing sent 3 rather than 2 requests so is probably worth the change.
from time import time as curr_time
...
data = {"ciphertext":cipher,"clues":clues,"mode":"auto","was_auto":True,"was_clue":False}
solve_response = json.loads( requests.post(url, data=json.dumps(data), headers=headers, verify=False).text )
url = "https://quipqiup.com/status"
data = {"id":solve_response["id"]}
status_response = json.loads( requests.post(url, data=json.dumps(data), headers=headers, verify=False).text )
start_time = curr_time()
while (curr_time() - start_time) <= min(solve_response["max_time"], time) and status_response["last"] != 1:
sleep( min(solve_response["poll_interval"], time) )
status_response = json.loads( requests.post(url, data=json.dumps(data), headers=headers, verify=False).text )
return json.dumps(status_response)
@calebstewart is this PR good to merge? The current version is broken, so would be good to have some fix applied.
Fix issue #27 by using the actual quipqiup site as the existing api always returns a 500 (Internal Server Error) response code.
It works, but I don't like having to set the
verify=False
with requests as this stops certificate validation which makes it less secure. I also dislike usingsleep()
, but I can't think of a better way to wait for the server.