-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_daily_question.py
49 lines (45 loc) · 1.2 KB
/
get_daily_question.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
import requests
import json
payload = {
"query": """
query questionOfToday {
activeDailyCodingChallengeQuestion {
date
userStatus
link
question {
acRate
difficulty
freqBar
frontendQuestionId: questionFrontendId
isFavor
paidOnly: isPaidOnly
status
title
titleSlug
hasVideoSolution
hasSolution
topicTags {
name
id
slug
}
}
}
}
""",
"variables": {},
"operationName": "questionOfToday",
}
headers = {
"authority": "leetcode.com",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36",
}
req = requests.Request("POST", "https://leetcode.com/graphql/", headers=headers, json=payload)
r = req.prepare()
s = requests.Session()
response = s.send(r)
if response.status_code == 200:
print(json.dumps(response.json()))
else:
print("Failed to fetch data. Status code:", response.status_code, response.text)