Example #1
0
File: HN.py Project: brad999/nikita
    def handleResponse(text):

        def extractOrdinals(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 = extractOrdinals(text)
        send_all = not chosen_articles and app_utils.isPositive(text)

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

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

            def formatArticle(article):
                tiny_url = app_utils.generateTinyURL(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.emailUser(profile, SUBJECT="",
                                                   BODY=article_link):
                            mic.say('A', "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.emailUser(profile,
                                           SUBJECT="From the Front Page of " +
                                                   "Hacker News",
                                           BODY=body):
                    mic.say('A', "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('A', "All done.")

        else:
            mic.say('A', "OK I will not send any articles")
    def handleResponse(text):

        def extractOrdinals(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 = extractOrdinals(text)
        send_all = not chosen_articles and app_utils.isPositive(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.generateTinyURL(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(articles):
                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.emailUser(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.emailUser(profile,
                                           SUBJECT="Your Top Headlines",
                                           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 set")

        else:

            mic.say("OK I will not send any articles")
Example #3
0
 def handleResponse(text):
     if app_utils.isPositive(text):
         mic.say("Checking the minutes...")
         sections = getMinutesSections()
         section = sections[section_title.lower()]
         mic.say(section.to_speakable_string())
     else:
         mic.say("Nevermind.")
Example #4
0
def changePostStatus(mic, wp, status):
    global target
    while True:
        ps = wp.getAllPosts()
        if status == "publish":
            mic.say(
                "Here is the posts list, which posting would you like to publish? Tell me the id."
            )
        elif status == "draft":
            mic.say(
                "Here is the posts list, which posting would you like to keep in draft? Tell me the id."
            )
        else:
            mic.say("no status change. Return")
            return
        print "Title \tId"
        for post in ps:
            print "%s \t%s " % (post.title, post.id)
        nums = mic.activeListen()
        numText = nums
        #for numText in nums:
        try:
            # check if it's a number
            num = int(numText)
            print num
            print type(num)
            while True:
                mic.say("is it %d ?" % num)
                ans = mic.activeListen()
                if ans:
                    if app_utils.isPositive(ans):
                        # make the post draft
                        target = getTarget(mic, num)
                        if status == "publish":
                            wp.publishPost(target)
                            p = wp.getThePost(target)
                            mic.say("The posting %s is published." % p.title)
                        elif status == "draft":
                            wp.unpublishPost(target)
                            p = wp.getThePost(target)
                            mic.say("The posting %s is kept as draft." %
                                    p.title)
                        else:
                            mic.say("it's hard to get here. Just in case")
                            return
                        return
                    elif app_utils.isNegative(ans):
                        # go to listen to the number
                        break
                    elif bool(re.search(r'\bOUT\b', ans, re.IGNORECASE)):
                        return
                    else:
                        pass
                else:
                    continue
        except ValueError:
            print("%s not an int!") % numText
def handle(text, mic, profile):
	mic.say("What would you like to search?")
	search = mic.activeListen()
	mic.say("Do you want to search for %s" % search)
	yn = mic.activeListen()
	if (app_utils.isPositive(yn) or yn == ""):
		summary = wikipedia.summary(search)
		mic.say(summary)	
	else:
		mic.say("I am so useless.")
def changePostStatus(mic, wp, status):
    global target
    while True:
        ps = wp.getAllPosts()
        if status == "publish":
            mic.say("Here is the posts list, which posting would you like to publish? Tell me the id.")
        elif status == "draft":
            mic.say("Here is the posts list, which posting would you like to keep in draft? Tell me the id.")
        else:
            mic.say("no status change. Return")
            return
        print "Title \tId"
        for post in ps:
            print "%s \t%s " % (post.title, post.id)
        nums = mic.activeListen()
        numText = nums
        #for numText in nums:
        try:
            # check if it's a number
            num = int(numText)
            print num
            print type(num)
            while True:
                mic.say("is it %d ?" % num)
                ans = mic.activeListen()
                if ans:
                    if app_utils.isPositive(ans):
                        # make the post draft
                        target = getTarget(mic, num)
                        if status == "publish":
                            wp.publishPost(target)
                            p = wp.getThePost(target)
                            mic.say("The posting %s is published." % p.title)
                        elif status == "draft":
                            wp.unpublishPost(target)
                            p = wp.getThePost(target)
                            mic.say("The posting %s is kept as draft." % p.title)
                        else:
                            mic.say("it's hard to get here. Just in case")
                            return
                        return
                    elif app_utils.isNegative(ans):
                        # go to listen to the number
                        break
                    elif bool(re.search(r'\bOUT\b', ans, re.IGNORECASE)):
                        return
                    else:
                        pass
                else:
                    continue
        except ValueError:
            print("%s not an int!") % numText
def createTitle(mic):
    while True:
        mic.say("What's the new post's title?")
        title = mic.activeListen()
        print title
        mic.say("The title is %s. Do you want to change it?" % title)
        ans = mic.activeListen()
        if app_utils.isPositive(ans):
            continue
        elif app_utils.isNegative(ans):
            mic.say("The title is %s." % title)
            return title
        elif bool(re.search(r'\bOUT\b', ans, re.IGNORECASE)):
            # if I don't want to create new post, just jump out
            return False
        else:
            continue
Example #8
0
def createTitle(mic):
    while True:
        mic.say("What's the new post's title?")
        title = mic.activeListen()
        print title
        mic.say("The title is %s. Do you want to change it?" % title)
        ans = mic.activeListen()
        if app_utils.isPositive(ans):
            continue
        elif app_utils.isNegative(ans):
            mic.say("The title is %s." % title)
            return title
        elif bool(re.search(r'\bOUT\b', ans, re.IGNORECASE)):
            # if I don't want to create new post, just jump out
            return False
        else:
            continue
def createPost(mic, wp):
    global target
    while True:
        mic.say("Going to create a new post")
        title = createTitle(mic)
        if not title:
            return
        content = createContent(mic)
        if not content:
            return
        # new post create
        new_post = wp.createPost(title, content)
        getTarget(mic, new_post.id)
        mic.say("Do you want to publish this ?")
        ans = mic.activeListen()
        if app_utils.isPositive(ans):
            wp.publishPost(new_post.id)
            mic.say("The new posting %s is published." % new_post.title)
        elif app_utils.isNegative(ans):
            mic.say("The new posting %s is draft." % new_post.title)
        else:
            mic.say("I will keep it as draft")

        return new_post
Example #10
0
def createPost(mic, wp):
    global target
    while True:
        mic.say("Going to create a new post")
        title = createTitle(mic)
        if not title:
            return
        content = createContent(mic)
        if not content:
            return
        # new post create
        new_post = wp.createPost(title, content)
        getTarget(mic, new_post.id)
        mic.say("Do you want to publish this ?")
        ans = mic.activeListen()
        if app_utils.isPositive(ans):
            wp.publishPost(new_post.id)
            mic.say("The new posting %s is published." % new_post.title)
        elif app_utils.isNegative(ans):
            mic.say("The new posting %s is draft." % new_post.title)
        else:
            mic.say("I will keep it as draft")

        return new_post