Correct common misspelling of codes
This commit is contained in:
parent
4309a79a5d
commit
b5236e8da2
|
@ -11,6 +11,19 @@ assert len(ALPHABET) == 32
|
|||
LENGTH = 4
|
||||
|
||||
|
||||
CORRECT = {
|
||||
'i': '1',
|
||||
'l': '1',
|
||||
'o': '0',
|
||||
}
|
||||
|
||||
|
||||
def correct_code(code):
|
||||
code = code.lower()
|
||||
fixed_code = ''.join(CORRECT.get(c, c) for c in code)
|
||||
return fixed_code
|
||||
|
||||
|
||||
def list_errors(code):
|
||||
for place in range(LENGTH):
|
||||
for replacement in ALPHABET:
|
||||
|
|
|
@ -2,6 +2,7 @@ from flask import Flask, render_template, request, url_for
|
|||
import logging
|
||||
from werkzeug.utils import redirect
|
||||
|
||||
from .codes import correct_code
|
||||
from .database import get_name_and_replies, record_reply
|
||||
|
||||
|
||||
|
@ -18,7 +19,7 @@ def form():
|
|||
'code' in request.form
|
||||
and len(request.form['code']) == 4
|
||||
):
|
||||
code = request.form['code']
|
||||
code = correct_code(request.form['code'])
|
||||
try:
|
||||
get_name_and_replies(code)
|
||||
except ValueError:
|
||||
|
|
Loading…
Reference in New Issue