-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdigest.py
34 lines (24 loc) · 875 Bytes
/
digest.py
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
26
27
28
29
30
31
32
33
34
from flask import Flask, Response, request, render_template
from markupsafe import escape
from lib.user import User
from lib.themes import Theme
app = Flask(__name__)
# grabs user data from a leetcode api and returns the svg template with the data filled in.
def populateSVG(username: str, theme: dict):
user = User(username, theme)
user.fetchData()
return user.svg
# returns the generated svg with a given user name
@app.route('/svg/<username>')
def svg(username):
custom_theme = request.args.get('theme')
if custom_theme == None:
# default theme is nord
custom_theme = 'nord'
theme = Theme(custom_theme)
svg_text = populateSVG(escape(username), theme)
return Response(svg_text, mimetype='image/svg+xml')
# app to customise svg
@app.route('/')
def customiseSVG():
return render_template('index.html')