- Jul 2023
-
github.com github.com
-
```python from flask import Flask, request from collections import defaultdict import re import random
GREEN ="🟩" YELLOW ="🟨" WHITE ="⬜"
def get_answers(): with open("allowed_answers.txt") as f: answers = set(l for l in f.read().splitlines() if l) return answers
def get_guesses(): guesses = get_answers() with open("allowed_guesses.txt") as f: for l in f.read().splitlines(): if l: guesses.add(l) return guesses
app = Flask(name, static_folder="static") app.answers = get_answers() app.guesses = get_guesses() word = random.choice(list(app.answers)) print(f"The word is {word}")
def with_header(content): return f"""
<html> <head> <link rel="search" type="application/opensearchdescription+xml" title="searchGame" href="http://searchgame:5000/static/opensearch.xml" /> </head> <body> {content} </body></html>"""
@app.route("/") def home(): return with_header("
Right click on the address bar to install the search engine.
")@app.route("/search") def search(): return with_header(f"Content: {request.args.get('q')}")
def to_result(guess, answer): chars = [WHITE] * 5 count = defaultdict(int) for idx, (g, a) in enumerate(zip(guess, answer)): if g == a: chars[idx] = GREEN else: count[a] += 1
for idx, g in enumerate(guess): if g in count and count[g] > 0 and chars[idx] == WHITE: chars[idx] = YELLOW count[g] -= 1 return "".join(chars)
def maybe_error(guess): if len(guess) < 5: return f"less than 5 characters" if len(guess) > 5: return f"greater than 5 characters" if guess not in app.guesses: return f"not in wordlist" return None
@app.route("/game") def game(): query = request.args.get("q") guesses = [x for x in re.split("[. ]", query) if x] response = [] if not guesses: response.append("Enter 5-letter guesses separated by spaces") else: most_recent = guesses[-1] # Don't show "too short" error for most recent guess if len(most_recent) < 5: guesses = guesses[:-1] if not guesses: response.append("Enter a wordle guess") for guess in guesses[::-1]: error = maybe_error(guess) if error is None: result = to_result(guess, word) s = f"{guess} | {result}" if result == GREEN * 5: s = f"{s} | CORRECT!" response.append(s) else: response.append(f"{guess} | ERROR: {error}")
return [query, response]
```
-
- Jan 2023
-
Tags
Annotators
URL
-
- Sep 2022
- Aug 2022
-
mycroftproject.com mycroftproject.com
-
-
addons.mozilla.org addons.mozilla.org
-
github.com github.com
Tags
Annotators
URL
-
-
eoxc.github.io eoxc.github.io
Tags
Annotators
URL
-
- May 2022
-
-
html <link rel="search" type="application/opensearchdescription+xml" href="http://www.nature.com/opensearch/opensearch.xml" title="nature.com" /> <link rel="search" type="application/sru+xml" href="http://www.nature.com/opensearch/request" title="nature.com" />
-
- Oct 2018
-
developer.mozilla.org developer.mozilla.org
-
www.opensearch.org www.opensearch.org
-
Provided here is a stylesheet (XSL file) that will convert RSS and Atom based OpenSearch search result feeds into HTML.
Tags
Annotators
URL
-
-
www.mediawiki.org www.mediawiki.org
Tags
Annotators
URL
-
-
7is7.com 7is7.com
Tags
Annotators
URL
-
-
www.chromium.org www.chromium.org
Tags
Annotators
URL
-
-
developer.mozilla.org developer.mozilla.org
-
github.com github.com
-
www.opensearch.org www.opensearch.org
-