Skip to content

Commit e9ff7ed

Browse files
committed
update readme
1 parent 71e9053 commit e9ff7ed

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Posts and associated code:
77

88
|Post|Code Directory|Notes|
99
|---|---|---|
10+
|[How to Provision Ubuntu 16.04 Linux Servers on Linode](https://www.fullstackpython.com/blog/provision-ubuntu-linux-servers-linode.html)|No code for this post.||
1011
|[Creating Bar Chart Visuals with Bokeh, Bottle and Python 3](https://www.fullstackpython.com/blog/python-bottle-bokeh-bar-charts.html)|[bar-charts-bokeh-bottle-python-3](https://github.com/fullstackpython/blog-code-examples/tree/master/bar-charts-bokeh-bottle-python-3)||
1112
|[How to Add Hosted Monitoring to Flask Web Applications](https://www.fullstackpython.com/blog/hosted-monitoring-flask-web-apps.html)|[monitor-flask-apps](https://github.com/fullstackpython/blog-code-examples/tree/master/monitor-flask-apps)||
1213
|[Responsive Bar Charts with Bokeh, Flask and Python 3](https://www.fullstackpython.com/blog/responsive-bar-charts-bokeh-flask-python-3.html)|[bar-charts-bokeh-flask-python-3](https://github.com/fullstackpython/blog-code-examples/tree/master/bar-charts-bokeh-flask-python-3)||

monitor-python-bottle-apps/app.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import os
2+
import re
3+
import rollbar
4+
import rollbar.contrib.flask
5+
from flask import Flask, render_template, Response
6+
from flask import got_request_exception
7+
from werkzeug.exceptions import NotFound
8+
9+
10+
app = Flask(__name__)
11+
MIN_PAGE_NAME_LENGTH = 2
12+
13+
14+
@app.before_first_request
15+
def add_monitoring():
16+
rollbar.init(os.environ.get('ROLLBAR_SECRET'))
17+
## delete the next line if you dont want this event anymore
18+
rollbar.report_message('Rollbar is configured correctly')
19+
got_request_exception.connect(rollbar.contrib.flask.report_exception, app)
20+
21+
22+
@app.route("/<string:page>/")
23+
def show_page(page):
24+
try:
25+
valid_length = len(page) >= MIN_PAGE_NAME_LENGTH
26+
valid_name = re.match('^[a-z]+$', page.lower()) is not None
27+
if valid_length and valid_name:
28+
return render_template("{}.html".format(page))
29+
else:
30+
msg = "Sorry, couldn't find page with name {}".format(page)
31+
raise NotFound(msg)
32+
except:
33+
rollbar.report_exc_info()
34+
return Response("404 Not Found")
35+
36+
37+
if __name__ == "__main__":
38+
app.run(debug=True)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
blinker==1.4
2+
Flask==0.12.2
3+
rollbar==0.13.12
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Rollbar token, found in project settings
2+
export ROLLBAR_SECRET=''

0 commit comments

Comments
 (0)