4141LC_SUBMISSION = LC_BASE + '/submissions/detail/{submission}/'
4242LC_CHECK = LC_BASE + '/submissions/detail/{submission}/check/'
4343LC_PROBLEM_SET_ALL = LC_BASE + '/problemset/all/'
44+ LC_PROGRESS_ALL = LC_BASE + '/api/progress/all/'
4445
4546EMPTY_FREQUENCIES = [0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ]
4647
@@ -69,7 +70,6 @@ def _make_headers():
6970 assert is_login ()
7071 headers = {'Origin' : LC_BASE ,
7172 'Referer' : LC_BASE ,
72- 'X-CSRFToken' : session .cookies ['csrftoken' ],
7373 'X-Requested-With' : 'XMLHttpRequest' }
7474 return headers
7575
@@ -143,6 +143,19 @@ def is_login():
143143 return session and 'LEETCODE_SESSION' in session .cookies
144144
145145
146+ def get_progress ():
147+ headers = _make_headers ()
148+ res = session .get (LC_PROGRESS_ALL , headers = headers )
149+ if res .status_code != 200 :
150+ _echoerr ('cannot get the progress' )
151+ return None
152+
153+ data = res .json ()
154+ if 'solvedTotal' not in data :
155+ return None
156+ return data
157+
158+
146159def load_session_cookie (browser ):
147160 if browser_cookie3 is None :
148161 _echoerr ('browser_cookie3 not installed: pip3 install browser_cookie3 --user' )
@@ -170,9 +183,9 @@ def load_session_cookie(browser):
170183 session = requests .Session ()
171184 session .cookies .set_cookie (session_cookie )
172185
173- res = session . get ( LC_BASE )
174- if res . status_code != 200 :
175- _echoerr ('cannot open ' + LC_BASE + '. Session might have expired .' )
186+ progress = get_progress ( )
187+ if progress is None :
188+ _echoerr ('cannot get progress. Please relogin in your browser .' )
176189 keyring .delete_password ('leetcode.vim' , 'SESSION_COOKIE' )
177190 return False
178191
@@ -182,7 +195,11 @@ def load_session_cookie(browser):
182195def _get_category_problems (category ):
183196 headers = _make_headers ()
184197 url = LC_CATEGORY_PROBLEMS .format (category = category )
198+ log .info ('_get_category_problems request: url="%s" headers="%s"' ,
199+ url , headers )
185200 res = session .get (url , headers = headers )
201+ log .info ('_get_category_problems response: status="%s" body="%s"' ,
202+ res .status_code , res .text )
186203 if res .status_code != 200 :
187204 _echoerr ('cannot get the category: {}' .format (category ))
188205 return []
0 commit comments