-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathspellcheck.py
36 lines (30 loc) · 859 Bytes
/
spellcheck.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
import urllib.request
def clean(word):
word = word.strip()
word = word.lower()
return word
def browsercontent(url):
try:
fp = urllib.request.urlopen(url)
mybytes = fp.read()
mystr = mybytes.decode("utf8")
fp.close()
except:
print ("ERROR: COULD NOT RECEIVE WEB DATA")
return "ERROR"
return mystr
#English version
#def priblink(word):
# return "https://www.dictionary.com/browse/"+clean(word)
#
#def check(word):
# web = browsercontent(priblink(word))
# if (web == "ERROR"):
# return False
# return not (("No results found for") in web)
# PORTUGUESE VERSION
def priblink(word):
return "https://dicionario.priberam.org/"+clean(word)
def check(word):
web = browsercontent(priblink(word))
return not (("Palavra n"+chr(227)+"o encontrada.") in web)