@@ -47,11 +47,12 @@ def set_cookies(self, cookies: str):
4747 logging .warning ("Cookies set failed" )
4848
4949 def is_user_logged (self ) -> bool :
50- if self .user_logged and datetime .datetime .now () > self .user_logged_expiration :
50+ if self .user_logged and datetime .datetime .now () < self .user_logged_expiration :
5151 return True
5252 cookie_dict = self .session .cookies .get_dict ()
5353 if 'csrftoken' in cookie_dict and 'LEETCODE_SESSION' in cookie_dict :
54- get_request = self .session .get (SUBMISSIONS_API_URL .format (0 ))
54+ get_request = self .session .get (SUBMISSIONS_API_URL .format (0 , 1 ))
55+ sleep (1 ) # cooldown time for get request
5556 if 'detail' not in get_request .json ():
5657 logging .debug ("User is logged in" )
5758 self .user_logged = True
@@ -78,12 +79,12 @@ def get_submissions(self) -> Dict[str, List[Submission]]:
7879 while 'detail' not in response_json and 'has_next' in response_json and response_json ['has_next' ]:
7980 logging .info (f"Exporting submissions from { current } to { current + 20 } " )
8081 response_json = self .session .get (
81- SUBMISSIONS_API_URL .format (current )).json ()
82+ SUBMISSIONS_API_URL .format (current , 20 )).json ()
8283 if 'submissions_dump' in response_json :
8384 for submission_dict in response_json ['submissions_dump' ]:
8485 submission_dict ['runtime' ] = submission_dict ['runtime' ].replace (' ' , '' )
8586 submission_dict ['memory' ] = submission_dict ['memory' ].replace (' ' , '' )
86- submission_dict ['date_formatted' ] = datetime .fromtimestamp (submission_dict ['timestamp' ]).strftime (
87+ submission_dict ['date_formatted' ] = datetime .datetime . fromtimestamp (submission_dict ['timestamp' ]).strftime (
8788 '%Y-%m-%d %H.%M.%S' )
8889 submission_dict ['extension' ] = language_to_extension (submission_dict ['lang' ])
8990 for key in submission_dict :
@@ -93,8 +94,9 @@ def get_submissions(self) -> Dict[str, List[Submission]]:
9394 if submission .title_slug not in dictionary :
9495 dictionary [submission .title_slug ] = []
9596 dictionary [submission .title_slug ].append (submission )
96- sleep ( 1 )
97+
9798 current += 20
99+ sleep (1 )
98100 if 'detail' in response_json :
99101 logging .warning (response_json ['detail' ])
100102 return dictionary
0 commit comments