Skip to content

Commit ff648a6

Browse files
committed
Added Script to check and comment
1 parent d57bc85 commit ff648a6

File tree

3 files changed

+384
-4
lines changed

3 files changed

+384
-4
lines changed

.github/workflows/leetcodeChecker.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: py
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
# - name: checkout repo content # checkout is unecessary
12+
# uses: actions/checkout@v2
13+
- name: setup python
14+
uses: actions/setup-python@v2
15+
with:
16+
python-version: 3.8
17+
- name: execute checker script
18+
run: |
19+
python codechecker.py
20+
with:
21+
github-token: ${{ github.token }}
22+
env:
23+
PR_NUMBER: ${{ github.event.pull_request.number }}
24+
leetcode-csrf-token: ${{ secrets.LEETCODE_CSRF_TOKEN }}
25+
leetcode-session: ${{ secrets.LEETCODE_SESSION }}
26+

codechecker.py

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,38 @@
55

66
load_dotenv(dotenv_path='sample.env')
77

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+
840
# load details from ENV
941
repo_name = os.getenv("REPO_NAME")
1042
access_token = os.getenv("GITHUB_ACCESS_TOKEN")
@@ -26,7 +58,7 @@
2658
for i in all_files:
2759
if i.filename[-3:] == ".py":
2860
file_url = i.raw_url
29-
problem_name = i.filename.lower()
61+
problem_name = i.filename[9:].lower()
3062

3163
# parse question id and problem name
3264
question_id = int(problem_name[0:4])
@@ -42,20 +74,31 @@
4274
headers = {
4375
"Origin": "https://leetcode.com",
4476
"content-type": "application/json",
45-
"X-CSRFToken": leetcode_csrf_token,
46-
"Referer": leetcode_submission_url,
77+
"Referer": "https://leetcode.com/problems/two-sum/submissions/",
4778
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:81.0) Gecko/20100101 Firefox/81.0",
4879
# "Cookie": f"csrftoken={leetcode_csrf_token};LEETCODE_SESSION={leetcode_session_token}",
4980
}
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+
5090
cookies = {
5191
"csrftoken": leetcode_csrf_token,
5292
"LEETCODE_SESSION": leetcode_session_token,
5393
}
5494
body = {"question_id": str(question_id), "lang": language, "typed_code": code}
5595

96+
leetcode_submission_url2 = f"https://leetcode.com/api/problems/all"
97+
leetcode_submission_url3 = f"https://leetcode.com/accounts/login/"
5698
# send request
99+
sub = requests.get(leetcode_submission_url2, headers=headers, data=body, cookies=cookies)
57100
submit = requests.post(
58-
leetcode_submission_url, headers=headers, data=body, cookies=cookies
101+
leetcode_submission_url3, headers=headers, cookies=cookies
59102
)
60103

61104
print(submit.status_code)

0 commit comments

Comments
 (0)