-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
49 lines (38 loc) · 1.62 KB
/
app.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
import os
import re
from flask import Flask, flash, render_template, request
from palette import *
app = Flask(__name__)
app.secret_key = "supersecretkey"
def validate_hex_color(color):
return re.match("^#(?:[0-9a-fA-F]{3}){1,2}$", color)
@app.route('/', methods=['GET', 'POST'])
def index():
selected_color = "#88E399"
all_palettes = {}
if request.method == 'POST':
selected_color = request.form.get('hex-color').strip()
if not validate_hex_color(selected_color):
flash("Invalid Hex color. Please use the format #RRGGBB or #RGB.")
else:
selected_color = selected_color
all_palettes = {
"Matching Gradient": matching_gradient(selected_color),
"Spot Palette": spot_palette(selected_color),
"Twisted Spot Palette": twisted_spot_palette(selected_color),
"Classy Palette": classy_palette(selected_color),
"Small Switch Palette": small_switch_palette(selected_color),
"Complementary Colors": complementary_colors(selected_color),
"Triadic Colors": triadic_colors(selected_color),
"Analogous Colors": analogous_colors(selected_color),
}
return render_template('pages/index.html',
all_palettes=all_palettes,
selected_color=selected_color)
@app.errorhandler(500)
def internal_server_error(error):
return render_template("pages/500.html"), 500
if __name__ == "__main__":
app.run(debug=True,
host="0.0.0.0",
port=int(os.environ.get("PORT", 8080)))