Python flask_ask.statement() Examples

The following are 30 code examples of flask_ask.statement(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module flask_ask , or try the search function .
Example #1
Source File: alexa.py    From kanzi with MIT License 6 votes vote down vote up
def alexa_current_playitem_time_remaining(kodi):
  card_title = render_template('time_left_playing').encode('utf-8')
  log.info(card_title)

  response_text = render_template('nothing_playing').encode('utf-8')

  status = kodi.GetPlayerStatus()
  if status['state'] is not 'stop':
    minsleft = status['total_mins'] - status['time_mins']
    if minsleft == 0:
      response_text = render_template('remaining_close').encode('utf-8')
    elif minsleft == 1:
      response_text = render_template('remaining_min').encode('utf-8')
    elif minsleft > 1:
      response_text = render_template('remaining_mins', minutes=minsleft).encode('utf-8')
      tz = config.get(kodi.dev_cfg_section, 'timezone')
      if minsleft > 9 and tz and tz != 'None':
        utctime = datetime.datetime.now(pytz.utc)
        loctime = utctime.astimezone(pytz.timezone(tz))
        endtime = loctime + datetime.timedelta(minutes=minsleft)
        response_text += render_template('remaining_time', end_time=endtime.strftime('%I:%M')).encode('utf-8')

  return statement(response_text).simple_card(card_title, response_text) 
Example #2
Source File: voice.py    From DepressionAI with MIT License 6 votes vote down vote up
def outside():
    message = random.choice([
        'Awesome.',
        'Good to hear!',
        'Wonderful!',
        'Great!',
    ])

    session.attributes["Outside"] = "Yes"
    session.attributes["State"] = "Suggested"
    response = evaluate_answers()
    if response == "Good job doing all those things. When you're depressed, those little things can be the most difficult.":
        suggestion_inquiry = "Let's try something else to improve your mood."
    else:
        suggestion_inquiry = "Here's an idea for an extra way to improve your mood."
        idea = ideas()

    return statement(message + "      " + suggestion_inquiry + "       " + idea + "          " + "I hope I could help. Would you like another suggestion?") 
Example #3
Source File: playback.py    From geemusic with GNU General Public License v3.0 6 votes vote down vote up
def list_all_playlists():
    if api.is_indexing():
        return statement(render_template("indexing"))

    all_playlists = api.get_all_user_playlist_contents()
    playlist_names = []
    total_playlists = 0
    for i, match in enumerate(all_playlists):

        playlist_names.append(match['name'])
        total_playlists = i + 1

    # Adds "and" before the last playlist to sound more natural when speaking
    if len(playlist_names) >= 3:
        and_placement = len(playlist_names) - 1
        playlist_names.insert(and_placement, render_template("playlist_separator"))

    app.logger.debug(playlist_names)
    playlist_names = ', '.join(playlist_names)

    speech_text = render_template("list_all_playlists_text",
                                  playlist_count=total_playlists,
                                  playlist_list=playlist_names)
    return statement(speech_text) 
Example #4
Source File: playback.py    From geemusic with GNU General Public License v3.0 6 votes vote down vote up
def currently_playing():
    if api.is_indexing():
        return statement(render_template("indexing"))

    track = queue.current_track()

    if track is None:
        return audio(render_template("currently_playing_none"))

    if 'albumArtRef' in queue.current_track():
        thumbnail = api.get_thumbnail(queue.current_track()['albumArtRef'][0]['url'])
    else:
        thumbnail = None
    return statement(render_template("success_title")
                     + render_template("success_text",
                                       song=track['title'],
                                       artist=track['artist']))\
        .standard_card(title=render_template("success_title"),
                       text=render_template("success_text",
                                            song=track['title'],
                                            artist=track['artist']),
                       small_image_url=thumbnail,
                       large_image_url=thumbnail) 
Example #5
Source File: alexa.py    From kanzi with MIT License 6 votes vote down vote up
def alexa_loop_on(kodi):
  card_title = render_template('loop_enable').encode('utf-8')
  log.info(card_title)

  kodi.PlayerLoopOn()

  response_text = ''

  curprops = kodi.GetActivePlayProperties()
  if curprops is not None:
    if curprops['repeat'] == 'one':
      response_text = render_template('loop_one').encode('utf-8')
    elif curprops['repeat'] == 'all':
      response_text = render_template('loop_all').encode('utf-8')
    elif curprops['repeat'] == 'off':
      response_text = render_template('loop_off').encode('utf-8')

  return statement(response_text).simple_card(card_title, response_text)


# Handle the AMAZON.LoopOffIntent intent. 
Example #6
Source File: voice.py    From DepressionAI with MIT License 6 votes vote down vote up
def outside():
    message = random.choice([
        'Awesome.',
        'Good to hear!',
        'Wonderful!',
        'Great!',
    ])

    session.attributes["Outside"] = "Yes"
    session.attributes["State"] = "Suggested"
    response = evaluate_answers()
    if response == "Good job doing all those things. When you're depressed, those little things can be the most difficult.":
        suggestion_inquiry = "Let's try something else to improve your mood."
    else:
        suggestion_inquiry = "Here's an idea for an extra way to improve your mood."
        idea = ideas()

    return statement(message + "      " + suggestion_inquiry + "       " + idea + "          " + "I hope I could help. Would you like another suggestion?") 
Example #7
Source File: voice.py    From DepressionAI with MIT License 6 votes vote down vote up
def outside():
    message = random.choice([
        'Awesome.',
        'Good to hear!',
        'Wonderful!',
        'Great!',
    ])

    session.attributes["Outside"] = "Yes"
    session.attributes["State"] = "Suggested"
    response = evaluate_answers()
    if response == "Good job doing all those things. When you're depressed, those little things can be the most difficult.":
        suggestion_inquiry = "Let's try something else to improve your mood."
    else:
        suggestion_inquiry = "Here's an idea for an extra way to improve your mood."
        idea = ideas()

    return statement(message + "      " + suggestion_inquiry + "       " + idea + "          " + "I hope I could help. Would you like another suggestion?") 
Example #8
Source File: alexa.py    From kanzi with MIT License 6 votes vote down vote up
def alexa_listen_recently_added_songs(kodi):
  card_title = render_template('playing_recent_songs').encode('utf-8')
  log.info(card_title)

  response_text = render_template('no_recent_songs').encode('utf-8')

  songs_result = kodi.GetRecentlyAddedSongs()
  if songs_result:
    songs = songs_result['result']['songs']

    songs_array = []
    for song in songs:
      songs_array.append(song['songid'])

    kodi.PlayerStop()
    kodi.ClearAudioPlaylist()
    kodi.AddSongsToPlaylist(songs_array, True)
    kodi.StartAudioPlaylist()
    response_text = render_template('playing_recent_songs').encode('utf-8')

  return statement(response_text).simple_card(card_title, response_text) 
Example #9
Source File: selection.py    From geemusic with GNU General Public License v3.0 6 votes vote down vote up
def play_album_by_artist(artist_name):
    api = GMusicWrapper.generate_api()
    album = api.get_album_by_artist(artist_name=artist_name)

    if album is False:
        return statement(render_template("no_album"))

    # Setup the queue
    first_song_id = queue.reset(album['tracks'])

    # Start streaming the first track
    stream_url = api.get_stream_url(first_song_id)

    speech_text = render_template("play_album_text",
                                  album=album['name'],
                                  artist=album['albumArtist'])
    return audio(speech_text).play(stream_url) 
Example #10
Source File: selection.py    From geemusic with GNU General Public License v3.0 6 votes vote down vote up
def play_promoted_songs():
    app.logger.debug("Fetching songs that you have up voted.")

    promoted_songs = api.get_promoted_songs()
    if promoted_songs is False:
        return statement(render_template("play_promoted_songs_no_songs"))

    first_song_id = queue.reset(promoted_songs)
    stream_url = api.get_stream_url(first_song_id)

    if "albumArtRef" in queue.current_track():
        thumbnail = api.get_thumbnail(queue.current_track()['albumArtRef'][0]['url'])
    else:
        thumbnail = None
    speech_text = render_template("play_promoted_songs_text")
    return audio(speech_text).play(stream_url) \
        .standard_card(title=speech_text,
                       text='',
                       small_image_url=thumbnail,
                       large_image_url=thumbnail) 
Example #11
Source File: alexa.py    From kanzi with MIT License 5 votes vote down vote up
def _alexa_listen_audio_playlist(kodi, AudioPlaylist, shuffle=False):
  if shuffle:
    op = render_template('shuffling_empty').encode('utf-8')
  else:
    op = render_template('playing_empty').encode('utf-8')

  card_title = render_template('action_audio_playlist', action=op).encode('utf-8')
  log.info(card_title)

  playlist = kodi.FindAudioPlaylist(AudioPlaylist)
  if playlist:
    if shuffle:
      songs = kodi.GetPlaylistItems(playlist[0][0])['result']['files']
      songs_array = []
      for song in songs:
        songs_array.append(song['id'])

      kodi.PlayerStop()
      kodi.ClearAudioPlaylist()
      kodi.AddSongsToPlaylist(songs_array, True)
      kodi.StartAudioPlaylist()
    else:
      kodi.PlayerStop()
      kodi.StartAudioPlaylist(playlist[0][0])
    response_text = render_template('playing_playlist_audio', action=op, playlist_name=playlist[0][1]).encode('utf-8')
  else:
    response_text = render_template('could_not_find_playlist', heard_name=AudioPlaylist).encode('utf-8')

  return statement(response_text).simple_card(card_title, response_text)


# Handle the ListenToAudioPlaylist intent. 
Example #12
Source File: alexa.py    From kanzi with MIT License 5 votes vote down vote up
def alexa_party_play(kodi):
  card_title = render_template('party_mode').encode('utf-8')
  log.info(card_title)

  kodi.PlayerStop()
  kodi.ClearAudioPlaylist()
  kodi.PartyPlayMusic()
  response_text = render_template('playing_party').encode('utf-8')
  return statement(response_text).simple_card(card_title, response_text)


# Handle the AMAZON.StartOverIntent intent. 
Example #13
Source File: alexa.py    From kanzi with MIT License 5 votes vote down vote up
def alexa_subtitles_on(kodi):
  card_title = render_template('subtitles_enable').encode('utf-8')
  log.info(card_title)

  kodi.PlayerSubtitlesOn()
  response_text = kodi.GetCurrentSubtitles()
  return statement(response_text).simple_card(card_title, response_text)


# Handle the SubtitlesOff intent. 
Example #14
Source File: alexa.py    From kanzi with MIT License 5 votes vote down vote up
def alexa_subtitles_next(kodi):
  card_title = render_template('subtitles_next').encode('utf-8')
  log.info(card_title)

  kodi.PlayerSubtitlesNext()
  response_text = kodi.GetCurrentSubtitles()
  return statement(response_text).simple_card(card_title, response_text)


# Handle the SubtitlesPrevious intent. 
Example #15
Source File: alexa.py    From kanzi with MIT License 5 votes vote down vote up
def alexa_subtitles_off(kodi):
  card_title = render_template('subtitles_disable').encode('utf-8')
  log.info(card_title)

  kodi.PlayerSubtitlesOff()
  response_text = render_template('subtitles_disable').encode('utf-8')
  return statement(response_text).simple_card(card_title, response_text)


# Handle the SubtitlesNext intent. 
Example #16
Source File: alexa.py    From kanzi with MIT License 5 votes vote down vote up
def alexa_subtitles_previous(kodi):
  card_title = render_template('subtitles_previous').encode('utf-8')
  log.info(card_title)

  kodi.PlayerSubtitlesPrevious()
  response_text = kodi.GetCurrentSubtitles()
  return statement(response_text).simple_card(card_title, response_text)


# Handle the SubtitlesDownload intent. 
Example #17
Source File: alexa.py    From kanzi with MIT License 5 votes vote down vote up
def alexa_listen_album_or_song(kodi, Song, Artist):
  card_title = render_template('playing_album_or_song').encode('utf-8')
  log.info(card_title)

  response_text = ''

  artist = kodi.FindArtist(Artist)
  if artist:
    for a in artist:
      log.info('Searching songs and albums by "%s"', a[1].encode('utf-8'))
      song = kodi.FindSong(Song, a[0])
      if song:
        kodi.PlayerStop()
        kodi.ClearAudioPlaylist()
        kodi.AddSongToPlaylist(song[0][0])
        kodi.StartAudioPlaylist()
        response_text = render_template('playing_song_artist', song_name=song[0][1], artist=a[1]).encode('utf-8')
        break
      else:
        album = kodi.FindAlbum(Song, a[0])
        if album:
          kodi.PlayerStop()
          kodi.ClearAudioPlaylist()
          kodi.AddAlbumToPlaylist(album[0][0])
          kodi.StartAudioPlaylist()
          response_text = render_template('playing_album_artist', album_name=album[0][1], artist=a[1]).encode('utf-8')
          break
        elif not response_text:
          response_text = render_template('could_not_find_multi', heard_name=Song, artist=a[1]).encode('utf-8')
  else:
    response_text = render_template('could_not_find', heard_name=Artist).encode('utf-8')

  return statement(response_text).simple_card(card_title, response_text)


# Handle the ListenToAudioPlaylistRecent intent (Shuffle all recently added songs). 
Example #18
Source File: alexa.py    From kanzi with MIT License 5 votes vote down vote up
def alexa_shuffle_off(kodi):
  card_title = render_template('shuffle_disable').encode('utf-8')
  log.info(card_title)

  kodi.PlayerShuffleOff()
  response_text = render_template('shuffle_off').encode('utf-8')
  return statement(response_text).simple_card(card_title, response_text)


# Handle the AMAZON.LoopOnIntent intent. 
Example #19
Source File: alexa.py    From kanzi with MIT License 5 votes vote down vote up
def alexa_volume_set_pct(kodi, Volume):
  card_title = render_template('adjusting_volume').encode('utf-8')
  log.info(card_title)

  vol = kodi.VolumeSet(int(Volume))['result']
  response_text = render_template('volume_set', num=vol).encode('utf-8')
  return statement(response_text).simple_card(card_title, response_text)


# Handle the SubtitlesOn intent. 
Example #20
Source File: alexa.py    From kanzi with MIT License 5 votes vote down vote up
def _alexa_listen_latest_album(kodi, Artist, shuffle=False):
  if shuffle:
    card_title = render_template('shuffling_latest_album_card', heard_artist=Artist).encode('utf-8')
  else:
    card_title = render_template('playing_latest_album_card', heard_artist=Artist).encode('utf-8')
  log.info(card_title)

  artist = kodi.FindArtist(Artist)
  if artist:
    album_id = kodi.GetNewestAlbumFromArtist(artist[0][0])
    if album_id:
      album_label = kodi.GetAlbumDetails(album_id)['label']
      kodi.PlayerStop()
      kodi.ClearAudioPlaylist()
      kodi.AddAlbumToPlaylist(album_id, shuffle)
      kodi.StartAudioPlaylist()
      if shuffle:
        response_text = render_template('shuffling_album_artist', album_name=album_label, artist=artist[0][1]).encode('utf-8')
      else:
        response_text = render_template('playing_album_artist', album_name=album_label, artist=artist[0][1]).encode('utf-8')
    else:
      response_text = render_template('could_not_find_artist', artist_name=artist[0][1]).encode('utf-8')
  else:
    response_text = render_template('could_not_find', heard_name=Artist).encode('utf-8')

  return statement(response_text).simple_card(card_title, response_text)


# Handle the ListenToLatestAlbum intent (Play latest album by a specific artist). 
Example #21
Source File: alexa.py    From kanzi with MIT License 5 votes vote down vote up
def alexa_listen_artist(kodi, Artist, MusicGenre):
  genre = []
  if MusicGenre:
    card_title = render_template('listen_artist_genre', heard_genre=MusicGenre, heard_artist=Artist).encode('utf-8')
    genre = kodi.FindMusicGenre(MusicGenre)
  else:
    card_title = render_template('listen_artist', heard_artist=Artist).encode('utf-8')
  log.info(card_title)

  artist = kodi.FindArtist(Artist)
  if artist:
    if genre:
      songs_result = kodi.GetArtistSongsByGenre(artist[0][1], genre[0][1])
      response_text = render_template('playing_genre_artist', genre_name=genre[0][1], artist_name=artist[0][1]).encode('utf-8')
    else:
      songs_result = kodi.GetArtistSongs(artist[0][0])
      response_text = render_template('playing', heard_name=artist[0][1]).encode('utf-8')
    if 'songs' in songs_result['result']:
      songs = songs_result['result']['songs']

      songs_array = []
      for song in songs:
        songs_array.append(song['songid'])

      kodi.PlayerStop()
      kodi.ClearAudioPlaylist()
      kodi.AddSongsToPlaylist(songs_array, True)
      kodi.StartAudioPlaylist()
    elif genre:
      response_text = render_template('could_not_find_genre_artist', genre_name=genre[0][1], artist_name=artist[0][1]).encode('utf-8')
    else:
      response_text = render_template('could_not_find_artist', artist_name=artist[0][1]).encode('utf-8')
  else:
    response_text = render_template('could_not_find', heard_name=Artist).encode('utf-8')

  return statement(response_text).simple_card(card_title, response_text) 
Example #22
Source File: alexa.py    From kanzi with MIT License 5 votes vote down vote up
def alexa_listen_genre(kodi, MusicGenre):
  card_title = render_template('playing_genre', genre_name=MusicGenre).encode('utf-8')
  log.info(card_title)

  genre = kodi.FindMusicGenre(MusicGenre)
  if genre:
    songs_result = kodi.GetSongsByGenre(genre[0][1])
    if 'songs' in songs_result['result']:
      songs = songs_result['result']['songs']

      songs_array = []
      for song in songs:
        songs_array.append(song['songid'])

      kodi.PlayerStop()
      kodi.ClearAudioPlaylist()
      kodi.AddSongsToPlaylist(songs_array, True)
      kodi.StartAudioPlaylist()
      response_text = render_template('playing_genre', genre_name=genre[0][1]).encode('utf-8')
    else:
      response_text = render_template('could_not_find_genre', genre_name=genre[0][1]).encode('utf-8')
  else:
    response_text = render_template('could_not_find', heard_name=MusicGenre).encode('utf-8')

  return statement(response_text).simple_card(card_title, response_text)


# Handle the ListenToArtist intent (Shuffles all music by an artist, optionally of a specific genre). 
Example #23
Source File: alexa.py    From kanzi with MIT License 5 votes vote down vote up
def _alexa_play_media(kodi, Movie=None, Artist=None, content=None, shuffle=False):
  if not content:
    content=['video','audio']

  heard_search = ''
  heard_slot = 'unknown'
  if 'video' in content and Movie:
    heard_search = Movie
    heard_slot = 'Movie'
  elif 'audio' in content and Artist:
    heard_search = Artist
    heard_slot = 'Artist'

  card_title = render_template('playing', heard_name=heard_search).encode('utf-8')
  log.info(card_title)

  if not config.getboolean('global', 'deep_search'):
    response_text = render_template('help_play').encode('utf-8')
  else:
    response_text = find_and_play(kodi, heard_search, content, shuffle, slot_hint=heard_slot)
    if not response_text and heard_slot != 'unknown':
      response_text = find_and_play(kodi, heard_search, content, shuffle, slot_ignore=[heard_slot])
    if not response_text:
      response_text = render_template('could_not_find', heard_name=heard_search).encode('utf-8')

  return statement(response_text).simple_card(card_title, response_text) 
Example #24
Source File: alexa.py    From kanzi with MIT License 5 votes vote down vote up
def alexa_player_seek_bigbackward(kodi):
  card_title = render_template('big_step_backward').encode('utf-8')
  log.info(card_title)

  kodi.PlayerSeekBigBackward()
  return statement('').simple_card(card_title, '') 
Example #25
Source File: alexa.py    From kanzi with MIT License 5 votes vote down vote up
def alexa_player_seek_bigforward(kodi):
  card_title = render_template('big_step_forward').encode('utf-8')
  log.info(card_title)

  kodi.PlayerSeekBigForward()
  return statement('').simple_card(card_title, '')


# Handle the PlayerSeekBigBackward intent. 
Example #26
Source File: alexa.py    From kanzi with MIT License 5 votes vote down vote up
def alexa_player_seek_smallbackward(kodi):
  card_title = render_template('step_backward').encode('utf-8')
  log.info(card_title)

  kodi.PlayerSeekSmallBackward()
  return statement('').simple_card(card_title, '')


# Handle the PlayerSeekBigForward intent. 
Example #27
Source File: alexa.py    From kanzi with MIT License 5 votes vote down vote up
def alexa_player_seek_smallforward(kodi):
  card_title = render_template('step_forward').encode('utf-8')
  log.info(card_title)

  kodi.PlayerSeekSmallForward()
  return statement('').simple_card(card_title, '')


# Handle the PlayerSeekSmallBackward intent. 
Example #28
Source File: alexa.py    From kanzi with MIT License 5 votes vote down vote up
def alexa_player_seek_backward(kodi, BackwardDur):
  card_title = render_template('step_backward').encode('utf-8')
  log.info(card_title)

  seek_sec = duration_in_seconds(BackwardDur)

  card_body = 'Stepping backward by %d seconds' % (seek_sec)
  log.info(card_body)

  kodi.PlayerSeek(-seek_sec)
  return statement('').simple_card(card_title, card_body)


# Handle the PlayerSeekSmallForward intent. 
Example #29
Source File: alexa.py    From kanzi with MIT License 5 votes vote down vote up
def alexa_stop_cancel(kodi):
  if session.new:
    card_title = render_template('stopping').encode('utf-8')
    log.info(card_title)

    kodi.PlayerStop()
    response_text = render_template('playback_stopped').encode('utf-8')
    return statement(response_text).simple_card(card_title, response_text)
  else:
    return statement('')


# Handle the AMAZON.StopIntent intent. 
Example #30
Source File: alexa.py    From kanzi with MIT License 5 votes vote down vote up
def alexa_play_pause(kodi):
  card_title = render_template('play_pause').encode('utf-8')
  log.info(card_title)

  kodi.PlayerPlayPause()
  return statement('').simple_card(card_title, '')


# Handle the AMAZON.PauseIntent intent.