|
#!/bin/python3 -- |
|
|
|
import argparse |
|
import collections |
|
import datetime |
|
import itertools |
|
import sys |
|
|
|
ap = argparse.ArgumentParser() |
|
ap.add_argument("--number", "-N", type=int, |
|
help="The number to use in the header instead of the " |
|
"number of today's Wordle") |
|
ap.add_argument("--hard", "-H", action="store_true", |
|
help="Print an asterisk at the end of the header") |
|
ap.add_argument("--light", "-l", action="store_true", |
|
help="Use white instead of black for incorrect letters") |
|
ap.add_argument("--words", "-w", action="store_true", |
|
help="Show guesses in the output") |
|
ap.add_argument("--discord", "-d", action="store_true", |
|
help="Use discord :emojis: instead of raw emoji " |
|
"characters, and print words with monospace and " |
|
"spoiler formatting") |
|
|
|
for i in range(1, 7): |
|
ap.add_argument("guesses", nargs="?", action="append", |
|
metavar=f"guess{i}", help="Incorrect guess") |
|
|
|
ap.add_argument("solution", help="The correct word") |
|
|
|
args = ap.parse_args() |
|
|
|
if args.number is None: |
|
number = (datetime.date.today() - datetime.date(2021, 6, 19)).days |
|
else: |
|
number = args.number |
|
|
|
def word5(word): |
|
if len(word) != 5: |
|
sys.exit(f"{word!r} is not a five letter word!") |
|
return word |
|
|
|
solution = word5(args.solution).upper() |
|
guesses = tuple(word5(g).upper() for g in args.guesses if g) |
|
|
|
result = "X" if args.guesses[5] else str(len(guesses) + 1) |
|
|
|
print(f"Wordle {number:,} {result}/6{'*' if args.hard else ''}\n") |
|
|
|
for word in itertools.islice((*guesses, solution), 6): |
|
colors = "" |
|
yellow = (*enumerate(solution), *enumerate(word)) |
|
yellow = set(k[0] for k, c in collections.Counter(yellow) if c == 1) |
|
for i, c in enumerate(word): |
|
if c == solution[i]: |
|
colors += ":green_square:" if args.discord else "\U0001f7e9" |
|
elif i in yellow: |
|
colors += ":yellow_square:" if args.discord else \ |
|
"\U0001f7e8" |
|
elif args.light: |
|
colors += ":white_large_square:" if args.discord else \ |
|
"\u2b1c" |
|
else: |
|
colors += ":black_large_square:" if args.discord else \ |
|
"\u2b1b" |
|
print(f"{colors}" if not args.words else |
|
f"{colors} {word}" if not args.discord else |
|
f"{colors} ||`{word}`||") |