Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
KRISHNA TEJA TOKALASatish Divakarla
Published © GPL3+

ChillFlix

Sure you can LOGIN and SEARCH for shows and movies on NETFLIX. How would it be to ask your assistant and get the answers .

IntermediateFull instructions provided8 hours1,717

Things used in this project

Hardware components

Echo Dot
Amazon Alexa Echo Dot
×1
Amazon Echo
Amazon Alexa Amazon Echo
×1
Amazon Tap
Amazon Alexa Amazon Tap
×1

Software apps and online services

AWS Lambda
Amazon Web Services AWS Lambda
AWS S3
Amazon Web Services AWS S3
We are using s3 only during the deployment phase to upload our zipfile created by zappa which is used by our lambda function.
AWS RDS
Amazon Web Services AWS RDS
Alexa Skills Kit
Amazon Alexa Alexa Skills Kit
TheMovieDB

Story

Read more

Schematics

High Level Infrastructure Diagram

Leveraging AWS Lambda and RDS

Interaction Model

The green boxes are for user Utterances and the Blue ones are Alexa's reply

Code

Python Class using Flask-Ask

Python
This is the python application which uses flask_ask and flask python modules to run the application.
The database that is being used in mySQL and mongodb. - Sorry about the credentials. There can be a miss use.
__author__ = 'krishnateja'

import logging
from flaskext.mysql import MySQL
from flask import Flask
from flask_ask import Ask, statement, question, session
from pymongo import MongoClient

mysql = MySQL()

app = Flask(__name__)
app.config.from_object(__name__)
app.config['MYSQL_DATABASE_USER'] = ''
app.config['MYSQL_DATABASE_PASSWORD'] = ''
app.config['MYSQL_DATABASE_DB'] = ''
app.config['MYSQL_DATABASE_HOST'] = ''
mysql.init_app(app)

ask = Ask(app, "/")

logging.getLogger("flask_ask").setLevel(logging.DEBUG)

list_of_words = ['a', 'the']
hellp_message = ''


def search_mongo(column):
    cursor_mongo = column.find({"id": int(session.attributes['moviedb'])})
    data_len = cursor_mongo.count()
    if data_len > 0:
        for document in cursor_mongo:
            return document
    else:
        return None


def search_movie(movie_name):
    print(movie_name)
    found = False
    if movie_name.split(' ', 1)[0] in list_of_words:
        movie_name = movie_name.split(' ', 1)[1]
    else:
        pass
    cursor = mysql.connect().cursor()
    query = "SELECT themoviedb,title FROM netflix_movies.movies WHERE title LIKE '%" + movie_name + "%';"
    cursor.execute(query)
    data = cursor.fetchone()
    if len(data) == 0:
        message = 'Nope, Have not found the movie' + movie_name + 'in netflix.'
    else:
        message = 'Yes, I found ' + movie_name
        session.attributes['moviedb'] = data[0]
        found = True

    return message, found


def search_show(show_name):
    found = False
    if show_name.split(' ', 1)[0] in list_of_words:
        show_name = show_name.split(' ', 1)[1]
    else:
        pass
    cursor = mysql.connect().cursor()
    query = "SELECT themoviedb, title FROM netflix_movies.shows WHERE title LIKE '%" + show_name + "%';"

    cursor.execute(query)
    data = cursor.fetchone()
    if len(data) == 0:
        message = 'Nope, Have not found the show' + show_name + 'in netflix.'
    else:
        message = 'Yes, I found ' + show_name
        found = True
        session.attributes['moviedb'] = data[0]
    return message, found


def search_show_updates():
    print('This API has to be completed.')


def search_movie_updates():
    print('This API has to be completed.')


@ask.launch
def new_search():
    welcome_msg = 'What do you want to search for in Netflix?... shows or movies?'
    return question(welcome_msg)


@ask.intent("WelcomeIntent")
def search_for(search_for):
    session.attributes['search_attr'] = str(search_for)
    message = 'Sure, I can help you with that...'
    if str(search_for) == 'show' or str(search_for) == 'movie':
        message = message + 'What is the ' + str(search_for) + ' you want to search for.'
        return question(message)
    elif str(search_for) == 'shows' or str(search_for) == 'movies':
        message = message + 'What are the ' + str(search_for) + ' you want to search for.'
        return question(message)
    else:
        message = 'Sorry. You can say something like search for shows or movies.'
        return question(message)


@ask.intent("SearchIntent")
def search(search_name):
    message = 'Sorry, I think I miss heard you there. You can say things like Does netflix Have Narcos.'
    found = False

    if search_name == "" or search_name is None:
        return question(message)
    else:
        session.attributes['search_term'] = str(search_name)
        message, found = search_show(search_name)
    if found:
        session.attributes['search_attr'] = 'show'
        return question(message + '...Do you want more info about the show?')
    else:
        message, found = search_movie(search_name)
        if found:
            session.attributes['search_attr'] = 'movie'
            return question(message + '...Do you want more info about the movie?')
        else:
            return statement(message)


@ask.intent("MoreInfoIntent")
def search(more_info_search, search_name):
    search_name = search_name
    message_ending = "   Do you want to know anything else?"
    mongo_db_uri = ""
    client = MongoClient(uri)
    if search_name is not None:
        session.attributes['search_term'] = str(search_name)
        message, found = search_show(search_name)
        if found:
            session.attributes['search_attr'] = 'show'
            shows_coll = client.netflix_mongodb.netflix_shows
            search_data = search_mongo(shows_coll)
            if search_data is not None:
                if more_info_search == 'genre':
                    genres = search_data['genres']
                    message = ' It belongs to '
                    for genre in genres:
                        message += genre['name'] + "..."
                    message += message_ending
                    return question(message)
                elif more_info_search == 'overview':
                    overview = search_data['overview']
                    message = overview + message_ending
                    return question(message)
                else:
                    return statement('Sorry I could not quite understand what ' +more_info_search+' is. I can give you an overview or get you you the genre')
            else:
                return statement('Sorry I could not find any info about the show')
        else:
            message, found = search_movie(search_name)
            if found:
                session.attributes['search_attr'] = 'movie'
                return question(message + '. Do you want more info about the movie?')
            else:
                return statement(message)
    else:
        try:
            search_name = session.attributes['search_term']
        except:
            return question(
                'You can say things like what is the genre of Narcos or something like give me an overview of Shameless')
        session.attributes['search_term'] = str(search_name)
        message, found = search_show(search_name)
        if found:
            session.attributes['search_attr'] = 'show'
            shows_coll = client.netflix_mongodb.netflix_shows
            search_data = search_mongo(shows_coll)
            if search_data is not None:
                if more_info_search == 'genre':
                    genres = search_data['genres']
                    message = 'It belongs to '
                    for genre in genres:
                        message += genre['name'] + ". "
                    message += message_ending
                    return question(message)
                elif more_info_search == 'overview':
                    overview = search_data['overview']
                    message = overview + message_ending
                    return question(message)
                else:
                    return question('Sorry I could not find that info about the show but, I can give you an overview or the genre. You can say things like give me an overview or what is the genre?')
            else:
                return statement('Sorry I could not find any info about the show.')
        else:
            message, found = search_movie(search_name)
            if found:
                session.attributes['search_attr'] = 'movie'
                return question(message + ' Do you want more info about the movie?')
            else:
                return statement(message)


@ask.intent("AMAZON.HelpIntent")
def help_intent():
    message = 'You can say things like I want to search for shows... Does netflix have Narcos'
    return question(message)


@ask.intent("AMAZON.NoIntent")
def help_intent():
    message = 'Ok, Happy watching!!!'
    return statement(message)


@ask.intent("AMAZON.StopIntent")
def stop():
    message = 'Ok, Bye'
    return statement(message)


@ask.intent("AMAZON.CancelIntent")
def stop():
    message = 'Ok, Ciao'
    return statement(message)


if __name__ == '__main__':
    app.run()

IntentSchema

Textile
This is the intent schema used.
{
  "intents": [
    {
      "intent": "WelcomeIntent",
      "slots": [
        {
          "name": "search_for",
          "type": "SEARCH_FOR"
        }
      ]
    },
    {
      "intent": "SearchIntent",
      "slots": [
        {
          "name": "search_name",
          "type": "SEARCH_NAME"
        }
      ]
    },
    {
      "intent": "MoreInfoIntent",
      "slots": [
        {
          "name": "more_info_search",
          "type": "MORE_INFO"
        },
        {
          "name": "search_name",
          "type": "SEARCH_NAME"
        }
      ]
    },
    {
    	"intent": "AMAZON.HelpIntent"
    },
    {
      	"intent": "AMAZON.NoIntent"
    },
    {
      	"intent": "AMAZON.StopIntent"
    },
    {
      	"intent": "AMAZON.CancelIntent"
    }
  ]
}

Sample Utterances

Textile
These are the sample utterances to which the application responds to
WelcomeIntent search for {search_for}
SearchIntent does Netflix have {search_name}
SearchIntent can I find {search_name} in Netflix
MoreInfoIntent I want to know the {more_info_search}
MoreInfoIntent what is the {more_info_search}
MoreInfoIntent what is the {more_info_search} of {search_name}
MoreInfoIntent give me an {more_info_search} of {search_name}
MoreInfoIntent give me an {more_info_search}

Custom Slot for SEARCH_NAME

Textile
One of the custom slots for the application. This is just a sample fine and was created by using themoviesdb. We have the complete list for the app. I can definitely provide it to you on request.
Orange Is the New Black 
Shameless 
The Walking Dead 
Marco Polo 
Penny Dreadful 
The Shannara Chronicles 
Gilmore Girls 
Supernatural 
Breaking Bad 
Pretty Little Liars 
Greys Anatomy 
Peaky Blinders 
The Flash 2014 
American Horror Story 
Criminal Minds 
Arrow 
Sherlock 
House of Cards 
The Last Kingdom 
Friends 
Dark Matter 
Bones 
The One Hundred 
Bloodline 
The Vampire Diaries 
Once Upon a Time 
Sons of Anarchy 
Marvels Daredevil 
NCIS 
Scream 
Person of Interest 
The Office 
Dexter 
How I Met Your Mother 
Prison Break 
Hell on Wheels 
Law  Order Special Victims Unit 
Narcos 
Containment 
Marvels Agents of SHIELD 
Lost 
House 
Limitless 
The Blacklist 
Gotham 
Gossip Girl 
Crazy ExGirlfriend 
Parks and Recreation 
Zoo 
New Girl 
The Fosters 
The XFiles 
Jane the Virgin 
Girl Meets World 
That 70s Show 
One Tree Hill 
Wentworth 
Better Call Saul 
Archer 
Pokémon 
Its Always Sunny in Philadelphia 
Star Trek The Next Generation 
Mad Men 
Spartacus 
The Originals 
Family Guy 
Bates Motel 
Blue Bloods 
Hawaii Five0 
How to Get Away With Murder 
Midsomer Murders 
Reign 
Supergirl 
Scandal 
Glee 
DCs Legends of Tomorrow 
Quantico 
Luther 
Buffy the Vampire Slayer 
Arrested Development 
White Collar 
iZombie 
Friday Night Lights 
Black Mirror 
Star Trek Voyager 
Freaks and Geeks 
Baby Daddy 
Beauty and the Beast CW 
Sense8 
Unbreakable Kimmy Schmidt 
Aquarius 
The West Wing 
Scrubs 
Bobs Burgers 
Charmed 
Grace and Frankie 
The Killing 
The Secret Life of the American Teenager 
Skins UK 
The Fall 
Parenthood 
The Tudors 
Star Trek Deep Space Nine 
Turn 
Malcolm in the Middle 
Californication 
Firefly 
American Dad 
Twin Peaks 
Royal Pains 
The League 
Hart of Dixie 
90210 
Young  Hungry 
Weeds 
BoJack Horseman 
Frasier 
Star Trek The Original Series 
Columbo 
Longmire 
Last Man Standing 
Liv and Maddie 
Switched at Birth 
Fuller House 
Broadchurch 
Madam Secretary 
Revenge 
Death in Paradise 
Murder She Wrote 
Thirty Rock 
Happy Valley
Nurse Jackie 
Salem 
The Andy Griffith Show 
Star Trek Enterprise 
The Twilight Zone 
Cheers 
Agatha Christies Poirot 
Hemlock Grove 
Heartland 
Voltron Legendary Defender 

Custom Slot for SEARCH_FOR

Python
This is a custom slot file for SEARCH_FOR
shows
show
movie
movies

Custom slot for MORE_INFO

Python
This is a custom slot file for MORE_INFO
overview
genre
an overview

Credits

KRISHNA TEJA TOKALA

KRISHNA TEJA TOKALA

1 project • 2 followers
Satish Divakarla

Satish Divakarla

1 project • 0 followers

Comments