tristan-tyler / Humbler-Unbundler

Grabs keys from Humble Bundle and redeems them on Steam
MIT License
7 stars 1 forks source link

check .used_keys not valid json when script stops prematurely #2

Closed MSDNAndi closed 1 year ago

MSDNAndi commented 1 year ago

When the script stops prematurely, .used_keys is 0 bytes and invalid .json. On restart it will fail. e.g. check for 0 length and skip (and delete) file?

tristan-tyler commented 1 year ago

Presently in the code, once the script has been running long enough, it will encounter a response of 53 from the steam api and will then put all of the info stored in the used_keys variable to the .used_keys file.

Does it fail? If so, could I get the error message you received? Have you run the script for long enough for this to happen?

If you would like it to save more frequently, I suggest you have it save the file on a different message. Move line 114 open("./.used_keys", "w", encoding="utf8").write(dumps(used_keys)) inside a different if statement, for example, under line 96. Or if you'd like it to save every iteration, to line 90.

Let me know if you have any questions or additional issues.

MSDNAndi commented 1 year ago

Thanks, I had the issue when something went wrong at the very beginning. e.g. when trying with Chrome it failed and once you have a 0 bytes file, it cannot recover from it. With Firefox my first attempt I think I was too impatient and did not wait long enough for enough of the page to fully load. I am not entirely sure if you are supposed to continue right away once logged in or if you should wait until the displayed page in Firefox does not change (populate with titles) anymore which could be a long time.

As for saving - response 53 means "too many requests" then?

Maybe an option for a good-old log-file could make sense.

tristan-tyler commented 1 year ago

Added logging functionality for future users :) I also got chrome to behave with a quick workaround