Open micvbang opened 10 years ago
Yep, you're very right! The code right now is pretty brutal in regards to requests. Do you have any suggestions as to where the cookie should be saved? There also has to be methods for renewing expired cookies.
I've implemented a simple storing mechanism in 98cf513. There is no handling of session timeouts yet, as this seems to be enforced server-side and not via cookies expiring (expiry dates are several months ahead), so this needs to be researched.
A simple way to handle this would be to just bump the file modification timestamp on the cookie storage file whenever a successful request has been made, and check if it's more than X minutes old before any subsequent request (where X is the assumed max session idle time), and if so, just re-authenticate.
This pulls in another dependency, tough-cookie-filestore, which request.jar already has support for, so the amount of code in this patch is low.
Needless to say, this speeds things up considerably, but the way it's implemented is a bit hacky (all the dealings with the cookiejar should probably be refactored to a separate module, plus the way it deals with not having schoolUrl is kind of terrible).
It's probably a good idea to store cookies and use them in future requests s.t. a user doesn't perform the log in sequence in every single time the program is executed.
This will both make script faster (because of less requests) and will put less load on the itslearning servers. Win-win.