-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
35 lines (28 loc) · 1.03 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
from flask import Flask, request, render_template
from wordlist import words
import requests
app = Flask(__name__)
if __name__ == "__main__":
app.run()
def load_words(word_size, jumbledTextSorted):
matches = []
if word_size <= 0 or word_size > 21:
return matches
for k, v in words.items():
if v == word_size:
if ''.join(sorted(k)) == jumbledTextSorted:
matches.append(k)
return matches
@app.route("/", methods=['GET'])
def index():
return render_template('index.html')
@app.route("/submit", methods=['GET', 'POST'])
def anagramsubmit():
if request.method == 'POST':
jumbledText = request.form.get('anagram').lower()
# Avoid scripting attacks
if not jumbledText.isalpha():
return render_template('index.html')
# Get valid words of matching length and letters
valid_answers = load_words(len(jumbledText), ''.join(sorted(jumbledText)))
return render_template('submit.html', valid_answers=valid_answers)