|
5 | 5 |
|
6 | 6 | load_dotenv(dotenv_path='sample.env')
|
7 | 7 |
|
| 8 | +def get_submissions(slug): |
| 9 | + url = "https://leetcode-cn.com/graphql" |
| 10 | + params = {'operationName': "Submissions", |
| 11 | + 'variables': {"offset": 0, "limit": 20, "lastKey": '', "questionSlug": slug}, |
| 12 | + 'query': '''query Submissions($offset: Int!, $limit: Int!, $lastKey: String, $questionSlug: String!) { |
| 13 | + submissionList(offset: $offset, limit: $limit, lastKey: $lastKey, questionSlug: $questionSlug) { |
| 14 | + lastKey |
| 15 | + hasNext |
| 16 | + submissions { |
| 17 | + id |
| 18 | + statusDisplay |
| 19 | + lang |
| 20 | + runtime |
| 21 | + timestamp |
| 22 | + url |
| 23 | + isPending |
| 24 | + __typename |
| 25 | + } |
| 26 | + __typename |
| 27 | + } |
| 28 | + }''' |
| 29 | + } |
| 30 | + |
| 31 | + json_data = json.dumps(params).encode('utf8') |
| 32 | + |
| 33 | + headers = {'User-Agent': user_agent, 'Connection': 'keep-alive', 'Referer': 'https://leetcode-cn.com/accounts/login/', |
| 34 | + "Content-Type": "application/json"} |
| 35 | + resp = session.post(url, data=json_data, headers=headers, timeout=10) |
| 36 | + content = resp.json() |
| 37 | + for submission in content['data']['submissionList']['submissions']: |
| 38 | + print(submission) |
| 39 | + |
8 | 40 | # load details from ENV
|
9 | 41 | repo_name = os.getenv("REPO_NAME")
|
10 | 42 | access_token = os.getenv("GITHUB_ACCESS_TOKEN")
|
|
26 | 58 | for i in all_files:
|
27 | 59 | if i.filename[-3:] == ".py":
|
28 | 60 | file_url = i.raw_url
|
29 |
| - problem_name = i.filename.lower() |
| 61 | + problem_name = i.filename[9:].lower() |
30 | 62 |
|
31 | 63 | # parse question id and problem name
|
32 | 64 | question_id = int(problem_name[0:4])
|
|
42 | 74 | headers = {
|
43 | 75 | "Origin": "https://leetcode.com",
|
44 | 76 | "content-type": "application/json",
|
45 |
| - "X-CSRFToken": leetcode_csrf_token, |
46 |
| - "Referer": leetcode_submission_url, |
| 77 | + "Referer": "https://leetcode.com/problems/two-sum/submissions/", |
47 | 78 | "User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:81.0) Gecko/20100101 Firefox/81.0",
|
48 | 79 | # "Cookie": f"csrftoken={leetcode_csrf_token};LEETCODE_SESSION={leetcode_session_token}",
|
49 | 80 | }
|
| 81 | + |
| 82 | +headers = { |
| 83 | + 'Connection': 'keep-alive', |
| 84 | + 'Content-Type': 'application/json', |
| 85 | + 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36', |
| 86 | + 'Referer': 'https://leetcode.com/accounts/login/', |
| 87 | + "origin": "https://leetcode.com" |
| 88 | +} |
| 89 | + |
50 | 90 | cookies = {
|
51 | 91 | "csrftoken": leetcode_csrf_token,
|
52 | 92 | "LEETCODE_SESSION": leetcode_session_token,
|
53 | 93 | }
|
54 | 94 | body = {"question_id": str(question_id), "lang": language, "typed_code": code}
|
55 | 95 |
|
| 96 | +leetcode_submission_url2 = f"https://leetcode.com/api/problems/all" |
| 97 | +leetcode_submission_url3 = f"https://leetcode.com/accounts/login/" |
56 | 98 | # send request
|
| 99 | +sub = requests.get(leetcode_submission_url2, headers=headers, data=body, cookies=cookies) |
57 | 100 | submit = requests.post(
|
58 |
| - leetcode_submission_url, headers=headers, data=body, cookies=cookies |
| 101 | + leetcode_submission_url3, headers=headers, cookies=cookies |
59 | 102 | )
|
60 | 103 |
|
61 | 104 | print(submit.status_code)
|
|
0 commit comments