diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2014-07-26 23:31:25 +0000 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2014-07-26 23:31:25 +0000 |
| commit | 78389f252a021d642a7a0146b658f0465da6e264 (patch) | |
| tree | b740c6339ceba381004d3441f2459f65d38d02a6 /client/modules/Birthday.py | |
| parent | 2c55f4da462383ee6c7b89ea44e5c40cd5badf0c (diff) | |
| download | jasper-client-78389f252a021d642a7a0146b658f0465da6e264.tar.gz jasper-client-78389f252a021d642a7a0146b658f0465da6e264.zip | |
Work on Google STT on RPi.
Diffstat (limited to 'client/modules/Birthday.py')
| -rw-r--r-- | client/modules/Birthday.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/client/modules/Birthday.py b/client/modules/Birthday.py new file mode 100644 index 0000000..1388443 --- /dev/null +++ b/client/modules/Birthday.py @@ -0,0 +1,64 @@ +import datetime +import re +from facebook import * +from app_utils import getTimezone + +WORDS = ["BIRTHDAY"] + + +def handle(text, mic, profile): + """ + Responds to user-input, typically speech text, by listing the user's + Facebook friends with birthdays today. + + Arguments: + text -- user-input, typically transcribed speech + mic -- used to interact with the user (for both input and output) + profile -- contains information related to the user (e.g., phone number) + """ + oauth_access_token = profile['keys']["FB_TOKEN"] + + graph = GraphAPI(oauth_access_token) + + try: + results = graph.request( + "me/friends", args={'fields': 'id,name,birthday'}) + except GraphAPIError: + mic.say( + "I have not been authorized to query your Facebook. If you would like to check birthdays in the future, please visit the Jasper dashboard.") + return + except: + mic.say( + "I apologize, there's a problem with that service at the moment.") + return + + needle = datetime.datetime.now(tz=getTimezone(profile)).strftime("%m/%d") + + people = [] + for person in results['data']: + try: + if needle in person['birthday']: + people.append(person['name']) + except: + continue + + if len(people) > 0: + if len(people) == 1: + output = people[0] + " has a birthday today." + else: + output = "Your friends with birthdays today are " + \ + ", ".join(people[:-1]) + " and " + people[-1] + "." + else: + output = "None of your friends have birthdays today." + + mic.say(output) + + +def isValid(text): + """ + Returns True if the input is related to birthdays. + + Arguments: + text -- user-input, typically transcribed speech + """ + return bool(re.search(r'birthday', text, re.IGNORECASE)) |
