@@ -37,6 +37,11 @@ def log_in(self, username: str, password: str) -> bool:
3737 return False
3838
3939 def set_cookies (self , cookies : str ) -> bool :
40+ '''
41+ Log in to LeetCode using cookies
42+ :param cookies: string with cookies to set
43+ :return: bool, true if login is successful, false otherwise
44+ '''
4045 cookies_list = cookies .split (';' )
4146 cookies_list = map (lambda el : el .split ('=' ), cookies_list )
4247 for cookies in cookies_list :
@@ -49,6 +54,10 @@ def set_cookies(self, cookies: str) -> bool:
4954 return False
5055
5156 def is_user_logged (self ) -> bool :
57+ '''
58+ Check if user is logged in LeetCode account
59+ :return: bool, true if user is logged in, false otherwise
60+ '''
5261 if self .user_logged and datetime .datetime .now () < self .user_logged_expiration :
5362 return True
5463 cookie_dict = self .session .cookies .get_dict ()
@@ -64,6 +73,11 @@ def is_user_logged(self) -> bool:
6473 return False
6574
6675 def get_problem (self , slug : str ) -> Problem :
76+ '''
77+ Get LeetCode problem info
78+ :param slug: problem identifier
79+ :return: Problem
80+ '''
6781 response = self .session .post (
6882 GRAPHQL_URL ,
6983 json = question_detail_json (slug ))
@@ -72,6 +86,10 @@ def get_problem(self, slug: str) -> Problem:
7286 return Problem .from_dict (problem_dict )
7387
7488 def get_submissions (self ) -> Dict [str , List [Submission ]]:
89+ '''
90+ Get list of submission for logged user
91+ :return: Dict[str, List[Submission]], dictionary with slug as key and submission for given problem as value
92+ '''
7593 if not self .is_user_logged ():
7694 logging .warning ("Trying to get user submissions while user is not logged in" )
7795 return {}
@@ -86,7 +104,8 @@ def get_submissions(self) -> Dict[str, List[Submission]]:
86104 for submission_dict in response_json ['submissions_dump' ]:
87105 submission_dict ['runtime' ] = submission_dict ['runtime' ].replace (' ' , '' )
88106 submission_dict ['memory' ] = submission_dict ['memory' ].replace (' ' , '' )
89- submission_dict ['date_formatted' ] = datetime .datetime .fromtimestamp (submission_dict ['timestamp' ]).strftime (
107+ submission_dict ['date_formatted' ] = datetime .datetime .fromtimestamp (
108+ submission_dict ['timestamp' ]).strftime (
90109 '%Y-%m-%d %H.%M.%S' )
91110 submission_dict ['extension' ] = language_to_extension (submission_dict ['lang' ])
92111 for key in submission_dict :
0 commit comments