Listing 1:
----------

import requests, json, re

WORDS = ["LIGHTS", "OFF"]
PRIORITY = 10
BRIDGE = '192.168.1.7'

def switchLightsOff():
    bridge_url = 'http://' + BRIDGE + '/api/newdeveloper/'
    route = 'groups/0/action/'
    action_url = bridge_url + route
    transfer_data = json.dumps({"on": False })
    req = requests.put(action_url, data=transfer_data)

def isValid(text):
    return bool(re.search(r'\blights off\b', text, re.IGNORECASE))

def handle(text, mic, profile):
    mic.say("As you please!")
    switchLightsOff()


Listing 2:
----------

import feedparser
import re
from dateutil.parser import parse as parse_date

WORDS = ["WIRED", "NEWS"]
PRIORITY = 10
URL = 'http://www.wired.com/feed/'

def getMostRecentDate(articles):
    dates = [n["date"] for n in articles]
    dates.sort(reverse=True)
    if dates:
        return dates[0]
    return None

def getTopArticles(maxResults=None, since=None):
    d = feedparser.parse(URL)
    articles = []
    count = 0

    for post in d.entries:
        if not since or parse_date(post.published) > since:
            articles.append({ "headline" : post.title, "date" : parse_date(post.published) })
            count += 1
            if maxResults and count == maxResults:
                break

    return articles

def handle(text, mic, profile):
    mic.say("Let's see if there is something new.")
    articles = getTopArticles(maxResults=5)
    headlines = ''

    if len(articles) == 1:
        response = "There is one article"
    elif len(articles) > 1:
        response = "There are %s articles" % len(articles)
    else:
        mic.say("Sorry, but no articles could be found.")
        return

    mic.say(response)

    for article in articles:
        headlines += article["headline"].encode('utf-8') + "..."

    mic.say(headlines)

def isValid(text):
    return bool(re.search(r'\bwired news\b', text, re.IGNORECASE))

	
Listing 3:
----------

def handleRSSNotifications(self, lastDate):
    articles = rss.getTopArticles(maxResults=5, since=lastDate)

    if articles:
        lastDate = rss.getMostRecentDate(articles)

    for i, article in enumerate(articles):
        if i == 0 and len(articles) > 1:
            intro = "There are %s new articles, these are the headlines:" % len(articles)
            self.q.put(intro)
        elif i == 0 and len(articles) == 1:
            intro = "There is one new article, its headline is:"
            self.q.put(intro)
        
        self.q.put(article["headline"].encode('utf-8'))

    return lastDate

