-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleetcode_graphql_query.py
52 lines (46 loc) · 1.11 KB
/
leetcode_graphql_query.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
50
51
52
import webbrowser
import requests
url = "https://leetcode.com/graphql"
query = """
query questionOfToday {
activeDailyCodingChallengeQuestion {
date
question {
difficulty
status
title
topicTags {
name
id
slug
}
}
}
}
"""
headers = {
"Content-Type": "application/json",
}
data = {"query": query}
response = requests.post(url, headers=headers, json=data)
if response.status_code == 200:
result = response.json()
question_data = result["data"]["activeDailyCodingChallengeQuestion"]
# Get info
question_details = question_data["question"]
file1 = open("daily_question.txt", "w")
date = question_data["date"]
title = question_details["title"]
difficulty = question_details["difficulty"]
topic_tags = [tag["name"] for tag in question_details["topicTags"]]
# print to file
L = [
f"Date: {date}\n",
f"Title: {title} \n",
f"Difficulty: {difficulty} \n",
f"Topic Tags: {topic_tags} \n",
]
print(L)
file1.writelines(L)
else:
print("Failed to fetch the question of the day.")