File size: 2,442 Bytes
ee2309a
 
c8e9ef0
 
 
ad38218
ee2309a
c0ab3ed
fb96dd8
9fe7e75
120d25d
7cc26a6
 
c8e9ef0
85f6a59
0fe0771
fb96dd8
177665a
 
9cb4940
 
 
 
7cc26a6
9cb4940
 
 
54922b6
 
 
909915c
9cb4940
fb96dd8
c8e9ef0
85f6a59
ad38218
 
c8e9ef0
17afdf5
c8e9ef0
 
ad38218
 
7bd6a90
 
 
 
 
 
fb96dd8
 
 
 
 
 
7bd6a90
fb96dd8
c0ab3ed
134ecd7
c8e9ef0
134ecd7
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import gradio as gr
import pandas as pd
import requests
import re
import json
from datetime import date

english_dict = pd.read_csv("dictionary.txt",
                         header = None, 
                         sep = ' ', 
                        names = ['word'])
english_dict = english_dict.reset_index(drop = True)
english_dict = english_dict.dropna()

print('TESTING')
url = 'https://spellbee.org'
def spell_bee_solver(no_centre, centre):
    full_set = set(no_centre.lower() + centre.lower())
    spell_bee_solver = english_dict[english_dict['word'].str.contains(str(centre.lower()), regex = False)]
    final_words = list()
    for i in range(0, spell_bee_solver.shape[0]):
        words = spell_bee_solver['word'].iloc[i]
        words_set = set(words)
        if len(words_set - full_set) == 0:
            final_words.append(words)

    final_word_df = pd.DataFrame(final_words)
    final_word_df.columns = ['word']
    final_word_df['word_length'] = final_word_df['word'].str.len()
    final_word_df = final_word_df[final_word_df['word_length'] > 3]
    final_word_df = final_word_df.sort_values('word_length', ascending = False)
    return(final_word_df)

def get_spellbee_answers(x):
    print("TESTING")
    today = date.today().strftime("%Y-%m-%d")

    content = requests.get(url)._content
    content = re.sub(".*window.games = ", "", str(content))
    content = re.sub("(.*?)\\;.*", "\\1", content)
    content = json.loads(content)
    
    valid_words = content[today]['data']['dictionary']
    final_word_df = pd.DataFrame(valid_words, columns = ['word'])
    final_word_df['word_length'] = final_word_df['word'].str.len()
    final_word_df = final_word_df[final_word_df['word_length'] > 3]
    final_word_df = final_word_df.sort_values('word_length', ascending = False)
    return(final_word_df)

with gr.Blocks() as app:
    with gr.Row():
        no_centre = gr.Textbox(label = 'Letters Outside of Centre')
        centre = gr.Textbox(label = 'Centre Letter')
    with gr.Row():
        solve_button = gr.Button(value = 'Solve')
        get_today_answers = gr.Button(value = "Get Today's answers")
    with gr.Row():
        output_df = gr.DataFrame(headers = ['word', 'word_length'])
    solve_button.click(spell_bee_solver, inputs = [no_centre, centre], outputs = [output_df])
    get_today_answers.click(get_spellbee_answers, inputs = [no_centre], outputs = [output_df])

app.launch(debug = True, share = False)