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
+101
-12
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)
|
||||
@@ -5,5 +5,19 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
Words go here.
|
||||
|
||||
{% if page > 0 %}<a href="{{ url_for('dictionary', page=page-1) }}">Prev</a>{% endif %}
|
||||
|
||||
Page {{ page }} / {{ max_pages }}
|
||||
|
||||
{% if page < max_pages %}<a href="{{ url_for('dictionary', page=page+1) }}">Next</a>{% endif %}
|
||||
|
||||
|
||||
<ul>
|
||||
{% for word in words %}
|
||||
<li>{{ word }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
@@ -18,7 +18,8 @@
|
||||
{% endblock %}
|
||||
<hr />
|
||||
<footer>
|
||||
I did this!
|
||||
This is not associated with the New York Times or the offical version of
|
||||
Wordle in any way.
|
||||
</footer>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
+23
-2
@@ -1,9 +1,30 @@
|
||||
{% extends "layout.html" %}
|
||||
|
||||
{% block title %}
|
||||
Solver!
|
||||
Solver!
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
Welcome to solver!
|
||||
<ul>
|
||||
{% for guess in guesses %}
|
||||
<li>{{ guess }}
|
||||
|
||||
{% for i in range(5) %}
|
||||
<select name="g{{i}}" id="g{{i}}">
|
||||
<option value="U">Unknown</option>
|
||||
<option value="I">Incorrect</option>
|
||||
<option value="M">Move</option>
|
||||
<option value="C">Correct</option>
|
||||
</select>
|
||||
{% endfor %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
|
||||
{%if solution %}
|
||||
The proposed solution is <b>{{ solution }}</b>.
|
||||
{% else %}
|
||||
No solution found.
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
Reference in new issue
Block a user