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 f12009a

Browse files
svg added
1 parent 42390b9 commit f12009a

File tree

6 files changed

+133
-7
lines changed

6 files changed

+133
-7
lines changed

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

3.35 KB
Binary file not shown.

‎api/views.py

Lines changed: 127 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
from django.shortcuts import render
2-
from django.http import JsonResponse
2+
from django.http import HttpResponse, JsonResponse
33
import requests
44
import json
5+
import pandas as pd
6+
from django.utils.html import format_html
57

68
# Create your views here.
79

810
def home(request):
911
return render(request, 'index.html')
1012

1113
def getUsername(request, username):
14+
print('wwww')
15+
1216
query = '''
1317
query getUserProfile($username: String!) {
1418
allQuestionsCount {
@@ -21,7 +25,6 @@ def getUsername(request, username):
2125
acSubmissionNum {
2226
difficulty
2327
count
24-
submissions
2528
}
2629
}
2730
}
@@ -34,6 +37,13 @@ def getUsername(request, username):
3437
url = 'https://leetcode.com/graphql/'
3538
r = requests.post(url, json={'query': query, 'variables': variables})
3639
json_data = json.loads(r.text)
40+
41+
# df_data = json_data['data']['matchedUser']
42+
# df = pd.DataFrame(df_data)
43+
# print(df)
44+
print('AA', json_data)
45+
data = json.dumps(json_data, indent=3)
46+
3747
print(json.dumps(json_data, indent=4))
3848

3949
usernameHandle = json_data['data']['matchedUser']['username']
@@ -50,6 +60,8 @@ def getUsername(request, username):
5060
return JsonResponse(json_data, status=201, safe=False)
5161

5262
def svg(request, username):
63+
print('ssss')
64+
5365
query = '''
5466
query getUserProfile($username: String!) {
5567
allQuestionsCount {
@@ -68,7 +80,7 @@ def svg(request, username):
6880
}
6981
}
7082
'''
71-
83+
7284
username = username
7385
variables = {'username': username}
7486

@@ -90,4 +102,115 @@ def svg(request, username):
90102
print(hard)
91103

92104
context = {'usernameHandle': usernameHandle, 'total': total, 'easy': easy, 'med':med, 'hard': hard}
93-
return render(request, 'svg.html', context)
105+
# return HttpResponse('a', content_type="image/svg+xml")
106+
return render(request, 'svg.html', context)
107+
108+
109+
110+
def svg_icon(request, username):
111+
print('dddd')
112+
113+
query = '''
114+
query getUserProfile($username: String!) {
115+
allQuestionsCount {
116+
difficulty
117+
count
118+
}
119+
matchedUser(username: $username) {
120+
username
121+
submitStats {
122+
acSubmissionNum {
123+
difficulty
124+
count
125+
submissions
126+
}
127+
}
128+
}
129+
}
130+
'''
131+
132+
username = username
133+
variables = {'username': username}
134+
135+
url = 'https://leetcode.com/graphql/'
136+
r = requests.post(url, json={'query': query, 'variables': variables})
137+
json_data = json.loads(r.text)
138+
print(json.dumps(json_data, indent=4))
139+
140+
usernameHandle = json_data['data']['matchedUser']['username']
141+
total = json_data['data']['matchedUser']['submitStats']['acSubmissionNum'][0]['count']
142+
easy = json_data['data']['matchedUser']['submitStats']['acSubmissionNum'][1]['count']
143+
med = json_data['data']['matchedUser']['submitStats']['acSubmissionNum'][2]['count']
144+
hard = json_data['data']['matchedUser']['submitStats']['acSubmissionNum'][3]['count']
145+
146+
147+
svg_tag = format_html('<svg width="330" height="180" xmlns="http://www.w3.org/2000/svg">'
148+
# '<style>'
149+
# 'svg {'
150+
# 'font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, sans-serif;'
151+
# 'font-size: 14px;'
152+
# 'line-height: 1.5;'
153+
# '}'
154+
155+
# '.problems-solved {'
156+
# color: #8A8A8E;font-size: 12px;line-height: 17px; margin-bottom: 2px;white-space: nowrap;font-weight: 500;
157+
# '}'
158+
159+
# '.total-solved-container .total-count::before {'
160+
# 'content: "/";'
161+
# 'margin: 0 1px;'
162+
# '}'
163+
164+
# '.total-solved-container .total-count {'
165+
# 'color: #8A8A8E;'
166+
# 'font-size: 12px;'
167+
# 'font-weight: 500;'
168+
# 'line-height: 14px;'
169+
# '}'
170+
171+
# '.top {'
172+
# 'height: 108px;'
173+
# '}'
174+
175+
# 'foreignObject {'
176+
# 'width: calc(100% - 10px - 32px);'
177+
# 'height: calc(100% - 10px - 24px);'
178+
# '}'
179+
# '</style>'
180+
'<g>'
181+
'<rect x="5" y="5" id="background" style="width: calc(100% - 10px);height: calc(100% - 10px);fill: #FFF;rx: 8px;ry: 8px;"/>'
182+
'<g>'
183+
'<foreignObject x="21" y="17" width="318" height="176">'
184+
'<div xmlns="http://www.w3.org/1999/xhtml">'
185+
'<div class="stat-wrapper top" size="108" style="display: flex; flex-direction: column;text-align: start;">'
186+
'<div class="problems-solved" style="color: #8A8A8E;font-size: 12px;line-height: 17px; margin-bottom: 2px;white-space: nowrap;font-weight: 500;">Problems Solved</div>'
187+
'<div class="total-solved-count" style="font-size: 22px;font-weight: 600;line-height: 100%;white-space: nowrap;color: #262626;">{0}</div>'
188+
'</div>'
189+
'<div class="total-solved-container" style="display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-pack: justify;-ms-flex-pack: justify;justify-content: space-between;color: #9e9e9e;height: 33px;">'
190+
'<div class="stat-wrapper" data-difficulty="Easy" style="display: flex; flex-direction: column;text-align: start;">'
191+
'<div class="difficulty-label easy" style="color: #43A047;font-size: 12px;font-weight: normal;line-height: 17px;margin-bottom: 2px;white-space: nowrap;">Easy</div>'
192+
'<div class="solved" style="color: #262626;font-size: 14px;font-weight: 600;line-height: 100%;white-space: nowrap;">'
193+
'{0}<span class="total-count">/568</span>'
194+
'</div>'
195+
'</div>'
196+
'<div class="stat-wrapper" data-difficulty="Medium" style="display: flex; flex-direction: column;text-align: start;">'
197+
'<div class="difficulty-label medium" style="color: #FB8C00;font-size: 12px;font-weight: normal;line-height: 17px;margin-bottom: 2px;white-space: nowrap;">Medium</div>'
198+
'<div class="solved" style="color: #262626;font-size: 14px;font-weight: 600;line-height: 100%;white-space: nowrap;">'
199+
'{0}<span class="total-count">/1203</span>'
200+
'</div>'
201+
'</div>'
202+
'<div class="stat-wrapper" data-difficulty="Hard" style="display: flex; flex-direction: column;text-align: start;">'
203+
'<div class="difficulty-label hard" style="color: #E91E63;font-size: 12px;font-weight: normal;line-height: 17px;margin-bottom: 2px;white-space: nowrap;">Hard</div>'
204+
'<div class="solved" style="color: #262626;font-size: 14px;font-weight: 600;line-height: 100%;white-space: nowrap;">'
205+
'{0}<span class="total-count">/491</span>'
206+
'</div>'
207+
'</div>'
208+
'</div>'
209+
'</div>'
210+
'</foreignObject>'
211+
'</g>'
212+
'</g>'
213+
'</svg>',total, easy, med, hard)
214+
215+
# return mark_safe(svg_tag)
216+
return HttpResponse(svg_tag, content_type="image/svg+xml")
68 Bytes
Binary file not shown.
-35 Bytes
Binary file not shown.

‎leetcodeApi/settings.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
from pathlib import Path
1414
from decouple import config
1515
import os
16+
import mimetypes
17+
18+
mimetypes.add_type("image/svg+xml", ".html", True)
1619

1720
# Build paths inside the project like this: BASE_DIR / 'subdir'.
1821
BASE_DIR = Path(__file__).resolve().parent.parent
@@ -28,7 +31,7 @@
2831
# SECRET_KEY = os.getenv('SECRET_KEY')
2932

3033
# SECURITY WARNING: don't run with debug turned on in production!
31-
DEBUG = False
34+
DEBUG = True
3235

3336
ALLOWED_HOSTS = ['*']
3437

‎leetcodeApi/urls.py

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

0 commit comments

Comments
(0)

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