forked from googlearchive/appengine-flask-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
59 lines (45 loc) · 1.48 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
57
58
59
"""`main` is the top level module for your Flask application."""
# Import the Flask Framework
import flask
app = flask.Flask(__name__)
# ============================ #
# todo(jondb) move this to its own file == #
import datetime
import babel.dates
def relative_time(dt):
now = datetime.datetime.utcnow()
delta = now - dt
return babel.dates.format_timedelta(delta, locale='en_US')
# ============================ #
app.jinja_env.filters['relative_time'] = relative_time
# Note: We don't need to call run() since our application is embedded within
# the App Engine WSGI application server.
import model
@app.route('/')
def hello():
"""Return a friendly HTTP greeting."""
return flask.render_template('index.html', name="Name")
@app.route('/log/<name>/<status>')
def log_status(name, status):
"""Return a friendly HTTP greeting."""
error_text = flask.request.args.get('error_text', None)
status = int(status)
m = model.Status.update_status(name, status, error_text)
return 'OK'
@app.route('/gocron')
def run_cron():
import tester
tester.run_tests()
return 'OK'
@app.route('/report')
def report():
data = model.Status.summary()
return flask.render_template('report.html', data=data)
@app.errorhandler(404)
def page_not_found(e):
"""Return a custom 404 error."""
return 'Sorry, Nothing at this URL.', 404
@app.errorhandler(500)
def page_not_found(e):
"""Return a custom 500 error."""
return 'Sorry, unexpected error: {}'.format(e), 500