-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
56 lines (48 loc) · 1.38 KB
/
main.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from flask import Flask, redirect
from flask import render_template
app = Flask(__name__)
@app.route('/')
def home_page():
startcolorcode = 'rgb(0, 191, 255)'
startcolorformat = 'any'
targetcolorformat = 'any'
context = {
'title': 'my title',
'content': 'my content',
'color': startcolorcode,
'startcolorformat': startcolorformat,
'targetcolorformat': targetcolorformat,
}
return render_template('home_page.html', **context)
@app.route('/<target>')
def conv_page(target):
paramlist = target.split('2')
iterator = iter(paramlist or [])
startcolorformat = next(iterator, 'Any')
startcolorcode = colormap.get(startcolorformat, None)
if startcolorcode is None:
return redirect("/", code=302)
targetcolorformat = next(iterator, None)
if targetcolorformat is not None:
targetcolorcode = colormap.get(targetcolorformat, None)
if targetcolorcode is None:
return redirect("/{0}".format(startcolorformat), code=302)
else:
targetcolorformat = 'any'
context = {
'title': 'my title',
'content': 'my content',
'color': startcolorcode,
'startcolorformat': startcolorformat,
'targetcolorformat': targetcolorformat,
}
return render_template('home_page.html', **context)
colormap = {
'name': 'DeepSkyBlue',
'rgb': 'rgb(0, 191, 255)',
'hex': '#00bfff',
'hsl': 'hsl(195, 100%, 50%)',
'hwb': 'hwb(195, 0%, 0%)',
'cmyk': 'cmyk(100%, 25%, 0%, 0%)',
'ncol': 'C25, 0%, 0%',
}