-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresponses.py
More file actions
25 lines (20 loc) · 975 Bytes
/
Copy pathresponses.py
File metadata and controls
25 lines (20 loc) · 975 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
import random
import requests
def handle_response(username) -> str:
if username.startswith('help'):
return "Usage: !leetcode <username> for public or ?leetcode <username> for private"
else:
try:
response = requests.get(f"https://leetcode-stats-api.herokuapp.com/{username}")
data = response.json()
total_solved = data['totalSolved']
easy_solved = data['easySolved']
medium_solved = data['mediumSolved']
hard_solved = data['hardSolved']
ranking = data['ranking']
if ranking == 0:
return "Please enter a valid leetcode username."
return f"{username}:\nTotal Solved: {total_solved}\nEasy Solved: {easy_solved}\nMedium Solved: {medium_solved}\nHard Solved: {hard_solved}\nRanking: {ranking}"
except Exception as e:
print(e)
return "Error retrieving user data from LeetCode."