Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 186f257704 | |||
| 6c14e13d08 | |||
| 8db931a4c7 | |||
| 1067b4fc3b |
34
web/app.py
34
web/app.py
@@ -2,7 +2,7 @@ from flask import Flask, render_template, request
|
||||
from flask_bootstrap import Bootstrap
|
||||
import db
|
||||
import config
|
||||
import pprint
|
||||
import utils
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(config.BaseConfig)
|
||||
@@ -21,18 +21,32 @@ def hello_world():
|
||||
@app.route('/generate', methods=["POST"])
|
||||
def generate():
|
||||
try:
|
||||
ip = utils.get_ip(request)
|
||||
pass
|
||||
except:
|
||||
ip = ''
|
||||
pass
|
||||
|
||||
if ip != '5.135.188.148' and ip != '178.32.58.160':
|
||||
try:
|
||||
error = None
|
||||
identifier = my_db.get_identifier(request.form['name'])
|
||||
pass
|
||||
except StopIteration:
|
||||
identifier = ''
|
||||
error = 'Maximum entry limit reached - please contact Sean or Joe'
|
||||
pass
|
||||
else:
|
||||
error = None
|
||||
identifier = my_db.get_identifier(request.form['name'])
|
||||
pass
|
||||
except StopIteration:
|
||||
identifier = ''
|
||||
error = 'Maximum entry limit reached - please contact Sean or Joe'
|
||||
pass
|
||||
identifier = 'F'
|
||||
|
||||
return render_template('generate.html', brew_name=brew_name, brew_month=brew_month, identifier=identifier, error=error)
|
||||
|
||||
|
||||
@app.route('/getip')
|
||||
def getip():
|
||||
return utils.get_ip(request)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True, host='0.0.0.0')
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ class Database:
|
||||
numbers = list(range(1, 100))
|
||||
identifiers = list(string.ascii_uppercase) + [str(item) for item in
|
||||
numbers] # All identifiers are treated as strings
|
||||
ambiguous = ['I', 'O', 'V', '1', '5', '9', '99']
|
||||
ambiguous = ['I', 'O', 'V', '1', '8', '5', '9', '99']
|
||||
utils.remove_common_elements(identifiers, ambiguous)
|
||||
return identifiers
|
||||
|
||||
|
||||
@@ -4,3 +4,10 @@ def remove_common_elements(a, b):
|
||||
if e in b:
|
||||
a.remove(e)
|
||||
b.remove(e)
|
||||
|
||||
|
||||
def get_ip(request):
|
||||
if request.headers.getlist("X-Forwarded-For"):
|
||||
return request.headers.getlist("X-Forwarded-For")[0]
|
||||
else:
|
||||
return request.remote_addr
|
||||
|
||||
Reference in New Issue
Block a user