katana icon indicating copy to clipboard operation
katana copied to clipboard

Fix the quipqiup module

Open 313ctric opened this issue 4 years ago • 3 comments

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 using sleep(), but I can't think of a better way to wait for the server.

313ctric avatar Jan 06 '21 18:01 313ctric

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?

calebstewart avatar Jan 08 '21 21:01 calebstewart

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)

313ctric avatar Jan 09 '21 19:01 313ctric

@calebstewart is this PR good to merge? The current version is broken, so would be good to have some fix applied.

eljeffeg avatar Sep 20 '21 21:09 eljeffeg