Skip to content

Commit 1dd9a0e

Browse files
committed
Fix expiration time check in is_user_logged function
1 parent 7bd1b36 commit 1dd9a0e

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Now you can either install it or just execute it:
4848

4949
- To install leetcode-export in your system:
5050
```bash
51-
python ./setup.py install
51+
python setup.py install
5252
```
5353

5454
- To run the project without installing it:

leetcode_export/leetcode.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

leetcode_export/leetcode_rest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
BASE_URL = 'https://leetcode.com'
66
LOGIN_URL = 'https://leetcode.com/accounts/login/'
7-
SUBMISSIONS_API_URL = 'https://leetcode.com/api/submissions/?offset={}&limit=20'
7+
SUBMISSIONS_API_URL = 'https://leetcode.com/api/submissions/?offset={}&limit={}'
88
PROBLEM_URL = 'https://leetcode.com/problems/'
99

1010

0 commit comments

Comments
 (0)