Ejemplo n.º 1
0
    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(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("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("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")
Ejemplo n.º 2
0
def handle(mic, profile):
    global read_ids

    if read_ids is None:
        read_ids = [[]]*len(profile['email_notification'])

    reports = []
    for accountID in range(len(profile['email_notification'])):
        account = profile['email_notification'][accountID]
        # Connect
        obj = imaplib.IMAP4_SSL(account['server'])
        obj.login(
            account['user'],
            base64.b64decode(account['password'])
        )

        # Select & search
        obj.select()
        status, ans = obj.search(None, '(UNSEEN)')

        if status != 'OK':
            obj.logout()
            continue

        if ans == ['']:
            ans = []

        # Download header
        for id in ans:

            if id in read_ids[accountID]:
                continue
            read_ids[accountID].append(id)

            status, msg_data = obj.fetch(id, '(BODY.PEEK[HEADER] FLAGS)')
            if status != 'OK':
                break
            for response_part in msg_data:
                if isinstance(response_part, tuple):
                    msg = email.message_from_string(response_part[1])
                    sender = re.sub("<[^>]+>", '', msg['from']).strip()

                    reports.append('From %s: %s' % (sender, msg['subject']))

        obj.logout()

    # Query user
    if len(reports) > 0:
        mic.say("You have %d new email%s. Do you want me to read %s?" % (
            len(reports),
            's' if len(reports) > 1 else '',
            'them' if len(reports) > 1 else 'it'
        ))
        user = mic.semiActiveListen(10)
        if isPositive(user):
            mic.say('\n'.join(reports))
Ejemplo n.º 3
0
    def handleResponse(text):
        def extractOrdinals(text):
            output = []
            service = NumberService()
            # convert to lower case for the ordinal function
            text = text.lower()
            for w in text.split():
                #print (w + "inside extract Ordinals")
                if w in service.__ordinals__:
                    print(w + " is a n ordinal")
                    output.append(service.__ordinals__[w])
            return [service.parse(w) for w in output]

        chosen_articles = extractOrdinals(text)
        send_all = 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.link)

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

            for idx, article in enumerate(healthreports):
                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="From the Front Page of Health 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")
Ejemplo n.º 4
0
    def handleResponse(text):

        def extractOrdinals(text):
            output = []
            if 'pierwszy' in text or 'pierwsza' in text or 'pierwszą' in text:
                output.append(1)
            if 'drugi' in text or 'druga' in text or 'drugą' in text:
                output.append(2)
            if 'trzeci' in text or 'trzecia' in text or 'trzecią' in text:
                output.append(3)
            if 'czwarty' in text or 'czwarta' in text or 'czwartą' in text:
                output.append(4)
            if 'piąty' in text or 'piąta' in text or 'piątą' in text:
                output.append(5)

            return output
            #output = []
            #service = NumberService()
            #if text:
            #  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("Już się robi, proszę o jedną chwilę")

            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, logger, SUBJECT="", BODY=article_link):
                            mic.say(
                                "Wybacz, ale mam problem z wysłaniem wiadomości.| Sprawdź proszę podany numer telefonu i operatora.")
                            return

            # if prefers email, we send once, at the end
            if profile['prefers_email']:
                body += "</ul>"
                if not app_utils.emailUser(profile, logger, SUBJECT="Twoje wiadomości", BODY=body):
                    mic.say(
                        "Wybacz, ale mam problem z wysłaniem wiadomości.| Sprawdź proszę podany numer telefonu i operatora.")
                    return

            mic.say("Gotowe")

        else:

            mic.say("W porządku, nie wysyłam wiadomości")
Ejemplo n.º 5
0
    def handleResponse(text):
        def extractOrdinals(text):
            output = []
            if 'pierwszy' in text or 'pierwsza' in text or 'pierwszą' in text:
                output.append(1)
            if 'drugi' in text or 'druga' in text or 'drugą' in text:
                output.append(2)
            if 'trzeci' in text or 'trzecia' in text or 'trzecią' in text:
                output.append(3)
            if 'czwarty' in text or 'czwarta' in text or 'czwartą' in text:
                output.append(4)
            if 'piąty' in text or 'piąta' in text or 'piątą' in text:
                output.append(5)

            return output
            #output = []
            #service = NumberService()
            #if text:
            #  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("Już się robi, proszę o jedną chwilę")

            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, logger, SUBJECT="",
                                BODY=article_link):
                            mic.say(
                                "Wybacz, ale mam problem z wysłaniem wiadomości.| Sprawdź proszę podany numer telefonu i operatora."
                            )
                            return

            # if prefers email, we send once, at the end
            if profile['prefers_email']:
                body += "</ul>"
                if not app_utils.emailUser(
                        profile, logger, SUBJECT="Twoje wiadomości",
                        BODY=body):
                    mic.say(
                        "Wybacz, ale mam problem z wysłaniem wiadomości.| Sprawdź proszę podany numer telefonu i operatora."
                    )
                    return

            mic.say("Gotowe")

        else:

            mic.say("W porządku, nie wysyłam wiadomości")