This repository was archived by the owner on Jun 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
52 lines (44 loc) · 1.32 KB
/
app.py
File metadata and controls
52 lines (44 loc) · 1.32 KB
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
# -!- coding:utf-8 -!-
import random
import re
import os
from flask import Flask
from flask_migrate import Migrate
from flask_sqlalchemy import SQLAlchemy
from jinja2 import evalcontextfilter, Markup, escape
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get("DATABASE_URL")
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
migrate = Migrate(app, db)
@app.template_filter()
@evalcontextfilter
def nl2br(eval_ctx, value):
_paragraph_re = re.compile(r'(?:\r\n|\r|\n){2,}')
result = u'\n\n'.join(u'<p>%s</p>' % p.replace('\n', '<br>\n') \
for p in _paragraph_re.split(escape(value)))
if eval_ctx.autoescape:
result = Markup(result)
return result
@app.template_filter()
def prcolor(value):
random.seed(value)
red, green, blue = [random.randint(0, 255) for _ in range(3)]
return "rgb({}, {}, {})".format(red, green, blue)
@app.template_filter()
@evalcontextfilter
def poiemoji(eval_ctx, text):
result = []
if 'Beifall' in text:
result.append("👏")
elif "Heiterkeit" in text:
result.append("😂")
elif "Unterbrechung" in text:
result.append("⏰")
else:
result.append("🗯")
result = " ".join(result)
if eval_ctx.autoescape:
result = Markup(result)
return result
import views