Skip to content

Commit ebeeeb5

Browse files
feat: add daily challenge
1 parent 6f7985b commit ebeeeb5

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

src/commands/daily.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import typer
2+
from src.commands import show
3+
from src.commands.edit import edit
4+
from src.server.api import get_daily_question
5+
6+
def daily(
7+
lang: str = typer.Argument("python", help="Programming language to use."),
8+
editor: str = typer.Option("code", '-e', help="Code editor to use."),
9+
):
10+
"""Check the daily problem."""
11+
result = get_daily_question()
12+
question = result['data']['activeDailyCodingChallengeQuestion']
13+
14+
show(problem=question['question']['titleSlug'], layout=True)
15+
16+
if editor:
17+
edit(problem=question['question']['titleSlug'], lang=lang, editor=editor)

src/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import profile
22
import typer
33
from src import show, profile
4+
from src.commands.daily import daily
45
from src.commands.edit import edit
56
from src.commands.list_problems import list_problems
67
from src.commands.login import login, logout
@@ -11,6 +12,7 @@
1112

1213
app.command(name="show")(show)
1314
app.command(name="list")(list_problems)
15+
app.command(name="daily")(daily)
1416
app.command(name="profile")(profile)
1517
app.command(name="login")(login)
1618
app.command(name="logout")(logout)

src/server/api.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from gql import gql, Client
22
from gql.transport.requests import RequestsHTTPTransport
3+
import requests
34

45
def create_leetcode_client(csrf_token: str, session_id: str):
56
headers = {
@@ -177,3 +178,37 @@ def fetch_problem_list(
177178
except Exception as e:
178179
print(f"Error fetching data: {str(e)}")
179180
return None
181+
182+
183+
def get_daily_question():
184+
url = "https://leetcode.com/graphql"
185+
query = """
186+
query questionOfToday {
187+
activeDailyCodingChallengeQuestion {
188+
date
189+
userStatus
190+
link
191+
question {
192+
titleSlug
193+
title
194+
translatedTitle
195+
acRate
196+
difficulty
197+
freqBar
198+
frontendQuestionId: questionFrontendId
199+
isFavor
200+
paidOnly: isPaidOnly
201+
status
202+
hasVideoSolution
203+
hasSolution
204+
topicTags {
205+
name
206+
id
207+
slug
208+
}
209+
}
210+
}
211+
}
212+
"""
213+
response = requests.post(url, json={'query': query})
214+
return response.json()

0 commit comments

Comments
 (0)