Beispiel #1
0
    def handle_response(text):

        def extract_ordinals(text):
            output = []
            service = NumberService()
            for w in text.split():
                if w in service.__ordinals__:
                    output.append(service.__ordinals__[w])
            return [service.parse(w) for w in output]

        chosen_articles = extract_ordinals(text)
        send_all = not chosen_articles and app_utils.is_positive(text)

        if send_all or chosen_articles:
            mic.say("Sure, just give me a moment")

            if profile['prefers_email']:
                body = "<ul>"

            def formatArticle(article):
                tiny_url = app_utils.generate_tiny_URL(article.URL)

                if profile['prefers_email']:
                    return "<li><a href=\'%s\'>%s</a></li>" % (tiny_url,
                                                               article.title)
                else:
                    return article.title + " -- " + tiny_url

            for idx, article in enumerate(stories):
                if send_all or (idx + 1) in chosen_articles:
                    article_link = formatArticle(article)

                    if profile['prefers_email']:
                        body += article_link
                    else:
                        if not app_utils.email_user(profile, SUBJECT="",
                                                    BODY=article_link):
                            mic.say("I'm having trouble sending you these " +
                                    "articles. Please make sure that your " +
                                    "phone number and carrier are correct " +
                                    "on the dashboard.")
                            return

            # if prefers email, we send once, at the end
            if profile['prefers_email']:
                body += "</ul>"
                if not app_utils.email_user(profile,
                                            SUBJECT="From the Front Page of " +
                                                    "Hacker News",
                                            BODY=body):
                    mic.say("I'm having trouble sending you these articles. " +
                            "Please make sure that your phone number and " +
                            "carrier are correct on the dashboard.")
                    return

            mic.say("All done.")

        else:
            mic.say("OK I will not send any articles")
Beispiel #2
0
    def handle_response(text):
        def extract_ordinals(text):
            output = []
            service = NumberService()
            for w in text.split():
                if w in service.__ordinals__:
                    output.append(service.__ordinals__[w])
            return [service.parse(w) for w in output]

        chosen_articles = extract_ordinals(text)
        send_all = not chosen_articles and app_utils.is_positive(text)

        if send_all or chosen_articles:
            mic.say("Sure, just give me a moment")

            if profile['prefers_email']:
                body = "<ul>"

            def formatArticle(article):
                tiny_url = app_utils.generate_tiny_URL(article.URL)

                if profile['prefers_email']:
                    return "<li><a href=\'%s\'>%s</a></li>" % (tiny_url,
                                                               article.title)
                else:
                    return article.title + " -- " + tiny_url

            for idx, article in enumerate(stories):
                if send_all or (idx + 1) in chosen_articles:
                    article_link = formatArticle(article)

                    if profile['prefers_email']:
                        body += article_link
                    else:
                        if not app_utils.email_user(
                                profile, SUBJECT="", BODY=article_link):
                            mic.say("I'm having trouble sending you these " +
                                    "articles. Please make sure that your " +
                                    "phone number and carrier are correct " +
                                    "on the dashboard.")
                            return

            # if prefers email, we send once, at the end
            if profile['prefers_email']:
                body += "</ul>"
                if not app_utils.email_user(
                        profile,
                        SUBJECT="From the Front Page of " + "Hacker News",
                        BODY=body):
                    mic.say("I'm having trouble sending you these articles. " +
                            "Please make sure that your phone number and " +
                            "carrier are correct on the dashboard.")
                    return

            mic.say("All done.")

        else:
            mic.say("OK I will not send any articles")
 def handle(self, text, mic):
     mic.say("What configuration option would you like to change?")
     for option in OPTIONS:
         mic.say("Would you like to change %s?" % option)
         if app_utils.is_positive(mic.active_listen()[0]):
             func = "change_%s" % option.replace(" ", "_")
             getattr(self, func)(mic)
             return
     mic.say("No configuration option selected for modification")
 def handle(self, text, mic):
     mic.say('What configuration option would you like to change?')
     for option in OPTIONS:
         mic.say('Would you like to change %s?' % option)
         if app_utils.is_positive(mic.active_listen()[0]):
             func = 'change_%s' % option.replace(' ', '_')
             getattr(self, func)(mic)
             return
     mic.say('No configuration option selected for modification')