Skip to content

Commit

Permalink
First Code Commit
Browse files Browse the repository at this point in the history
Adds the Define.py file, a MethodTest file and a ReadMe.
  • Loading branch information
iamjake648 committed Jan 11, 2016
1 parent d32a578 commit 7556578
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
36 changes: 36 additions & 0 deletions Define.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#Written by Jake Schultz
import re
from urllib2 import Request, urlopen, URLError
import json

WORDS = ["DEFINE"]

PRIORITY = 1


def handle(text, mic, profile):

dict_key = profile['keys']['YANDEX_DICT']

get_def(text,mic,dict_key)


def get_def(text,mic,key):
mic.say("What word would you like to define?")
theWord = mic.activeListen()

request = Request('https://dictionary.yandex.net/api/v1/dicservice.json/lookup?key='+key+'&lang=en-en&text='+theWord)
try:
response = urlopen(request)
data = json.load(response)
word_type = data["def"][0]["pos"]
mic.say("The word is a " + word_type)
defs = data["def"][0]["tr"]
for text in defs:
mic.say(text["text"])
except URLError, e:
mic.say("Unable to reach dictionary API.")


def isValid(text):
return bool(re.search(r'\Define\b',text, re.IGNORECASE))
20 changes: 20 additions & 0 deletions MethodTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from urllib2 import Request, urlopen, URLError
import json
from pprint import pprint

key = ''


def get_def(text,key):
request = Request('https://dictionary.yandex.net/api/v1/dicservice.json/lookup?key='+key+'&lang=en-en&text='+text)
try:
response = urlopen(request)
data = json.load(response)
word_type = data["def"][0]["pos"]
defs = data["def"][0]["tr"]
for text in defs:
print text["text"]
except URLError, e:
print 'Unable to get translation', e

get_def('insect', key)
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
# jasper-dictionary
A jasper module that defines a given word.

jasper-dictionary is a jasper module that allows you to get the definition of a given word or phrase. It uses the Yandex Translate API (Free) to define words.

Usage:

- You: Jasper, Define
- Japser: What word would you like to define?
- You: Dog
- Jasper: Lists definitions

### Installation
- Get an API Key - https://tech.yandex.com/dictionary/doc/dg/concepts/api-overview-docpage/
- Add the key to the Jasper .profile under keys as "YANDEX_DICT"
- Add the Define.py file to the /client/modules dir.
- THATS IT!

0 comments on commit 7556578

Please sign in to comment.