Skip to content

Instantly share code, notes, and snippets.

@allanburleson
Last active January 25, 2016 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allanburleson/f4e048e14f32b2d0195f to your computer and use it in GitHub Desktop.
Save allanburleson/f4e048e14f32b2d0195f to your computer and use it in GitHub Desktop.
ScrabbleDict.py
# coding: utf-8
from bs4 import BeautifulSoup
import requests
import sys
import webbrowser
pythonista = True
try:
import notification
import console
except ImportError:
pythonista = False
def getWord():
global usearg
if len(sys.argv) > 1:
usarg = True
word = sys.argv[1]
elif pythonista:
word = console.input_alert('Word:')
while word == '':
word = console.input_alert('Try again (actually type something)')
else:
word = getInput('Word: ')
while word == '':
word = getInput('Try again (actually type something)\n')
return word
def notify(status):
if status:
text = 'Your word is valid!'
yes = True
else:
text = 'Sorry, your word is invalid.'
yes = False
if pythonista and usearg:
webbrowser.open('launcher://crash')
notification.schedule('text', 3, '', 'pythonista://ScrabbleDict?action=run')
elif pythonista:
console.hud_alert(text) if yes else console.hud_alert(text, 'error')
else:
print(text)
def getInput(prompt):
if sys.version.startswith('2'):
inp = raw_input(prompt)
else:
inp = input(prompt)
return inp
usearg = False
word = getWord()
word = word.lower().strip()
url = 'http://scrabble.merriam.com/finder/' + word
page = requests.get(url)
soup = BeautifulSoup(page.text, 'html5lib')
workyString = soup.select('.play_area')[0].get_text().strip()
worky = True if workyString == word.upper() + ' is a playable word' else False
notify(worky)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment