|
import streamlit as st |
|
import nltk |
|
from nltk.corpus import words |
|
|
|
st.title("Word Game Solver") |
|
|
|
@st.cache |
|
def download(): |
|
nltk.download('words') |
|
download() |
|
|
|
|
|
[a,b,c,d,e,f,g] = st.columns(7) |
|
|
|
with a: |
|
first_letter = st.text_input(label="1st",value = 'a') |
|
with b: |
|
second_letter = st.text_input(label="2nd", value = 'e') |
|
with c: |
|
third_letter = st.text_input(label="3rd", value = 'i') |
|
with d: |
|
fourth_letter = st.text_input(label="4th", value = 'o') |
|
with e: |
|
fifth_letter = st.text_input(label="5th", value = 'u') |
|
with f: |
|
sixth_letter = st.text_input(label="6th", value = '') |
|
with g: |
|
seventh_letter = st.text_input(label="7th", value = '') |
|
|
|
clue2 = first_letter+second_letter |
|
clue3 = first_letter+second_letter+third_letter |
|
clue4 = first_letter+second_letter+third_letter+fourth_letter |
|
clue5 = first_letter+second_letter+third_letter+fourth_letter+fifth_letter |
|
clue6 = first_letter+second_letter+third_letter+fourth_letter+fifth_letter+sixth_letter |
|
clue7 = first_letter+second_letter+third_letter+fourth_letter+fifth_letter+sixth_letter+seventh_letter |
|
|
|
st.markdown("### clue") |
|
st.write(clue2) |
|
st.write(clue3) |
|
st.write(clue4) |
|
st.write(clue5) |
|
st.write(clue6) |
|
st.write(clue7) |
|
|
|
exclusions = st.text_input(label="exclusions") |
|
|
|
clue_result2 = [] |
|
clue_result3 = [] |
|
clue_result4 = [] |
|
clue_result5 = [] |
|
clue_result6 = [] |
|
clue_result7 = [] |
|
|
|
two_letters = [word for word in words.words() if len(word)==2 ] |
|
three_letters = [word for word in words.words() if len(word)==3 ] |
|
four_letters = [word for word in words.words() if len(word)==4 ] |
|
five_letters = [word for word in words.words() if len(word)==5 ] |
|
six_letters = [word for word in words.words() if len(word)==6 ] |
|
seven_letters = [word for word in words.words() if len(word)==7 ] |
|
|
|
for word in two_letters: |
|
if all(c in word for c in clue2) and not any(c in word for c in exclusions): |
|
clue_result2.append(word) |
|
for word in three_letters: |
|
if all(c in word for c in clue3) and not any(c in word for c in exclusions): |
|
clue_result3.append(word) |
|
for word in four_letters: |
|
if all(c in word for c in clue4) and not any(c in word for c in exclusions): |
|
clue_result4.append(word) |
|
for word in five_letters: |
|
if all(c in word for c in clue5) and not any(c in word for c in exclusions): |
|
clue_result5.append(word) |
|
for word in six_letters: |
|
if all(c in word for c in clue6) and not any(c in word for c in exclusions): |
|
clue_result6.append(word) |
|
for word in seven_letters: |
|
if all(c in word for c in clue7) and not any(c in word for c in exclusions): |
|
clue_result7.append(word) |
|
|
|
|
|
st.write(clue_result2) |
|
st.write(clue_result3) |
|
st.write(clue_result4) |
|
st.write(clue_result5) |
|
st.write(clue_result6) |
|
st.write(clue_result7) |
|
|
|
|
|
import requests |
|
from bs4 import BeautifulSoup as bs |
|
import lxml.etree as xml |
|
import lxml |
|
|
|
def define(word): |
|
url = f'https://www.dictionary.com/browse/{word}?s=t' |
|
web_page = bs(requests.get(url, {}).text, "lxml") |
|
meanings = web_page.find_all('div', attrs={'class': 'css-1ghs5zt e1q3nk1v2'}) |
|
for meaning in meanings: |
|
st.write('* '+ meaning.text) |
|
st.write(meanings[0].text) |
|
|
|
for word in clue_result7: |
|
define(word) |