-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleetcode.py
More file actions
36 lines (30 loc) · 861 Bytes
/
leetcode.py
File metadata and controls
36 lines (30 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import requests
LEETCODE_SESSION = "ADD YOUR LEETCODE SESSION"
def get_recent_leetcode(username, limit=20):
url = "https://leetcode.com/graphql"
headers = {
"Content-Type": "application/json",
"Cookie": f"LEETCODE_SESSION={LEETCODE_SESSION}",
"Referer": f"https://leetcode.com/u/{username}/"
}
query = """
query recentAcSubmissions($username: String!, $limit: Int!) {
recentAcSubmissionList(username: $username, limit: $limit) {
title
titleSlug
timestamp
}
}
"""
res = requests.post(
url,
headers=headers,
json={
"query": query,
"variables": {
"username": username,
"limit": limit
}
}
)
return res.json().get("data", {}).get("recentAcSubmissionList", [])