Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
forslund committed Jul 13, 2018
0 parents commit 34bcd35
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
settings.json
__pycache__
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## Cocktail
Cocktail recipies using thecocktaildb

## Description
Lets mycroft read drink and cocktail recipies.

For devices with screen support, conditions are briefly shown.

## Examples
* "How do I make a moscow mule"
* "How do I mix a gin and tonic"

## Credits
Åke Forslund
49 changes: 49 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from mycroft import MycroftSkill, intent_file_handler
from mycroft.util.log import LOG
import requests
import time


API_KEY = '1'
API_URL = 'https://www.thecocktaildb.com/api/json/v1/{}/'.format(API_KEY)
SEARCH = API_URL + 'search.php'


def search_cocktail(name):
r = requests.get(SEARCH, params={'s': name})
if 200 <= r.status_code < 300:
return r.json()['drinks'][0]
else:
return None


def ingredients(drink):
ingredients = []
for i in range(1, 15):
if not drink['strIngredient' + str(i)]:
break
ingredients.append(' '.join((drink['strMeasure' + str(i)],
drink['strIngredient' + str(i)])))
return ingredients


class CocktailSkill(MycroftSkill):
@intent_file_handler('Recipie.intent')
def get_recipie(self, message):
LOG.info('!!!!!!!!!!!')
LOG.info(message.data['recepie'])
cocktail = search_cocktail(message.data['recepie'])
if cocktail:
ingredient_speech = 'You\'ll need '
for i in ingredients(cocktail)[:-1]:
print(i)
ingredient_speech += ', ' + i
ingredient_speech += ' and '
ingredient_speech += ingredients(cocktail)[-1]
self.speak(ingredient_speech)
time.sleep(1)
self.speak(cocktail['strInstructions'])


def create_skill():
return CocktailSkill()
4 changes: 4 additions & 0 deletions vocab/en-us/Recipie.intent
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
how do i make (a|an) {recepie}
how do i mix (a|an) {recepie}
tell me how to mix (a|an) {recepie}
give me instructions for (a|an) {recepie}

0 comments on commit 34bcd35

Please sign in to comment.