def alexa_check_new_episodes(slots): card_title = 'Looking for new shows to watch' print card_title sys.stdout.flush() # Get the list of unwatched EPISODES from Kodi new_episodes = kodi.GetUnwatchedEpisodes() # Find out how many EPISODES were recently added and get the names of the SHOWS really_new_episodes = [x for x in new_episodes if x['dateadded'] >= datetime.datetime.today() - datetime.timedelta(5)] really_new_show_names = list(set([sanitize_show(x['show']) for x in really_new_episodes])) if len(really_new_episodes) == 0: answer = "There isn't anything new to watch." elif len(really_new_show_names) == 1: # Only one new show, so provide the number of episodes also. count = len(really_new_episodes) if count == 1: answer = "There is one new episide of %(show)s to watch." % {"show":really_new_show_names[0]} else: answer = "You have %(count)d new episides of %(show)s." % {'count':count, 'show':really_new_show_names[0]} elif len(really_new_show_names) == 2: random.shuffle(really_new_show_names) answer = "There are new episodes of %(show1)s and %(show2)s." % {'show1':really_new_show_names[0], 'show2':really_new_show_names[1]} elif len(really_new_show_names) > 2: show_sample = random.sample(really_new_show_names, 2) answer = "You have %(show1)s, %(show2)s, and more waiting to be watched." % {'show1':show_sample[0], 'show2':show_sample[1]} return build_alexa_response(answer, card_title)
def alexa_what_new_episodes(slots): # Lists the shows that have had new episodes added to Kodi in the last 5 days # Get the list of unwatched EPISODES from Kodi new_episodes = kodi.GetUnwatchedEpisodes() # Find out how many EPISODES were recently added and get the names of the SHOWS really_new_episodes = [x for x in new_episodes if x['dateadded'] >= datetime.datetime.today() - datetime.timedelta(5)] really_new_show_names = list(set([sanitize_show(x['show']) for x in really_new_episodes])) num_shows = len(really_new_show_names) if num_shows == 0: # There's been nothing added to Kodi recently answers = [ "You don't have any new shows to watch.", "There are no new shows to watch.", ] answer = random.choice(answers) if random.random() < 0.25: comments = [ " Maybe you should go to the movies.", " Maybe you'd like to read a book.", " Time to go for a bike ride?", " You probably have chores to do anyway.", ] answer += random.choice(comments) elif len(really_new_show_names) == 1: # There's only one new show, so provide information about the number of episodes, too. count = len(really_new_episodes) if count == 1: answers = [ "There is a single new episode of %(show)s." % {'show':really_new_show_names[0]}, "There is one new episode of %(show)s." % {'show':really_new_show_names[0]}, ] elif count == 2: answers = [ "There are a couple new episodes of %(show)s" % {'show':really_new_show_names[0]}, "There are two new episodes of %(show)s" % {'show':really_new_show_names[0]}, ] elif count >= 5: answers = [ "There are lots and lots of new episodes of %(show)s" % {'show':really_new_show_names[0]}, "There are %(count)d new episodes of %(show)s" % {"count":count, "show":really_new_show_names[0]}, ] else: answers = [ "You have a few new episodes of %(show)s" % {'show':really_new_show_names[0]}, "There are %(count)d new episodes of %(show)s" % {"count":count, "show":really_new_show_names[0]}, ] answer = random.choice(answers) else: # More than one new show has new episodes ready random.shuffle(really_new_show_names) show_list = really_new_show_names[0] for one_show in really_new_show_names[1:-1]: show_list += ", " + one_show show_list += ", and " + really_new_show_names[-1] answer = "There are new episodes of %(show_list)s." % {"show_list":show_list} return build_alexa_response(answer)
def alexa_what_new_episodes(slots): card_title = 'Newly added shows' print card_title sys.stdout.flush() # Lists the shows that have had new episodes added to Kodi in the last 5 days # Get the list of unwatched EPISODES from Kodi new_episodes = kodi.GetUnwatchedEpisodes() # Find out how many EPISODES were recently added and get the names of the SHOWS new_show_names = list(set([sanitize_name(x['show']) for x in new_episodes])) num_shows = len(new_show_names) if num_shows == 0: # There's been nothing added to Kodi recently answers = [ "You don't have any new shows to watch.", "There are no new shows to watch.", ] answer = random.choice(answers) answer += suggest_alternate_activity() elif len(new_show_names) == 1: # There's only one new show, so provide information about the number of episodes, too. count = len(new_episodes) if count == 1: answers = [ "There is a single new episode of %(show)s." % {'show':new_show_names[0]}, "There is one new episode of %(show)s." % {'show':new_show_names[0]}, ] elif count == 2: answers = [ "There are a couple new episodes of %(show)s" % {'show':new_show_names[0]}, "There are two new episodes of %(show)s" % {'show':new_show_names[0]}, ] elif count >= 5: answers = [ "There are lots and lots of new episodes of %(show)s" % {'show':new_show_names[0]}, "There are %(count)d new episodes of %(show)s" % {"count":count, "show":new_show_names[0]}, ] else: answers = [ "You have a few new episodes of %(show)s" % {'show':new_show_names[0]}, "There are %(count)d new episodes of %(show)s" % {"count":count, "show":new_show_names[0]}, ] answer = random.choice(answers) else: # More than one new show has new episodes ready random.shuffle(new_show_names) limited_new_show_names = new_show_names[0:5] show_list = limited_new_show_names[0] for one_show in limited_new_show_names[1:-1]: show_list += ", " + one_show if num_shows > 5: show_list += ", " + limited_new_show_names[-1] + ", and more" else: show_list += ", and" + limited_new_show_names[-1] answer = "There are new episodes of %(show_list)s." % {"show_list":show_list} return build_alexa_response(answer, card_title)
def alexa_new_show_inquiry(slots): # Responds to the question, "Do we have any new episodes of <show>?" # Get the list of unwatched EPISODES from Kodi new_episodes = kodi.GetUnwatchedEpisodes() # Group the episodes by the show name in normalized format show_episodes = {} for one_episode in new_episodes: normalized = str(one_episode['show']).lower().translate(None, string.punctuation) if not normalized in show_episodes: show_episodes[normalized] = [] show_episodes[normalized].append(one_episode) # See if we can match one of these to the show name the Echo heard heard_show = str(slots['Show']['value']).lower().translate(None, string.punctuation) located = None fuzzy_match = False # Try an exact match first if heard_show in show_episodes: located = heard_show if not located: # Try an exact match after removing any leading "the" heard_minus_the = remove_the(heard_show) for one_show in show_episodes: if remove_the(one_show) == heard_minus_the: located = one_show break if not located: # See if the spoken show matches the beginning of our show names # removing leading "the" from both. E.g. "Daily Show" vs "Daily Show with Jon Stewart" for one_show in show_episodes: if heard_minus_the == remove_the(one_show)[:len(heard_minus_the)]: located = one_show break if not located: # Last resort -- take out some useless words and see if we have a show with # any of the remaining words in common heard_list = set([x for x in heard_show.split() if x not in STOPWORDS]) for one_show in show_episodes: show_list = set(one_show.split()) if heard_list & show_list: located = one_show fuzzy_match = True break if not located: answer = "There are no shows called %(show)s." % {'show': heard_show} else: if fuzzy_match: answer = "You asked about %(show)s. " % {'show': heard_show} else: answer = "" count = len(show_episodes[located]) if count == 1: answer += "There is one unseen episode of %(real_show)s." % {'real_show': located} else: answer += "There are %(num)d episodes of %(real_show)s." % {'real_show': located, 'num': count} return build_alexa_response(answer)