Snapshot flask development.
Dictionary and solver pages can partially display, but can't make any changes.
This commit is contained in:
1 parent
f7dd7c40f8
commit
17c8aefbed
5 files changed
+102
-13
No files matched your search
@@ -3,14 +3,67 @@
|
||||
from flask import Flask
|
||||
from flask import render_template
|
||||
|
||||
import wordle
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
def parse_guess(guess):
|
||||
return 'foody', 'CICMI'
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def solver():
|
||||
return render_template("solver.html")
|
||||
@app.route("/<g1>")
|
||||
@app.route("/<g1>/<g2>")
|
||||
@app.route("/<g1>/<g2>/<g3>")
|
||||
@app.route("/<g1>/<g2>/<g3>/<g4>")
|
||||
@app.route("/<g1>/<g2>/<g3>/<g4>/<g5>")
|
||||
@app.route("/<g1>/<g2>/<g3>/<g4>/<g5>/<g6>")
|
||||
def solver(g1=None, g2=None, g3=None, g4=None, g5=None, g6=None):
|
||||
|
||||
constraints = wordle.Constraints()
|
||||
|
||||
guesses = []
|
||||
results = []
|
||||
|
||||
for g in (g1, g2, g3, g4, g5, g6):
|
||||
parsed_guess, parsed_result = parse_guess(g)
|
||||
|
||||
if parsed_guess:
|
||||
guesses.append(parsed_guess)
|
||||
|
||||
if parsed_result:
|
||||
results.append(parsed_result)
|
||||
|
||||
if parsed_guess and parsed_result:
|
||||
constraints.update_graded(parsed_guess, parsed_result)
|
||||
|
||||
valid_words = wordle.filter_dictionary(constraints)
|
||||
scored_words = wordle.scored_words(valid_words)
|
||||
|
||||
# If a proposed solution was found...
|
||||
if scored_words:
|
||||
guesses.append(scored_words[0][0])
|
||||
|
||||
return render_template("solver.html", guesses=guesses, results=results)
|
||||
|
||||
|
||||
@app.route("/dictionary")
|
||||
def dictionary():
|
||||
return render_template("dictionary.html")
|
||||
@app.route("/dictionary/<page>")
|
||||
def dictionary(page=0):
|
||||
PAGE_SIZE = 100
|
||||
words = sorted(wordle.dictionary())
|
||||
|
||||
try:
|
||||
page = int(page)
|
||||
except ValueError:
|
||||
page = 0
|
||||
|
||||
max_pages = int(len(words) / PAGE_SIZE)
|
||||
|
||||
start_word = page * PAGE_SIZE
|
||||
end_word = start_word + PAGE_SIZE
|
||||
|
||||
words = words[start_word: end_word]
|
||||
|
||||
return render_template("dictionary.html",
|
||||
page=page, max_pages=max_pages, words=words)
|
||||
Reference in new issue
Block a user