Created
July 6, 2017 06:20
-
-
Save kevalpatel2106/44bbb610093e02641835d4a99e8e25cd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from __future__ import print_function | |
import argparse | |
import os.path | |
import json | |
import google.oauth2.credentials | |
import RPi.GPIO as GPIO | |
from google.assistant.library import Assistant | |
from google.assistant.library.event import EventType | |
from google.assistant.library.file_helpers import existing_file | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setup(25, GPIO.OUT) | |
def process_event(event): | |
"""Pretty prints events. | |
Prints all events that occur with two spaces between each new | |
conversation and a single space between turns of a conversation. | |
Args: | |
event(event.Event): The current event to process. | |
""" | |
if event.type == EventType.ON_CONVERSATION_TURN_STARTED: | |
print() | |
GPIO.output(25,True) | |
print(event) | |
if (event.type == EventType.ON_CONVERSATION_TURN_FINISHED and | |
event.args and not event.args['with_follow_on_turn']): | |
print() | |
GPIO.output(25,False) | |
def main(): | |
parser = argparse.ArgumentParser( | |
formatter_class=argparse.RawTextHelpFormatter) | |
parser.add_argument('--credentials', type=existing_file, | |
metavar='OAUTH2_CREDENTIALS_FILE', | |
default=os.path.join( | |
os.path.expanduser('/home/pi/.config'), | |
'google-oauthlib-tool', | |
'credentials.json' | |
), | |
help='Path to store and read OAuth2 credentials') | |
args = parser.parse_args() | |
with open(args.credentials, 'r') as f: | |
credentials = google.oauth2.credentials.Credentials(token=None, | |
**json.load(f)) | |
with Assistant(credentials) as assistant: | |
for event in assistant.start(): | |
process_event(event) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment