Skip to content

Commit 527d52f

Browse files
committed
dark theme added
1 parent 55a7b73 commit 527d52f

File tree

4 files changed

+132
-9
lines changed

4 files changed

+132
-9
lines changed

api/__pycache__/views.cpython-39.pyc

2.92 KB
Binary file not shown.

api/views.py

Lines changed: 131 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,16 @@ def svg_icon(request, username):
169169
# '}'
170170
# '</style>'
171171
'<g>'
172-
'<rect x="5" y="5" id="background" style="width: calc(100% - 10px);height: 400px;fill: #FFF;rx: 8px;ry: 8px;"/>'
172+
'<rect x="10" y="10" style="width: calc(100% - 10px);height: calc(100% - 10px); fill:#FFF; rx: 8px;ry: 8px;"/>'
173173
'<g>'
174-
'<foreignObject x="21" y="17" width="318" height="176" style="width: calc(100% - 10px - 32px); height: 400px;">'
174+
'<foreignObject x="21" y="17" width="318" height="176" style="width: calc(100% - 10px - 32px); height: 250px;">'
175175
'<div xmlns="http://www.w3.org/1999/xhtml">'
176176
'<div style="margin-bottom:15px; font-size:18px;"><b style="color:#fc9905;">{0}</b> - LeetCode Stats</div>'
177177
'<div class="row1" style="margin-top:10px;">'
178-
'<div class="column" style="float: left;width: 35%;">'
179-
'<div class="stat-wrapper top" size="108" style="display: flex; flex-direction: column;text-align: start; margin-top:40px;">'
180-
'<div class="problems-solved" style="color: #8A8A8E;font-size: 16px;line-height: 17px; margin-bottom: 2px;white-space: nowrap;font-weight: 500;">Problems Solved</div>'
181-
'<div class="total-solved-count" style="font-size: 22px;font-weight: 600;line-height: 100%;white-space: nowrap;color: #262626;">{1}</div>'
178+
'<div style="float: left;width: 35%;">'
179+
'<div size="108" style="display: flex; flex-direction: column;text-align: start; margin-top:40px;">'
180+
'<div style="color: #8A8A8E;font-size: 15px;line-height: 17px; margin-bottom: 2px;white-space: nowrap;font-weight: 500;">Problems Solved</div>'
181+
'<div style="font-size: 22px;font-weight: 600;line-height: 100%;white-space: nowrap;color: #262626;">{1}</div>'
182182
'</div>'
183183
# '<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;">'
184184
# '<div class="stat-wrapper" data-difficulty="Easy" style="display: flex; flex-direction: column;text-align: start;">'
@@ -201,7 +201,7 @@ def svg_icon(request, username):
201201
# '</div>'
202202
# '</div>'
203203
'</div>'
204-
'<div class="column" style="float: left;width: 65%;">'
204+
'<div style="float: left;width: 65%;">'
205205
'<div style="margin:20px; margin-bottom:2px; margin-top:0px;"><span style="color:#5db55f;">Easy:</span> <b style="color:#5db55f;">{2}</b>/568</div>'
206206
'<div style="background-color:#e4e4e4; border-radius:50px; margin:20px; margin-top:2px;">'
207207
'<div style="height:4px; width:calc(({2}/568) * 100%); background-color:#5db55f; border-radius:50px;"></div>'
@@ -220,7 +220,129 @@ def svg_icon(request, username):
220220
'</foreignObject>'
221221
'</g>'
222222
'</g>'
223-
'</svg>', username, total, easy, med, hard, )
223+
'</svg>', username, total, easy, med, hard)
224224

225225
# return mark_safe(svg_tag)
226-
return HttpResponse(svg_tag, content_type="image/svg+xml")
226+
return HttpResponse(svg_tag, content_type="image/svg+xml")
227+
228+
def svg_icon_theme(request, username, theme):
229+
if(theme.lower() == 'dark'):
230+
# print('dddd')
231+
232+
query = '''
233+
query getUserProfile($username: String!) {
234+
allQuestionsCount {
235+
difficulty
236+
count
237+
}
238+
matchedUser(username: $username) {
239+
username
240+
submitStats {
241+
acSubmissionNum {
242+
difficulty
243+
count
244+
submissions
245+
}
246+
}
247+
}
248+
}
249+
'''
250+
251+
username = username
252+
variables = {'username': username}
253+
254+
url = 'https://leetcode.com/graphql/'
255+
r = requests.post(url, json={'query': query, 'variables': variables})
256+
json_data = json.loads(r.text)
257+
print(json.dumps(json_data, indent=4))
258+
259+
usernameHandle = json_data['data']['matchedUser']['username']
260+
total = json_data['data']['matchedUser']['submitStats']['acSubmissionNum'][0]['count']
261+
easy = json_data['data']['matchedUser']['submitStats']['acSubmissionNum'][1]['count']
262+
med = json_data['data']['matchedUser']['submitStats']['acSubmissionNum'][2]['count']
263+
hard = json_data['data']['matchedUser']['submitStats']['acSubmissionNum'][3]['count']
264+
265+
266+
svg_tag = format_html('<svg width="330" height="180" xmlns="http://www.w3.org/2000/svg">'
267+
# '<style>'
268+
# 'svg {'
269+
# 'font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, sans-serif;'
270+
# 'font-size: 14px;'
271+
# 'line-height: 1.5;'
272+
# '}'
273+
274+
# '.total-solved-container .total-count::before {'
275+
# 'content: "/";'
276+
# 'margin: 0 1px;'
277+
# '}'
278+
279+
# '.total-solved-container .total-count {'
280+
# 'color: #8A8A8E;'
281+
# 'font-size: 12px;'
282+
# 'font-weight: 500;'
283+
# 'line-height: 14px;'
284+
# '}'
285+
286+
# '.top {'
287+
# 'height: 108px;'
288+
# '}'
289+
# '</style>'
290+
'<g>'
291+
'<rect x="10" y="10" style="width: calc(100% - 10px);height: calc(100% - 10px); fill:black; rx: 8px;ry: 8px;"/>'
292+
'<g>'
293+
'<foreignObject x="21" y="17" width="318" height="176" style="width: calc(100% - 10px - 32px); height: 250px;">'
294+
'<div xmlns="http://www.w3.org/1999/xhtml">'
295+
'<div style="margin-bottom:15px; font-size:18px; color:#e6e6eb;"><b style="color:#fc9905;">{0}</b> - LeetCode Stats</div>'
296+
'<div class="row1" style="margin-top:10px;">'
297+
'<div style="float: left;width: 35%;">'
298+
'<div size="108" style="display: flex; flex-direction: column;text-align: start; margin-top:40px;">'
299+
'<div style="color: #e6e6eb;font-size: 15px;line-height: 17px; margin-bottom: 2px;white-space: nowrap;font-weight: 500;">Problems Solved</div>'
300+
'<div style="font-size: 22px;font-weight: 600;line-height: 100%;white-space: nowrap;color: white;">{1}</div>'
301+
'</div>'
302+
# '<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;">'
303+
# '<div class="stat-wrapper" data-difficulty="Easy" style="display: flex; flex-direction: column;text-align: start;">'
304+
# '<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>'
305+
# '<div class="solved" style="color: #262626;font-size: 14px;font-weight: 600;line-height: 100%;white-space: nowrap;">'
306+
# '{2}<span class="total-count">/568</span>'
307+
# '</div>'
308+
# '</div>'
309+
# '<div class="stat-wrapper" data-difficulty="Medium" style="display: flex; flex-direction: column;text-align: start;">'
310+
# '<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>'
311+
# '<div class="solved" style="color: #262626;font-size: 14px;font-weight: 600;line-height: 100%;white-space: nowrap;">'
312+
# '{3}<span class="total-count">/1203</span>'
313+
# '</div>'
314+
# '</div>'
315+
# '<div class="stat-wrapper" data-difficulty="Hard" style="display: flex; flex-direction: column;text-align: start;">'
316+
# '<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>'
317+
# '<div class="solved" style="color: #262626;font-size: 14px;font-weight: 600;line-height: 100%;white-space: nowrap;">'
318+
# '{4}<span class="total-count">/491</span>'
319+
# '</div>'
320+
# '</div>'
321+
# '</div>'
322+
'</div>'
323+
'<div style="float: left;width: 65%;">'
324+
'<div style="margin:20px; margin-bottom:2px; margin-top:0px; color:#e6e6eb;"><span style="color:#5db55f;">Easy:</span> <b style="color:#5db55f;">{2}</b>/568</div>'
325+
'<div style="background-color:#e4e4e4; border-radius:50px; margin:20px; margin-top:2px;">'
326+
'<div style="height:4px; width:calc(({2}/568) * 100%); background-color:#5db55f; border-radius:50px;"></div>'
327+
'</div>'
328+
'<div style="margin:20px; margin-bottom:2px; color:#e6e6eb;"><span style="color:#faab43;">Medium: </span> <b style="color:#faab43;">{3}</b>/1203</div>'
329+
'<div style="background-color:#e4e4e4; border-radius:50px; margin:20px; margin-top:2px;">'
330+
'<div style="height:4px; width:calc(({3}/1203) * 100%); background-color:#faab43; border-radius:50px;"></div>'
331+
'</div>'
332+
'<div style="margin:20px; margin-bottom:2px; color:#e6e6eb;"><span style="color:#d55951;">Hard: </span> <b style="color:#d55951;">{4}</b>/491</div>'
333+
'<div style="background-color:#e4e4e4; border-radius:50px; margin:20px; margin-top:2px;">'
334+
'<div style="height:4px; width:calc(({4}/491) * 100%); background-color:#d55951; border-radius:50px;"></div>'
335+
'</div>'
336+
'</div>'
337+
'</div>'
338+
'</div>'
339+
'</foreignObject>'
340+
'</g>'
341+
'</g>'
342+
'</svg>', username, total, easy, med, hard)
343+
344+
# return mark_safe(svg_tag)
345+
return HttpResponse(svg_tag, content_type="image/svg+xml")
346+
347+
else:
348+
return HttpResponse('Currently only dark theme is supported')
60 Bytes
Binary file not shown.

leetcodeApi/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@
2222
path('admin/', admin.site.urls),
2323
path('', home),
2424
path('<str:username>/', svg_icon),
25+
path('<str:username>/theme=<str:theme>', svg_icon_theme),
2526
# path('a/<str:username>/', svg_icon),
2627
]

0 commit comments

Comments
 (0)