-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
29 lines (25 loc) · 789 Bytes
/
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
import os
import time
import redis
from flask import Flask, render_template, send_from_directory
app = Flask(__name__)
cache = redis.Redis(host='{APP_SERVER}', port=6379)
def get_hit_count():
retries = 5
while True:
try:
return cache.incr('hits')
except redis.exceptions.ConnectionError as exc:
if retries == 0:
raise exc
retries -= 1
time.sleep(0.5)
@app.route('/')
@app.route('/<count>')
def hello(count=None):
count = get_hit_count()
return render_template('index.html', count=count)
@app.route('/favicon.ico')
def favicon():
return send_from_directory(os.path.join(app.root_path, 'static', 'img'),
'favicon.ico', mimetype='image/vnd.microsoft.icon')