|
11 | 11 |
|
12 | 12 | from leetcode_export.leetcode_graphql import GRAPHQL_URL, question_detail_json, Problem |
13 | 13 | from leetcode_export.leetcode_rest import ( |
| 14 | + BASE_URL, |
14 | 15 | LOGIN_URL, |
15 | 16 | SUBMISSIONS_API_URL, |
16 | 17 | Submission, |
17 | | - BASE_URL, |
18 | 18 | ) |
19 | 19 | from leetcode_export.utils import ( |
| 20 | + dict_camelcase_to_snakecase, |
20 | 21 | language_to_extension, |
21 | 22 | remove_special_characters, |
22 | | - dict_camelcase_to_snakecase, |
| 23 | + REQUEST_HEADERS, |
23 | 24 | ) |
24 | 25 |
|
25 | 26 |
|
26 | 27 | class LeetCode(object): |
27 | 28 | def __init__(self): |
28 | 29 | logging.debug("LeetCode class instantiated") |
29 | 30 | self.session = requests.Session() |
| 31 | + self.session.headers.update(REQUEST_HEADERS) |
30 | 32 | self.user_logged = False |
31 | 33 | self.user_logged_expiration = datetime.datetime.now() |
32 | 34 |
|
@@ -104,6 +106,7 @@ def is_user_logged(self) -> bool: |
104 | 106 | cookie_dict = self.session.cookies.get_dict() |
105 | 107 | if "csrftoken" in cookie_dict and "LEETCODE_SESSION" in cookie_dict: |
106 | 108 | get_request = self.session.get(SUBMISSIONS_API_URL.format(0, 1)) |
| 109 | + logging.debug(get_request.text) |
107 | 110 | sleep(1) # cooldown time for get request |
108 | 111 | if "detail" not in get_request.json(): |
109 | 112 | logging.debug("User is logged in") |
@@ -145,9 +148,9 @@ def get_submissions(self) -> Iterator[Submission]: |
145 | 148 | and response_json["has_next"] |
146 | 149 | ): |
147 | 150 | logging.debug(f"Exporting submissions from {current} to {current + 20}") |
148 | | - response_json = self.session.get( |
149 | | - SUBMISSIONS_API_URL.format(current, 20) |
150 | | - ).json() |
| 151 | + response = self.session.get(SUBMISSIONS_API_URL.format(current, 20)) |
| 152 | + logging.debug(response.content) |
| 153 | + response_json = response.json() |
151 | 154 | if "submissions_dump" in response_json: |
152 | 155 | for submission_dict in response_json["submissions_dump"]: |
153 | 156 | submission_dict["runtime"] = submission_dict["runtime"].replace( |
|
0 commit comments