Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 42390b9

Browse files
GitHub profile readme add
1 parent 23533c8 commit 42390b9

File tree

9 files changed

+193
-5
lines changed

9 files changed

+193
-5
lines changed

‎.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"liveServer.settings.port": 5501
3+
}

‎api/__pycache__/views.cpython-39.pyc

618 Bytes
Binary file not shown.

‎api/views.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,47 @@ def getUsername(request, username):
4747
print(easy)
4848
print(med)
4949
print(hard)
50-
return JsonResponse(json_data, status=201, safe=False)
50+
return JsonResponse(json_data, status=201, safe=False)
51+
52+
def svg(request, username):
53+
query = '''
54+
query getUserProfile($username: String!) {
55+
allQuestionsCount {
56+
difficulty
57+
count
58+
}
59+
matchedUser(username: $username) {
60+
username
61+
submitStats {
62+
acSubmissionNum {
63+
difficulty
64+
count
65+
submissions
66+
}
67+
}
68+
}
69+
}
70+
'''
71+
72+
username = username
73+
variables = {'username': username}
74+
75+
url = 'https://leetcode.com/graphql/'
76+
r = requests.post(url, json={'query': query, 'variables': variables})
77+
json_data = json.loads(r.text)
78+
print(json.dumps(json_data, indent=4))
79+
80+
usernameHandle = json_data['data']['matchedUser']['username']
81+
total = json_data['data']['matchedUser']['submitStats']['acSubmissionNum'][0]['count']
82+
easy = json_data['data']['matchedUser']['submitStats']['acSubmissionNum'][1]['count']
83+
med = json_data['data']['matchedUser']['submitStats']['acSubmissionNum'][2]['count']
84+
hard = json_data['data']['matchedUser']['submitStats']['acSubmissionNum'][3]['count']
85+
86+
print(usernameHandle)
87+
print(total)
88+
print(easy)
89+
print(med)
90+
print(hard)
91+
92+
context = {'usernameHandle': usernameHandle, 'total': total, 'easy': easy, 'med':med, 'hard': hard}
93+
return render(request, 'svg.html', context)
81 Bytes
Binary file not shown.
36 Bytes
Binary file not shown.

‎leetcodeApi/settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
TEMPLATES = [
6161
{
6262
'BACKEND': 'django.template.backends.django.DjangoTemplates',
63-
'DIRS': [],
63+
'DIRS': [os.path.join(BASE_DIR,'templates')],
6464
'APP_DIRS': True,
6565
'OPTIONS': {
6666
'context_processors': [
@@ -122,6 +122,7 @@
122122
# https://docs.djangoproject.com/en/4.0/howto/static-files/
123123

124124
STATIC_URL = 'static/'
125+
STATICFILES_DIRS = os.path.join(BASE_DIR,'static'), # new
125126

126127
# Default primary key field type
127128
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field

‎leetcodeApi/urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@
2121
urlpatterns = [
2222
path('admin/', admin.site.urls),
2323
path('', home),
24-
path('<str:username>/',getUsername),
24+
path('<str:username>/', getUsername),
25+
path('a/<str:username>/', svg),
2526
]

‎templates/index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
<meta charset="UTF-8">
55
<meta http-equiv="X-UA-Compatible" content="IE=edge">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7-
<title>Document</title>
7+
<title>HomePage</title>
88
</head>
99
<body>
10-
10+
<h1 style="text-align:center;">LeetCode Statistics API</h1>
11+
<div style="text-align:center; font-size: 20px;">Append your LeetCode user handle at the end of the homepage url to get your stats.</div>
1112
</body>
1213
</html>

‎templates/svg.html

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
2+
<svg width="330" height="180" xmlns="http://www.w3.org/2000/svg">
3+
<style>
4+
svg {
5+
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, sans-serif;
6+
font-size: 14px;
7+
line-height: 1.5;
8+
}
9+
10+
#background {
11+
width: calc(100% - 10px);
12+
height: calc(100% - 10px);
13+
14+
fill: #FFF;
15+
16+
rx: 8px;
17+
ry: 8px;
18+
}
19+
20+
.total-solved-container {
21+
display: -webkit-box;
22+
display: -ms-flexbox;
23+
display: flex;
24+
-webkit-box-pack: justify;
25+
-ms-flex-pack: justify;
26+
justify-content: space-between;
27+
color: #9e9e9e;
28+
height: 33px;
29+
}
30+
31+
.stat-wrapper {
32+
display: flex;
33+
flex-direction: column;
34+
text-align: start;
35+
}
36+
37+
.problems-solved {
38+
color: #8A8A8E;
39+
font-size: 12px;
40+
line-height: 17px;
41+
margin-bottom: 2px;
42+
white-space: nowrap;
43+
font-weight: 500;
44+
}
45+
46+
.total-solved-count {
47+
font-size: 22px;
48+
font-weight: 600;
49+
line-height: 100%;
50+
white-space: nowrap;
51+
52+
color: #262626;
53+
font-size: 22px;
54+
}
55+
56+
.difficulty-label {
57+
font-size: 12px;
58+
font-weight: normal;
59+
line-height: 17px;
60+
margin-bottom: 2px;
61+
white-space: nowrap;
62+
}
63+
64+
.easy {
65+
color: #43A047;
66+
}
67+
68+
.medium {
69+
color: #FB8C00;
70+
}
71+
72+
.hard {
73+
color: #E91E63;
74+
}
75+
76+
.total-solved-container .total-count::before {
77+
content: '/';
78+
margin: 0 1px;
79+
}
80+
81+
.total-solved-container .total-count {
82+
color: #8A8A8E;
83+
font-size: 12px;
84+
font-weight: 500;
85+
line-height: 14px;
86+
}
87+
88+
.solved {
89+
color: #262626;
90+
font-size: 14px;
91+
font-weight: 600;
92+
line-height: 100%;
93+
white-space: nowrap;
94+
}
95+
96+
.top {
97+
height: 108px;
98+
}
99+
100+
foreignObject {
101+
width: calc(100% - 10px - 32px);
102+
height: calc(100% - 10px - 24px);
103+
}
104+
</style>
105+
<g>
106+
<rect x="5" y="5" id="background" />
107+
<g>
108+
<foreignObject x="21" y="17" width="318" height="176">
109+
<div xmlns="http://www.w3.org/1999/xhtml">
110+
<div class="stat-wrapper top" size="108">
111+
<div class="problems-solved">Problems Solved</div>
112+
<div class="total-solved-count">{{total}}</div>
113+
</div>
114+
<div class="total-solved-container">
115+
<div class="stat-wrapper" data-difficulty="Easy">
116+
<div class="difficulty-label easy">Easy</div>
117+
<div class="solved">
118+
{{easy}}<span class="total-count">568</span>
119+
</div>
120+
</div>
121+
<div class="stat-wrapper" data-difficulty="Medium">
122+
<div class="difficulty-label medium">Medium</div>
123+
<div class="solved">
124+
{{med}}<span class="total-count">1203</span>
125+
</div>
126+
</div>
127+
<div class="stat-wrapper" data-difficulty="Hard">
128+
<div class="difficulty-label hard">Hard</div>
129+
<div class="solved">
130+
{{hard}}<span class="total-count">491</span>
131+
</div>
132+
</div>
133+
</div>
134+
</div>
135+
</foreignObject>
136+
</g>
137+
</g>
138+
</svg>
139+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /