Created
April 6, 2018 20:36
-
-
Save mayorquinmachines/ae5ed9fa891c1f9d8dd32ab368f19ae9 to your computer and use it in GitHub Desktop.
Flask-ask tutorial sample application
This file contains 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 flask import Flask #Importing the main class | |
from flask_ask import Ask, statement #Importing Alexa class | |
import picamera | |
from datetime import datetime | |
from crontab import CronTab | |
app = Flask(__name__) #Initializing the app | |
ask = Ask(app, '/') #Initializing Alexa functionality around app | |
@app.route('/') | |
def home(): | |
return 'Hi! I am CentiPi' | |
@ask.intent('helloCentiPi') | |
def hello(): | |
speech_text = 'Hello there!' | |
return statement(speech_text).simple_card(title='CentiPi says', content= | |
speech_text) | |
@ask.intent('photoCentiPi') | |
def photo(): | |
camera = picamera.PiCamera() #initialize the camera | |
camera.capture('my_pic.jpg') #take a photo! | |
pic = '/home/pi/my_pic.jpg' | |
speech_text = 'Here is your picture!' | |
return statement(speech_text).display_render(template='BodyTemplate7', title='CentiPi', backButton='HIDDEN', background_image_url=pic) | |
@ask.intent('scheduleCentiPi') | |
def schedule(date, time): | |
cron = CronTab(user='pi') | |
job = cron.new('python /home/pi/take_picture.py') | |
dd = date + ' ' + time | |
job_date = datetime.strptime(dd, '%Y-%m-%d %H:%M') | |
job.setall(job_date) | |
cron.write() | |
speech_text = "Ok. I've got it scheduled for {} at {}".format(date,time) | |
return statement(speech_text) | |
if __name__ == "__main__": | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment