-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrabbleHelper.py
75 lines (58 loc) · 2.18 KB
/
scrabbleHelper.py
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
63
64
65
66
67
68
69
70
71
72
73
74
75
#! python3
from itertools import combinations as combo
import enchant
from bs4 import BeautifulSoup as bs
import requests as req
from textwrap import fill
print('')
print('welcome to scrabble helper'.upper().center(65, '*'))
print('remember that you can\'t use abbreviations in the game'.upper().center(65, '*'))
while True:
print('')
word = ''.join(input('Letters you have in scrabble: ').strip().split(' '))
d = enchant.Dict("en_US")
a = [combo(word, i) for i in range(1, len(word) + 1)]
b = list()
v = 'aeiou'
for f in range(len(a)):
for g in list(a[f]):
g = ''.join(g).strip()
if g not in b:
b.append(''.join(g))
words = sorted([i for i in b if d.check(i)], key=len)
print('\nword list\n'.upper().center(65, '*'))
for word in words:
word = word.ljust(15, ' ')
word = word + '<'
print(word.ljust(30, '-'))
while True:
try:
print('')
look = input('Look up a definition? [y/n]: ').lower()
if look == 'y':
print('')
look = input('Which word?: ').lower()
if look in words:
print('\nLoading...\n')
webDictionary = req.get(
'https://www.dictionary.com/browse/' + look + '?s=t')
page = bs(webDictionary.text, 'lxml')
definitions = page.find("div", "e1hk9ate4")
definitions = definitions.find_all("div", "e1q3nk1v3")
else:
print('That word is not in your possibles :/')
break
print(''.center(65, '-'))
print('\"' + look.upper() + '\"')
print('')
for n, d in enumerate(definitions):
print(str(n + 1) + ') ' + fill(d.text.strip(), 40))
print('')
print(''.center(65, '-') + '\n')
elif look == 'n':
break
else:
print('\nwhat?')
except AttributeError:
print(
"I wasn't able to retrieve any definitions from dictionary.com :(")