Skip to content

Commit 14e5ad5

Browse files
fetched mocked user info
1 parent 241a2a2 commit 14e5ad5

File tree

3 files changed

+145
-40
lines changed

3 files changed

+145
-40
lines changed

src/commands/profile.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
from server.api import fetch_user_data
2-
from lib.ui import display_problem_stats
1+
from server.api import fetch_user_profile
32
from rich.spinner import Spinner
3+
from src.lib.ui import display_user_stats
44
from rich.live import Live
55

66
def profile():
77
"""List all available LeetCode problems."""
88
spinner = Spinner('dots')
99
with Live(spinner, refresh_per_second=10, transient=True) as live:
1010
live.console.print("[cyan]Fetching user profile...")
11-
data = fetch_user_data()
12-
display_problem_stats(data)
11+
data = fetch_user_profile()
12+
display_user_stats(data)

src/lib/ui.py

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from rich import box
55
from datetime import datetime
66

7+
import typer
8+
79
console = Console()
810

911
def format_timestamp(timestamp):
@@ -84,25 +86,71 @@ def create_profile_header(data):
8486
title="[bold cyan]LeetCode Profile[/bold cyan]"
8587
)
8688

87-
def display_problem_stats(data):
89+
def display_user_stats(data):
8890
console.clear()
8991
console.print("\n")
9092

91-
# Display profile header
92-
console.print(create_profile_header(data))
93-
console.print("\n")
93+
if not data.get('userProfile'):
94+
console.print(Panel("Could not fetch user profile", border_style="red"))
95+
return
96+
97+
user = data['userProfile']['matchedUser']
98+
profile = user['profile']
99+
100+
# Display basic profile info
101+
profile_table = Table.grid(padding=(0, 2))
102+
profile_table.add_column(justify="left")
94103

95-
# Display recent submissions
96-
recent_submissions = data.get('matchedUser', {}).get('recentSubmissionList', [])
97-
if recent_submissions:
98-
recent_activity = create_recent_activity(recent_submissions)
99-
if recent_activity:
100-
console.print(recent_activity)
101-
else:
102-
console.print(Panel("No recent activity", border_style="cyan"))
104+
profile_info = [
105+
f"[bold cyan]{user['username']}[/bold cyan]",
106+
f"[dim]Ranking:[/dim] {profile['ranking']}",
107+
f"[dim]Company:[/dim] {profile['company'] or 'Not specified'}",
108+
f"[dim]Location:[/dim] {profile['countryName'] or 'Not specified'}"
109+
]
103110

111+
if profile['skillTags']:
112+
skills = ", ".join(profile['skillTags'])
113+
profile_info.append(f"[dim]Skills:[/dim] {skills}")
114+
115+
profile_table.add_row("\n".join(profile_info))
116+
console.print(Panel(profile_table, title="[bold cyan]Profile Info[/bold cyan]", border_style="cyan"))
104117
console.print("\n")
105118

119+
# Display contest info if available
120+
if data.get('contestInfo') and data['contestInfo'].get('userContestRanking'):
121+
contest = data['contestInfo']['userContestRanking']
122+
contest_table = Table.grid(padding=(0, 2))
123+
contest_table.add_column(justify="left")
124+
contest_table.add_row(
125+
f"Rating: [yellow]{contest['rating']}[/yellow]\n"
126+
f"Global Rank: {contest['globalRanking']}/{contest['totalParticipants']}\n"
127+
f"Top: {contest['topPercentage']}%\n"
128+
f"Contests: {contest['attendedContestsCount']}"
129+
)
130+
console.print(Panel(contest_table, title="[bold yellow]Contest Stats[/bold yellow]", border_style="yellow"))
131+
console.print("\n")
132+
133+
# Display progress
134+
if data.get('progress'):
135+
progress = data['progress']
136+
console.print(create_profile_header(progress))
137+
console.print("\n")
138+
139+
# Display language stats
140+
if data.get('languageStats'):
141+
lang_stats = data['languageStats']['matchedUser']['languageProblemCount']
142+
lang_table = Table(title="Languages", box=box.ROUNDED, border_style="cyan")
143+
lang_table.add_column("Language", style="cyan")
144+
lang_table.add_column("Problems Solved", justify="right")
145+
146+
for lang in sorted(lang_stats, key=lambda x: x['problemsSolved'], reverse=True)[:5]:
147+
lang_table.add_row(
148+
lang['languageName'],
149+
str(lang['problemsSolved'])
150+
)
151+
console.print(lang_table)
152+
console.print("\n")
153+
106154
def display_problem_list(data):
107155
console.clear()
108156
console.print("\n")

src/server/api.py

Lines changed: 81 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,95 @@ def create_leetcode_client(csrf_token: str, session_id: str):
1919
fetch_schema_from_transport=False
2020
)
2121

22-
def fetch_user_data(username: str = "yuvrajsinh5252"):
22+
def fetch_user_profile(username: str = "yuvrajsinh5252"):
2323
client = create_leetcode_client("csrf_token", "session_id")
24-
variables = {"username": username}
25-
query = gql(
26-
"""
27-
query userProblemsSolved($username: String!) {
28-
allQuestionsCount {
29-
difficulty
30-
count
24+
queries = {
25+
"userProfile": """
26+
query userPublicProfile($username: String!) {
27+
matchedUser(username: $username) {
28+
contestBadge { name expired hoverText icon }
29+
username githubUrl twitterUrl linkedinUrl
30+
profile {
31+
ranking userAvatar realName aboutMe school websites
32+
countryName company jobTitle skillTags postViewCount
33+
postViewCountDiff reputation reputationDiff solutionCount
34+
solutionCountDiff categoryDiscussCount categoryDiscussCountDiff
35+
certificationLevel
36+
}
37+
}
3138
}
32-
matchedUser(username: $username) {
33-
problemsSolvedBeatsStats {
34-
difficulty
35-
percentage
39+
""",
40+
"languageStats": """
41+
query languageStats($username: String!) {
42+
matchedUser(username: $username) {
43+
languageProblemCount {
44+
languageName
45+
problemsSolved
46+
}
3647
}
37-
submitStatsGlobal {
38-
acSubmissionNum {
39-
difficulty
40-
count
48+
}
49+
""",
50+
"skillStats": """
51+
query skillStats($username: String!) {
52+
matchedUser(username: $username) {
53+
tagProblemCounts {
54+
advanced { tagName tagSlug problemsSolved }
55+
intermediate { tagName tagSlug problemsSolved }
56+
fundamental { tagName tagSlug problemsSolved }
57+
}
58+
}
59+
}
60+
""",
61+
"contestInfo": """
62+
query userContestRankingInfo($username: String!) {
63+
userContestRanking(username: $username) {
64+
attendedContestsCount rating globalRanking
65+
totalParticipants topPercentage
66+
badge { name }
67+
}
68+
userContestRankingHistory(username: $username) {
69+
attended trendDirection problemsSolved totalProblems
70+
finishTimeInSeconds rating ranking
71+
contest { title startTime }
72+
}
73+
}
74+
""",
75+
"progress": """
76+
query userSessionProgress($username: String!) {
77+
allQuestionsCount { difficulty count }
78+
matchedUser(username: $username) {
79+
submitStats {
80+
acSubmissionNum { difficulty count submissions }
81+
totalSubmissionNum { difficulty count submissions }
82+
}
83+
}
84+
}
85+
""",
86+
"calendar": """
87+
query userProfileCalendar($username: String!, $year: Int) {
88+
matchedUser(username: $username) {
89+
userCalendar(year: $year) {
90+
activeYears streak totalActiveDays
91+
dccBadges { timestamp badge { name icon } }
92+
submissionCalendar
4193
}
4294
}
4395
}
44-
}
4596
"""
46-
)
97+
}
98+
99+
results = {}
100+
for name, query in queries.items():
101+
try:
102+
results[name] = client.execute(
103+
gql(query),
104+
variable_values={"username": username}
105+
)
106+
except Exception as e:
107+
print(f"Error fetching {name}: {str(e)}")
108+
results[name] = None
47109

48-
try:
49-
result = client.execute(query, variable_values=variables)
50-
return result
51-
except Exception as e:
52-
print(f"Error fetching data: {str(e)}")
53-
return None
110+
return results
54111

55112
def fetch_problem_list(
56113
csrf_token: str,

0 commit comments

Comments
 (0)